loader(exe):
#include "stdafx.h" #include <Windows.h> #include <stdio.h> #define Loaddll_API __declspec(dllexport) extern "C" Loaddll_API int _stdcall testloader(void); #pragma comment(lib,"Loaddll") int main(int argc,char* argv[]) { testloader(); //隐式调用 //显示调用 typedef int(_stdcall *Fun)(void); HMODULE hmod = LoadLibraryA("Loaddll.dll"); Fun testFun = GetProcAddress(hmod,"testloader"); testFun(); system("pause"); return 0; }
dll:Loaddll
#include "stdafx.h" #include <Windows.h> #include <stdio.h> #define Loaddll_API __declspec(dllexport) extern "C" Loaddll_API int _stdcall testloader(void); 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; } extern "C" int _stdcall testloader(void) { MessageBoxA(NULL,"loader dll","Title",MB_OK); printf("Hello word,this is a export dll functions\r\n"); return 0; }
添加一个.def模块定义文件。
LIBRARY "Loaddll" EXPORTS testloader @ 1