DLL代码
#include <Windows.h>BOOL APIENTRY DllMain( HMODULE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{switch (ul_reason_for_call){case DLL_PROCESS_ATTACH:MessageBox(NULL, L"dllHook", L"Hook", MB_OK);break;case DLL_THREAD_ATTACH:case DLL_THREAD_DETACH:case DLL_PROCESS_DETACH:break;}return TRUE;
}extern "C"
{__declspec(dllexport) int add(int x, int y){return x + y;}__declspec(dllexport) int sub(int x, int y){return x - y;}
}
exe代码
#include <Windows.h>
#include <cstdio>typedef int (*func)(int a, int b);
func add;
func sub;int main()
{HINSTANCE dllHins = LoadLibrary(L"hookNotepadDLL.dll");if (dllHins == NULL) {printf("Load Failed\n");}else {printf("Load Success\n");}add = (func)GetProcAddress((HMODULE)dllHins, "add");if (add == NULL) {printf("Get ADD function failed\n");return 1;}sub = (func)GetProcAddress((HMODULE)dllHins, "sub");if (sub == NULL) {printf("Get SUB function failed\n");return 1;}printf("%d %d\n", add(4, 5), sub(9, 4));return 0;
}
结果
工具
查看dll导出的函数:dumpbin dllname /exports