#include #include //#include 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; }