Using c++ unmanaged object methods in c#

J

Joneleth

Hi

I know how to call external c functions in c# through DllImport.
Now, i'm trying to call a c++ (unmanaged) class method, defined in an
external .dll as static int myClass::myMethod, and i wonder if it is
possible.
I have used the VS utility dumpbin /exports "myDllPath" in the
post-build event and have added the row extern "C"
__declspec(dllexport) int myMethod(int, int);
before the method implementation in the .cpp file, in order to set an
entry point (or so i believe...).
but it doesn't work, it raises the error "Unable to find an entry point
for <myMethod> in DLL <myDLL>".
This make me think that it is not possible to use PInvoke (DllImport)
for c++ classes, even if the methods are statics, and the only solution
would be to wrap the unmanaged c++ class into a managed one.
Am i right?

thanks
 
W

Willy Denoyette [MVP]

| Hi
|
| I know how to call external c functions in c# through DllImport.
| Now, i'm trying to call a c++ (unmanaged) class method, defined in an
| external .dll as static int myClass::myMethod, and i wonder if it is
| possible.
| I have used the VS utility dumpbin /exports "myDllPath" in the
| post-build event and have added the row extern "C"
| __declspec(dllexport) int myMethod(int, int);
| before the method implementation in the .cpp file, in order to set an
| entry point (or so i believe...).
| but it doesn't work, it raises the error "Unable to find an entry point
| for <myMethod> in DLL <myDLL>".
| This make me think that it is not possible to use PInvoke (DllImport)
| for c++ classes, even if the methods are statics, and the only solution
| would be to wrap the unmanaged c++ class into a managed one.
| Am i right?
|

Yes indeed you are.

Willy.
 

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