Re: Declaring a constant in managed C++ for access from C#



GnG wrote:
Hello all,

Someone posted a similar question a while ago but there was
no response. Does anyone know the answer?

I have a managed C++ DLL which is used by a C# project.
In that DLL, I have code like this:

namespace Foo {
public __value const int Bar = 123;
};

It appears in the object browser when I'm in the C++
project, but it's not visible from the C# project. Why
not? Is there another way I'm supposed to do this?

I could put it into an enumeration, or make it a static
property of a class, but I'd rather not do that, if at all
possible.

Make it static. C# (and the.NET framework) has no real concept of a const
int. In C# when you declare a const int, you're really declaring a static
const int which always occupies memory and has an address, while in C++
you're declaring a constant, which may not even have an address.

-cd


.



Relevant Pages

  • Re: Access Violation using CCriticalSection in DLL
    ... declared within the logger class. ... the DLL, then the logger works OK once I return from the DLL, so lifetime ... everything works when I run a debug version. ... I am declaring the logger outside of the scope of my main program so ...
    (microsoft.public.vc.mfc)
  • Declare function problem
    ... I am having problems with Declaring a function from a dll. ... hSocket As Long) As Long ... What I think is the problem is that hSocket is the connection handle if it ...
    (microsoft.public.dotnet.languages.vb)
  • CLR Class Libary
    ... Can anyone tell me how to write a CLR Class Library (C++/CLI DLL) ... public ref class TestFunctions ... I am declaring the functions as static so that I can use them directly from ...
    (microsoft.public.dotnet.languages.vc)
  • Re: memory issue
    ... > declaring it, ... All you need to do is use the dll as you normally would ... Then when you want to free it from memory call ... LoadLibrary before the app terminates otherwise it will call FreeLibrary ...
    (microsoft.public.vb.general.discussion)
  • Const from IDL-File
    ... I have defined a "const int" in an idl file(const int ... in the tlh file which was build after import of the com dll. ...
    (microsoft.public.vc.atl)