You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

38 lines
1.3 KiB

#include <iostream>
#include <Windows.h>
//#include <dlfcn.h> windows 上没有这个头文件
// 声明DLL中的函数原型
typedef void (*PrintWelcomeMessage)();
typedef int (*Sub)(int, int);
typedef bool (*IsEven)(int);
int main() {
HMODULE dllHandle = LoadLibrary("..\\lib\\libdynLib.dll"); // 加载DLL
if (dllHandle != nullptr) {
// 获取DLL中的函数地址
PrintWelcomeMessage printWelcomeMessage = (PrintWelcomeMessage)GetProcAddress(dllHandle, "printWelcomeMessage");
Sub sub = (Sub)GetProcAddress(dllHandle, "sub");
IsEven isEven = (IsEven)GetProcAddress(dllHandle, "isEven");
if (printWelcomeMessage != nullptr && sub != nullptr && isEven != nullptr) {
// 调用DLL中的函数
printWelcomeMessage();
int a = 22;
int b = 2;
int result = sub(a, b);
bool even = isEven(result);
std::cout << a << " - " << b << " = " << result << std::endl;
std::cout << "IsEven(" << result << ") = " << even << std::endl;
} else {
std::cerr << "Failed to get function address from DLL." << std::endl;
}
// 卸载DLL
FreeLibrary(dllHandle);
} else {
std::cerr << "Failed to load DLL." << std::endl;
}
return 0;
}