Can 64bit Hook application affect 32bit hook appl when both are running together on Win 7(64bit)?

Dec 13, 2011 at 5:59 AM

I have created 32bit CBT hook and 64bit mouse hook applications.

First i start 32bit CBT hook, it works fine then i started 64bit mouse hook application. Now 64bit Mouse hook is working fine, but if I start any 32bit window application, it is not responding and it is unhooked also. After installation of 64bit hook, No 32bit applications work fine in the sense it is not responding. But when kill that 64bit Mouse hook, 32bit applications start to work. 32bit CBT hook is also happening.

 Anyone can please suggest the possible solutions,

32bit exe that installs 32bit hook,

hinstDLL = LoadLibrary(_T("SampHook.dll"));

fpCBTProc = (HOOKPROC)GetProcAddress(hinstDLL, "MyHookProc");

hhkCallWndProc = SetWindowsHookEx( WH_CBT, fpCBTProc,hinstDLL,0);

 fpSetCBTHook = (SETHOOKPROC)GetProcAddress(hinstDLL,"SetCallWndProcHookHandle");

fpSetCBTHook(hhkCallWndProc);

32bit hook dll,

LRESULT CALLBACK ScreenPosWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

BOOL bResult = TRUE;

const WNDPROC wpOldProc = (WNDPROC) ::GetProp(hWnd, WND_PROC_PROP);

 if (wpOldProc == NULL)

 bResult = FALSE;

 LRESULT lResult = 0;

if (bResult)

 lResult = ::CallWindowProc(wpOldProc, hWnd, uMsg, wParam, lParam);

 else

 lResult = ::DefWindowProc(hWnd, uMsg, wParam, lParam);

return lResult;

 }

__declspec(dllexport) LRESULT WINAPI MyHookProc(int nCode, WPARAM wParam, LPARAM lParam)

{

switch(nCode)

{

case HCBT_CREATEWND:

 {

 const HWND hWnd = (HWND) wParam;

const WNDPROC wpOrigProc = (WNDPROC)::SetWindowLong(hWnd,GWL_WNDPROC,(LONG) ScreenPosWndProc);

 ::SetProp(hWnd, WND_PROC_PROP, wpOrigProc);

 } break;

 }

return CallNextHookEx(g_hhkCallWndProc, nCode, wParam, lParam);

 }

 __declspec(dllexport) void CALLBACK SetCallWndProcHookHandle(HHOOK hHook)

 { g_hhkCallWndProc = (HHOOK) hHook; }

64bit exe that installs 64bit hook,

hinstDLL = LoadLibrary(_T("SampHook64.dll"));

fpMouseProc = (HOOKPROC)GetProcAddress(hinstDLL, "MyHookProc");

hhkMouse = SetWindowsHookEx(WH_MOUSE, fpMouseProc, hinstDLL, 0);

fpSetMouseHook = (SETHOOKPROC)GetProcAddress(hinstDLL, "SetMouseHookHandle");

fpSetMouseHook(hhkMouse);

64bit dll,

 __declspec(dllexport) LRESULT WINAPI MyHookProc(int nCode, WPARAM wParam, LPARAM lParam)

{ return CallNextHookEx(g64_hhkMouse, nCode, wParam, lParam); }

 __declspec(dllexport) void SetMouseHookHandle(HHOOK hHook)

{ g64_hhkMouse = (HHOOK) hHook; }

 Note :

 1. Just for checking, I have kept empty hook procedure, am getting same issue even procedure is having implementation.

2. I have created 32bit and 64bit exe files and dll files with separate name, and I have checked by process explorer it is loading corresponding dlls to processes.