"System.EntryPointNotFoundException" when trying to call an unmanaged function from C #
I finally have a populated C ++ DLL, but I can't manage to call it from C #. This definitely finds the DLL, because when I remove it from the folder I get another exception, "DLLNotFoundException". Full error description "Unable to find entry point named" GetNewInstance "in DLL" CComms.dll ". All functions are exported to C ++, for example:
__declspec(dllexport) DWORD __stdcall GetNewInstance();
and I call it from C # like so
[DllImport("CComms.dll")]
private static extern uint GetNewInstance();
// ... and in main
uint inst = GetNewInstance();
When I use 'dumpbin / exports CComms.dll' I get some wierd output. I'm not sure if the function name is running and why it can't find the entry point
7 6 00002FB0 ?GetNewInstance@@YGKXZ = ?GetNewInstance@@YGKXZ (unsigned long
__stdcall GetNewInstance(void))
I tried to use __cdecl instead of __stdcall and had the same result. I am so close to being ready for this project that I missed completely, hopefully this is the last thing on my way.
Thank.
source to share
You have two ways to create a DLL.
One of them is to get the addresses of functions (the oldschool path), and the second is by parameters and name (the "new" way, for example, uses .net).
I am assuming that you are not using your C ++ dll correctly
Maybe you should be using GetProcAddress
GetProcAddress Msdn
Below is some documentation regarding Dll export that you might find helpful
source to share
Has the same problem with VB.NE Didn't get this exception if the function was declared without __stdcall but was warned by the Managed Debugging Assistant "PInvokeStackImbalance".
in the declared library function
extern "C" _declspec(dllexport)
int __stdcall GetLine(HWND hwnd, int iLine, TCHAR *buff)
Add export.def file to dll project
EXPORT
GetLine
and linker More options
/DEF:"exports.def"
problem solved
source to share