这是我的 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