Re: Linking with 3rd party DLL
"David Ching" <dc@remove-this.dcsoft.com> ha scritto nel messaggio
news:E9B926FF-A71C-4547-998C-1D53BC81668D@microsoft.com...
Try adding WINAPI to the function prototype:
extern "C"
{
const char* WINAPI CreateCodeShort3(int level, const char *name, const
char
I think that WINAPI means __stdcall.
So, __stdcall causes name mangling (with leading underscore, @<bytes>, etc.)
http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx
Instead, the OP showed that the function is exported without leading
underscore and @ decoration.
So, I think that extern "C" + WINAPI would not work in that case.
Without having the .h and .lib files, I would just use GetProcAddress()
(trying with WINAPI calling convention, and if that fails corrupting the
stack, trying without WINAPI):
<code>
// Function to be imported from the DLL
typedef LPCSTR (WINAPI *PFNCREATECODESHORT3)(
int /* level */,
LPCSTR /* name */
...others parameters ...
);
// Load the DLL
HMODULE hDll = LoadLibrary(TEXT("<<your dll filename>>"));
if ( hDll == NULL )
{
// Error
// ...
}
// Load the exported function CreateCodeShort3 (without name mangling)
PFNCREATECODESHORT3 pfnCreateCodeShort3 = reinterpret_cast<
PFNCREATECODESHORT3 >(
GetProcAddress( hDll, "CreateCodeShort3" ));
</code>
Giovanni