tags:

views:

80

answers:

3

How would I use DLLImport pinvoke to invoke a function i wrote in a class in an unmanaged DLL? It always throws that the entry point doesn't exist in the dll. EX:

class Foo
{
  int __declspec(dllexport) Bar() {return 0;}
};

Bar is in the Foo class. when I use pinvoke as:

[DLLImport("Test.dll")]
public static extern int Bar();

When using it i get an exception saying that the entry point does not exist in the DLL. Is it possible to call functions directly from classes?

+1  A: 

Short answer:

No

Long answer:

Create a C callable export (iow including the instance parameter).

leppie
+1  A: 

You are going to have to find the mangled name. You can use dumpbin /exports but 'im not sure that the calling convention will work through pinvoke.

rerun
+1  A: 

Not easily...

To call a member function, the first "hidden" argument has to be a pointer to the C++ class who's member function you are calling.

And C++ functions are name mangeled, so you need to find the name mangeled name of the function you are calling.

In short: It is easier to create a C++/CLI wrapper of your C++ class to do this.

Arve