我查看了导出函数的文档,它指出__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"));因为__declspec(dllexport)的问题是否包含在类型胡枝子中?因此,应用程序源文件中的语句实际上是:
__declspec(dllexport) void (*print_test)() printTest = reinterpret_cast<print_test*>(GetProcAddress(testDLL, "PrintTest"));我没有收到任何编译器错误或警告。
发布于 2015-12-19 01:29:38
问题在于您正在导出一个C++函数,该函数有一个损坏的名称。您要么需要将这个损坏的名称传递给GetProcAddress (从不有趣),要么需要在函数声明中使用__stdcall解除对导出的破坏。
LIBRARY_API __stdcall void PrintTest或者用extern "C"。__stdcall更简单,并将调用约定从C++样式更改为C样式。(这可能需要将"_PrintTest“传递给GetProcAddress,因为C函数名是如何导出的。)
https://stackoverflow.com/questions/34365367
复制相似问题