dllmain.cpp 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // dllmain.cpp : 定义 DLL 应用程序的入口点。
  2. #include "stdafx.h"
  3. HHOOK g_hook = NULL;
  4. LRESULT CALLBACK Hook_CBT_Proc(int nCode, WPARAM wParam, LPARAM lParam)
  5. {
  6. tagMSG* msg;
  7. msg = (tagMSG*)lParam;
  8. if (nCode == HCBT_MINMAX)
  9. {
  10. WriteTextLog(_T("窗口HCBT_MINMAX"));
  11. return 1;
  12. }
  13. return CallNextHookEx(g_hook, nCode, wParam, lParam);
  14. }
  15. BOOL APIENTRY DllMain(HMODULE hModule,
  16. DWORD ul_reason_for_call,
  17. LPVOID lpReserved
  18. )
  19. {
  20. g_hCurModule = hModule;
  21. switch (ul_reason_for_call)
  22. {
  23. case DLL_PROCESS_ATTACH:
  24. {
  25. if (g_hook == NULL)
  26. g_hook = SetWindowsHookEx(WH_CBT, Hook_CBT_Proc, NULL, ::GetCurrentThreadId());
  27. WriteTextLog(_T("dll已成功注入:%d,%d"), ::GetCurrentThreadId(), ::GetCurrentProcessId());
  28. WxInfo wxInfo;
  29. GetWxInfo(wxInfo);
  30. }
  31. break;
  32. case DLL_THREAD_ATTACH:
  33. break;
  34. case DLL_THREAD_DETACH:
  35. break;
  36. case DLL_PROCESS_DETACH:
  37. if (g_hook)
  38. UnhookWindowsHookEx(g_hook);
  39. WriteTextLog(_T("dll已成功卸载"));
  40. break;
  41. default:
  42. break;
  43. }
  44. return TRUE;
  45. }