用英特尔编译器编译DLL时出错
Error with compiling DLL with intel compiler
我正在尝试从控制台编译DLL,而不使用任何IDE并面临下一个错误。
我写了下面的代码:
test_dll.cpp
#include <windows.h>
#define DLL_EI __declspec(dllexport)
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved){
return 1;
}
extern "C" int DLL_EI func (int a, int b){
return a + b;
}
然后用icl /LD test_dll.cpp
命令编译。我试着从另一个程序调用func
:
prog.cpp
int main(){
HMODULE hLib;
hLib = LoadLibrary("test_dll.dll");
double (*pFunction)(int a, int b);
(FARPROC &)pFunction = GetProcAddress(hLib, "Function");
printf("beginn");
Rss = pFunction(1, 2);
}
用icl prog.cpp
编译。然后我运行它,它失败了,标准窗口"程序不工作"。可能有分段错误错误。
我做错了什么?
检查LoadLibrary()
和GetProcAddress()
是否成功,在这种情况下,它们肯定不会因为导出的函数被称为func
,而不是"Function"
,如GetProcAddress()
的参数中指定的那样,这意味着当尝试调用它时,函数指针将是NULL
。
函数指针的签名也与导出函数的签名不匹配,导出函数返回的是int
,而函数指针期望的是double
。
typedef int (*func_t)(int, int);
HMODULE hLib = LoadLibrary("test_dll.dll");
if (hLib)
{
func_t pFunction = (func_t)GetProcAddress(hLib, "func");
if (pFunction)
{
Rss = pFunction(1, 2);
}
else
{
// Check GetLastError() to determine
// reason for failure.
}
FreeLibrary(hLib);
}
else
{
// Check GetLastError() to determine
// reason for failure.
}
相关文章:
- 从DLL导出函数,LoadLibrary()需要用TEXT转换的字符串才能编译而不会出错
- 使用mingw遵循简单的c ++ DLL教程时出错
- 在 dll 中为 qLibrary 编译 qobject 时出错
- 从 Python 调用 Windows DLL 函数时出错
- 加载共享库时出错:JVM.dll
- 在 Windows 10 上使用 CZMQ 编译 dll 时出错
- 在Visual Studio中使用Cygwin编译的dll的库函数时出错
- 在Windows上使用GCC的链接时间优化构建wxWidgets DLL时出错
- 在DLL客户端中使用dllimport时出错
- 在C/C++中加载DLL时出错
- 使用 Visual Studio 2013 构建过剩 DLL 时出错
- 在 Windows 2008 上从 JNI 加载 dll 时出错
- 油.dll调用 - 访问被拒绝错误80020009出错
- 使用 libstdc++6.dll 运行代码时出错
- Qt创建者-当dll的标头出现在多个位置时出错
- Visual Studio链接器在尝试使用DLL中的静态库时出错(LNK2038、LNK2005)
- 在c++ dll中删除指针时出错
- C++ 与Dll沟通出错
- LNK1104.dll链接到 Visual Studio "invalid or corrupt file" 中的测试应用程序时出错
- 使用g++编译器在Eclipse IDE中生成DLL类时出错