[Qt-interest] Loading DLL Functions with QLibary fails with "Run-Time Check Failure"
Matthias Pospiech
matthias.pospiech at gmx.de
Mon Apr 27 15:55:48 CEST 2009
I have a libary which I only want to load if selected.
The vendor header file looks like this:
#ifdef USMCDLL_EXPORTS
#define USMCDLL_API __declspec(dllexport)
#else
#define USMCDLL_API __declspec(dllimport)
#endif
#ifdef __cplusplus // C++
extern "C" {
//
// The USMC_Init function initializes driver and returns devices
information
//
USMCDLL_API DWORD USMC_Init( USMC_Devices &Str); // OUT - Array
of structures describing all divices (may be NULL) MUST NOT be deleted
-------------------------------
I changed it to:
typedef DWORD (__stdcall *fn_USMC_Init)( USMC_Devices &Str);
class USMCDLL
{
public:
USMCDLL(void){}
~USMCDLL(void) { m_Dll.unload(); }
public:
bool DllLoaded() { return m_Dll.isLoaded(); }
void unloadDLL() { m_Dll.unload(); }
bool LoadDLL() {
m_Dll.setFileName(QString("USMCDLL.dll"));
m_Dll.load();
if (!m_Dll.isLoaded())
return false;
USMC_Init =
(fn_USMC_Init)(m_Dll.resolve("USMC_Init"));
protected:
QLibrary m_Dll;
public:
fn_USMC_Init USMC_Init;
};
this however does not work (it compiles). At runtime I get the error:
Run-Time Check Failure #0 - The value of ESP was not properly saved
across a function call. This is usually a result of calling a function
declared with one calling convention with a function pointer declared
with a different calling convention.
How can I get around this problem?
Matthias
More information about the Qt-interest-old
mailing list