程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> VC >> vc教程 >> 用C++ Builder編HOOK程序

用C++ Builder編HOOK程序

編輯:vc教程

一,

HINSTANCE g_hinstDll = NULL;
HHOOK g_hhook   = NULL;
HWND g_hwndPost = NULL;
UINT g_uMsgNotify = WM_USER;
HOOKPROC KeyboardHook_HookProc ( int nCode, WPARAM wParam, LPARAM lParam)
{
  LRESULT lResult = CallNextHookEx(g_hhook, nCode, wParam, lParam);
  if (nCode == HC_ACTION)
  {
    PostMessage(g_hwndPost, g_uMsgNotify, wParam, lParam);
  }
  return((HOOKPROC)lResult);
}
///////////
BOOL WINAPI SetKeyboardHook (HWND hWndPost, UINT Msg)
{
  HHOOK hhook;
  if (g_hhook != NULL) return(FALSE);
  g_hwndPost = hWndPost;
  g_uMsgNotify = Msg;
  Sleep(0);
  if (g_hLogHook==NULL)
  hhook = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardHook_HookProc,g_hinstDll, 0);
  InterlockedExchange((PLONG) &g_hhook, (LONG) hhook);
  return(g_hhook != NULL);
}
///
BOOL WINAPI ReleaseKeyboardHook()
{
  BOOL fOK = TRUE;
  if (g_hhook != NULL)
  {
    fOK = UnhookWindowsHookEx(g_hhook);
    g_hhook = NULL;
  }
  return(fOK);
}
BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
{
  switch (fdwReason)
  {
    case DLL_PROCESS_ATTACH:
     g_hinstDll = hinstDll;
     break;
  }
  return(TRUE);
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved