Using c++ unmanaged object methods in c#

  • Thread starter Thread starter Joneleth
  • Start date Start date
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
 
| 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.
 
Back
Top