Calling Managed code in a mixed C++ dll

  • Thread starter Thread starter Ray
  • Start date Start date
R

Ray

I am trying to add calls to managed C++ class from unmanaged C in the same
DLL (I saw somewhere while trying to solve something else, that if you have
them both in the same DLL that you could freely call between managed and
unmanaged code with no stress, but i'm living proof that that was wrong, I'm
full of stress :)

at any rate, I've been laboring under the assumption that if I have file 1
over here with

#pragma unmanaged
BOOL myNiceUnmanagedMeth(void)
{

long x = MyNS::MyClass::MyMeanOlManagedMeth( 30);
}

and on the managed side

namespace MyNS
{
__gc class MyClass
{
public:
int MyMeanOlManagedMeth(int y){

return y * 2;
}
}
}

anybody got hints on how to make myNiceUnmanagedMeth call
MyMeanOlManagedMeth????

Ray
 
That managed method is an instance method, so you need to create an object,

MyClass *o = new MyClass();
long x = o->MyMeanOlManagedMeth( 30);

Or declare the method to be static.

Huihong
The most secure .NET source code protection @ Remotesoft
 
I get compile errors...
MyClass : is not a class or a namespace name
MyMeanOlManagedMeth: identifier not found, even with argument-dependent
lookup.
 
try to use full class name

MyNS::MyClass *o = new MyNS::MyClass();
long x = o->MyMeanOlManagedMeth( 30);

Huihong
 
Back
Top