#include <windows.h>
#include <iostream>
// 定义一个函数指针类型,用于指向 DLL 中的函数
typedef int (*MyFunctionPtr)();
int main() {
// 加载 DLL 文件
HINSTANCE hDLL = LoadLibrary(TEXT("MyDLL.dll"));
if (hDLL == NULL) {
std::cerr << "无法加载 DLL 文件。" << std::endl;
return 1;
}
// 获取函数地址
MyFunctionPtr myFunction = (MyFunctionPtr)GetProcAddress(hDLL, "MyFunction");
if (myFunction == NULL) {
std::cerr << "无法找到函数地址。" << std::endl;
FreeLibrary(hDLL);
return 1;
}
// 调用 DLL 中的函数
int result = myFunction();
std::cout << "DLL 函数返回值: " << result << std::endl;
// 卸载 DLL
FreeLibrary(hDLL);
return 0;
}
windows api dll延时加载技术代码
最新推荐文章于 2024-09-09 22:12:12 发布