c++ - GetProcAddress() 为我的 Hello World 函数返回 null

标签 c++ c winapi dll

好吧,我的简单 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/

相关文章:

c++ - 如何从链表指针字符中查找字符

c - 这个clear_mem函数的目的是什么?

在 Ubuntu 上使用 TCP_REPAIR 套接字选项编译代码

c# - 多次按 Tab 键后不再调用线程 Hook 程序。为什么?

c++ - 无法添加静态库

c++ - 在32位数字中查找第一个(最低)置位位置

c++ - 使用 std::thread 从派生类调用重写方法

c - MacOS brew install libsndfile 但还是找不到

c++ - WritePrinter 不要求输入 PIN 码

c++ - winapi:去除装饰