简体   繁体   English

在Windows上加载DLL失败

[英]Loading DLL fails on Windows

As a Xcode developer I have to use my written code on windows, too. 作为Xcode开发人员,我也必须在Windows上使用我编写的代码。 I think I have successful master all cross platform issues but now I have a real problem understanding the DLL hell on Windows. 我认为我已经成功地掌握了所有跨平台问题,但是现在我在理解Windows上的DLL地狱时遇到了一个真正的问题。 I used my code with Xcode and Gcc (Ubuntu) successful. 我将代码成功用于Xcode和Gcc(Ubuntu)。 On Windows I get a error message: 在Windows上,我收到一条错误消息:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. 运行时检查失败#0-在整个函数调用中ESP的值未正确保存。 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 通常在Windows上我有类似

#define MYLIB_API __declspec(dllimport)

I cannot find this inside the header of the Bass Library (bass.h). 我在低音库(bass.h)的标头中找不到该文件。 There is only one line 只有一行

#define BASSDEF(f) WINAPI f

Now, I try to dynamic load the DLL functions in my code. 现在,我尝试在代码中动态加载DLL函数。 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. 这种动态加载适用于.dylib和.so库,不适用于.dll。我的目标是动态加载DLL,而不能通过其他lib静态加载。

In my code I use the bass.h and the bassdecode.h. 在我的代码中,我使用了bass.h和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? 要成功在Windows上导入DLL函数,我必须在头文件中做什么?

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. 好的,对于所有遇到相同问题的人,解决方案都是Hans Passant的答案。 I cannot mark this answer as solution so I want to give him the reputation. 我无法将此答案标记为解决方案,因此我想给他以声誉。

My original typedef of the function: 我的原始typedef函数:

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

Was searched in DLL 在DLL中搜寻

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

Where DLLFindSym is defined as: DLLFindSym定义为:

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

Now changed the typedef to 现在将typedef更改为

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

Now everything works like a charm in Windows. 现在,一切在Windows中都像魅力一样。 Many thanks to the quick hint from Hans Passant. 非常感谢Hans Passant的快速提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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