gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 01:13:01 25 4
gpt4 key购买 nike

好吧,我的简单 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”MessageBox,认为它应该打开 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com