Calling Managed code in a mixed C++ dll

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
 
H

Huihong Luo

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
 
R

Ray

I get compile errors...
MyClass : is not a class or a namespace name
MyMeanOlManagedMeth: identifier not found, even with argument-dependent
lookup.
 
H

Huihong

try to use full class name

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

Huihong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top