I read a few questions related to mine, but none of the few answers worked for me.
I need to call a function from an unmanaged DLL. I have a 32-bit version of DLL in SysWow64 and a 64-bit version in system32. Anyway, I am compiling for x86. I have no source for the DLL, so recompiling with extern "C" is not an option.
Relevant parts of the include file for the DLL:
(...) #include <string> namespace SomeNamespace { (...) typedef std::wstring STRING; (...) class SomeClass { (...) static bool SomeFunc(const STRING& p1, bool p2); (...) } }
When calling SomeFunc, I get an exception: "Could not find an entry point with a name"? "in DllName.dll" (my translation may be inaccurate).
My ad in C #:
[System.Runtime.InteropServices.DllImport("DllName.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = " ?SomeFunc@SomeClass @ SomeNamespace@ @ SA_NABV?$basic_string@ _WU?$char_traits@ _W@std @@ V?$allocator@ _W@2 @@ std@ @ _N@Z ")] bool SomeFunc(string p1, bool p2);
I also tried the following:
[System.Runtime.InteropServices.DllImport("DllName.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "#15")] bool SomeFunc(string p1, bool p2);
15 is the function serial number depending on Depends, and EntryPoint in the first version is also obtained from Depends.
According to undname.exe, this is the original function declaration:
public: static bool __cdecl SomeFunc(class ?? :: ?? ::Z::basic_string<wchar_t,str uct std::char_traits<wchar_t>,class w::allocator<wchar_t>,td,bool> const &, ?? ) throw( ?? )
It does not seem to be parsing it correctly; bool should be a parameter for FuncName, not a type parameter for basic_string. However, I'm not sure if this is just a parsing error from the undname.exe file or something more serious.
How can i fix this?
Update: When using the function serial number as an entry point, I get no exception. I call this from the form load event, and during debugging I lost control. I mean, I am debugging the cursor on the SomeFunc () line, I press F10 and the application continues as if I am not debugging. I do not get ThreadException or UnhandledException.
Caller Code:
public bool CallSomeFunc() { try { SomeFunc("p1", true); } catch (Exception ex) { ex.ToString();
Final update