简体   繁体   中英

Loading DLL fails on Windows

As a Xcode developer I have to use my written code on windows, too. I think I have successful master all cross platform issues but now I have a real problem understanding the DLL hell on Windows. I used my code with Xcode and Gcc (Ubuntu) successful. On Windows I get a error message:

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.

I read much about this uses but I have my problems to understand the issue. Normally on windows I have something like

#define MYLIB_API __declspec(dllimport)

I cannot find this inside the header of the Bass Library (bass.h). There is only one line

#define BASSDEF(f) WINAPI f

Now, I try to dynamic load the DLL functions in my code. You can see the dynamic loading header as link on bottom. To much to copy here. This dynamic loading is working for .dylib and .so libs well, not for .dll My target is to load the DLL dynamic and not static with an additional lib.

In my code I use the bass.h and the bassdecode.h. In my code I call as sample:

bool returnVar = _BASS_SetConfig(BASS_CONFIG_DEV_DEFAULT,1);

And here I get the calling convention message.

What I have to do in my header file to successful import DLL functions on Windows?

You can download the files at: header files to download

Ok, for all who run into the same problem, the solution is the Answer from Hans Passant. I cannot mark this answer as solution so I want to give him the reputation.

My original typedef of the function:

typedef BOOL    (*BASS_SetConfig_Type)(DWORD option, DWORD value);

Was searched in DLL

_BASS_SetConfig = (BASS_SetConfig_Type)DllFindSym(m_hMod, "BASS_SetConfig")

Where DLLFindSym is defined as:

#define DllFindSym(handle,name) (GetProcAddress(handle,name))   

Now changed the typedef to

typedef BOOL    (__stdcall *BASS_SetConfig_Type)(DWORD option, DWORD value);

Now everything works like a charm in Windows. Many thanks to the quick hint from Hans Passant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM