I have a 64bit-DLL which exports the function
__cdecl int (*function)(IN wchar_t* file, OUT VARIANT &htmlFile, IN wchar_t* path);
which is implemented as
int CShellWrapperx64Module:function(wchar_t* file, VARIANT &htmlFile, wchar_t* path) {
VariantInit(&htmlFile);
htmlFile.vt = VT_BSTR;
htmlFile.bstrVal = ::SysAllocString(L"");
return 0;
}
and a 64bit-DLL which calls the function
function pfunction = (function)GetProcAddress(hMod, MAKEINTRESOURCEA(0x0001));
TCHAR m_file[MAX_PATH];
VARIANT vhtml;
VariantInit(&vhtml);
pfunction(m_file, vhtml, path);
In 32bit-mode the function call succeeds but in 64bit-mode the function-entry-point is reached but the parameters开发者_运维知识库 are invalid? What could I do?
You declared it as a static function but the odds that it is actually an instance method are great. It works by accident on x86 because the this pointer is passed in a register and not on the stack. You ran out of luck on x64 because it passes the arguments a different way. Everything is passed in registers, now caller and callee no longer match. There is otherwise no way for the linker to help you diagnose this issue at build time because you used GetProcAddress.
Declare the method static.
In x64 there is no such thing as the __cdecl
convention, see this, you'd need to branch correctly for x86-32 and x86-64 builds (also seems you have some compiler specific extensions in there like :function
). I suspect that the dll you are calling wasn't correctly compiled for x64 (a debugger would give you a more definitive answer).
精彩评论