dll.cpp,用vc2017编译
#include <iostream>
#include <windows.h>
extern "C" __declspec(dllexport) void Go() {
std::cout << "go" << std::endl;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
main.cpp 用mingw64的g++编译
#include <iostream>
extern "C" __declspec(dllimport) void Go();
int main (int argc, char **argv)
{
Go();
return 0;
}
将dll.lib dll.dll dll.exp dll.pdb复制到main.cpp当前目录,编译:
g++ main.cpp -ldll -L.
原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/9101306.html
时间: 2024-10-18 21:32:44