这是我的 DLL 代码:
#include <Windows.h>
#include <iostream>
int sysLol(char *arg);
int sysLol(char *arg)
{
std::cout<<arg<<"\n";
return 1;
}
这是我的应用程序代码:
#include <Windows.h>
#include <iostream>
#include <TlHelp32.h>
#include <stdlib.h>
typedef int (WINAPI* Lol)(char* argv);
struct PARAMETERS
{
DWORD Lol;
};
int main()
{
PARAMETERS testData;
HMODULE e = LoadLibrary(L"LIB.dll"); //This executes without problem
if (!e) std::cout<<"LOADLIBRARY: "<<GetLastError()<<"\n";
else std::cout<<"LOADLIBRARY: "<<e<<"\n";
testData.Lol = (DWORD)GetProcAddress(e,"sysLol"); //Error 127?
if (!testData.Lol) std::cout<<testData.Lol<<" "<<GetLastError()<<"\n";
else std::cout<<"MESSAGEBOX: "<<testData.Lol<<"\n";
std::cin.ignore();
return 1;
}
因此,我的 LIB.dll 使用 LoadLibrary()
成功加载,但 GetProcAddress()
失败并显示 127。这似乎是因为它没有找到我的函数名称,但我不明白为什么会失败。
非常感谢您的帮助! :) ~P
原文由 Moon 发布,翻译遵循 CC BY-SA 4.0 许可协议
由于该标记是 C++,因此您需要为函数声明一个
C
名称:您可以使用 Dependency Walker 查看编译器为您的 C++ 函数提供的实际名称。
成功后,将函数转换为 GetProcAddress 返回的指针到实际函数类型: