vc.net 2003, managed global containers

I need to create some kind of container in vc.net 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
LVL 3
bjqrnAsked:
Who is Participating?
 
AlexFMCommented:
This is my test in VC++ 8.0 which is successfully compiled:

ref class TestClass
{
public:
    static String^ str = "test";
};


int main(array<System::String ^> ^args)
{
    Console::WriteLine(TestClass::str);
    return 0;
}

What line exactly is not compiled in your project? Maybe you are trying to create global BasicCommands_ instance?
0
 
mahesh1402Commented:
You could make a class that initialises and holds  struct BasicCommands_

Remember you can only define .NET Framework objects within function scope.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vctbsCompilerErrorC3145.asp <===

You may try using gcroot.



MAHESH
0
 
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.
0
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.

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

http://msdn.microsoft.com/msdnmag/issues/02/02/managedc/ <==


MAHESH
0
 
bjqrnAuthor Commented:
Yes, a global BasicCommands_ instance is what I try to create.
0
 
bjqrnAuthor Commented:
AlexFM: Worked!

Didn't know you could get a variable from a class without instancing it!
0
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.