2003, managed global containers

I need to create some kind of container in 2003, it shall store either Strings or byte arrays. It must be in a separate header and be accessible throughout the whole project.

it must use managed code.

I would prefer it to use const variables.

Any ideas?

This is what it looks like right now:

#pragma once

#using <mscorlib.dll>
#using <System.dll>

namespace Dgcp {

      __gc struct BasicCommands_ {
            static const System::String *cmdAcknowledgement = "ACK";
            static const System::String *cmdHandshake = "HSK";
      } *BasicCommands;

But it produces this error:
error C3145: 'BasicCommands' : cannot declare a global or static managed type object or a __gc pointer
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mahesh1402IT ProfessionalCommented:
You could make a class that initialises and holds  struct BasicCommands_

Remember you can only define .NET Framework objects within function scope. <===

You may try using gcroot.

bjqrnAuthor Commented:
The thing is that I would like to use the variables as I would use #define's, but I would like a more "modern" way of doing that.

Please explain gcroot.
mahesh1402IT ProfessionalCommented:
GCHandle and gcroot are well described in the docs see "Tips and Tricks to Bolster Your Managed C++ Code" by Tomas Restrepo in the February 2002 MSDN®Magazine : <==

Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

This is my test in VC++ 8.0 which is successfully compiled:

ref class TestClass
    static String^ str = "test";

int main(array<System::String ^> ^args)
    return 0;

What line exactly is not compiled in your project? Maybe you are trying to create global BasicCommands_ instance?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bjqrnAuthor Commented:
Yes, a global BasicCommands_ instance is what I try to create.
bjqrnAuthor Commented:
AlexFM: Worked!

Didn't know you could get a variable from a class without instancing it!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.