使用__declspec(dllexport)而不是-EXPORT:
Using __declspec(dllexport) instead of -EXPORT:
我正在查看导出函数的文档,其中指出__declspec(dllexport)应在命令行版本-EXPORT之前使用:如果可能的话。我目前正在使用命令行变体。在尝试进行这些更改时,我试图理解正确的实现,但我遇到了问题。
DLL的头文件:
#ifdef LIBRARY_EXPORTS
#define LIBRARY_API __declspec(dllexport)
#else
#define LIBRARY_API __declspec(dllimport)
#endif
#define PRINT_TEST(name) LIBRARY_API void name()
typedef PRINT_TEST(print_log);
// ^ What's the C++11 equivalent with the using keyword?
DLL的源文件:
PRINT_TEST(PrintTest) {
std::cout << "Testing DLL" << std::endl;
}
应用程序的源文件:
print_test* printTest = reinterpret_cast<print_test*>(GetProcAddress(testDLL, "PrintTest"));
这个问题是因为typedef中包含了__declspec(dllexport)吗?因此,应用程序源文件中的语句实际上是:
__declspec(dllexport) void (*print_test)() printTest = reinterpret_cast<print_test*>(GetProcAddress(testDLL, "PrintTest"));
我没有收到任何编译器错误或警告。
问题是因为您正在导出一个C++函数,该函数的名称已损坏。您要么需要将损坏的名称传递给GetProcAddress(从来都不好玩),要么需要在函数声明中使用__stdcall来取消导出
LIBRARY_API __stdcall void PrintTest
或者使用CCD_ 1。__stdcall
更简单,并将调用约定从C++样式更改为C样式。(这可能需要将"_PrintTest"传递到GetProcAddress,因为C函数名是如何导出的。)
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 混合 Rcpp 模块和 Rcpp::export
- C ++:DECLSPEC,静态库和DLL
- 创建C++ Redis 模块 - "does not export RedisModule_OnLoad() symbol"
- 在C++,OpenGL,Glut,如何将image.c绑定到纹理,其中image.c来自Gimp>Export>C源代码
- 如何使用库的头文件生成 libfoo.sym 文件以用于 libtool -export-symbols?
- Declspec A 结构,当创建要发送到 OpenCL 内核的缓冲区时
- 使用__declspec(dllexport)而不是-EXPORT:
- Visual c++ 2008应用程序在链接时出现的名称混淆(declspec)不匹配的链接错误
- QWebFrame export xhtml
- declspec and stdcall vs declspec only