Reputation: 331
I have created a WIN32 DLL project and its dllmain.cpp is as follows;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
_declspec(dllexport) float RGBCompare()
{
return 100;
}
My target is to call method RGBCompare from a C# project and as per rule I have mentioned dllexport tag before it.
On the other side in C# project I have defined an entry point as follows;
namespace LogoFinderWrapper
{
public class LogoFinder
{
[DllImport("LogoIdentifier.dll", EntryPoint = "RGBCompare")]
private static extern float Api_RGBCompare();
public static float RGBCompare()
{
return Api_RGBCompare();
}
}
}
When I call DLL it raises exception System.EntryPointNotFoundException.
Please could any one help me in this regard?
Upvotes: 0
Views: 1152
Reputation: 613262
Your native code is C++ and the name is mangled before export. Possible solutions:
EntryPoint
parameter. Find out the mangled name with dumpbin
or Dependency Viewer.__declspec(dllexport)
to control which functions are exported.extern "C"
in your C++ source code.The final option would look like this:
extern "C"
{
__declspec(dllexport) float RGBCompare()
{
return 100;
}
}
Upvotes: 1