好吧,我的简单 DLL Hellow World 函数
#include "stdafx.h"
extern "C" void HelloWorld()
{
MessageBox( NULL, TEXT("Hello World"),
TEXT("In a DLL"), MB_OK);
}
我的简单的 hello world 应用程序没有调用:
case IDM_ABOUT:
hinstDLL = LoadLibrary(L"phantasyhook.dll");
if (hinstDLL != NULL)
{
HelloWorld = (FARPROC) GetProcAddress(hinstDLL, "HelloWorld");
if (HelloWorld != NULL)
HelloWorld();
else
MessageBox(NULL, L"is null", L"dll Error", MB_OK);
FreeLibrary(hinstDLL);
}
break;
它打开“is null”消息框,认为它应该打开 Hello World 消息框。我做错了什么?
最佳答案
您需要标记某个函数应由 DLL 导出,以便其他代码能够加载它。您可以通过添加 __declspec(dllexport) 来完成或 module definition file .
extern "C" __declspec(dllexport) void HelloWorld()
关于c++ - GetProcAddress() 为我的 Hello World 函数返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13131261/