[英]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"));
是因為__declspec(dllexport)導致的問題包含在typedef中? 因此,應用程序源文件中的語句實際上是:
__declspec(dllexport) void (*print_test)() printTest = reinterpret_cast<print_test*>(GetProcAddress(testDLL, "PrintTest"));
我沒有收到任何編譯器錯誤或警告。
問題是因為您要導出的C ++函數名稱錯誤。 您要么需要將該錯誤的名稱傳遞給GetProcAddress(這很有趣),要么需要在函數聲明中使用__stdcall取消導出的損壞
LIBRARY_API __stdcall void PrintTest
或帶有extern "C"
。 __stdcall
更簡單, __stdcall
調用約定從C ++樣式更改為C樣式。 (由於如何導出C函數名稱,這可能需要將“ _PrintTest”傳遞給GetProcAddress。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.