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?
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?
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.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 : <==

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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.