Mouse hook from JNI doesn't work
802678Oct 3 2010 — edited Oct 3 2010Hello
i am trying to register windows mouse hook(WH_MOUSE) from java using jni. (windows vista x64)
all is fine when i register hook from c++ application. strange things start to happen when the hook is registered inside jni.
i implemented a hook proc in 32bit dll, when it is injected into 32bit processes it looks ok, but 64bit applications stop responding. 64bit dll injected into all windows makes 32bit apps inactive for any mouse inputs, similar as in first scenario.
there are no problems with WH_KEYBOARD or WH_SHELL hooks
here is the code:
//dll loaded in jni function
extern "C" __declspec(dllexport) LRESULT HookMouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if(nCode<0)
{
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
if(wParam==WM_RBUTTONDOWN && nCode==HC_ACTION)
{
AfxMessageBox("inside mouse proc");
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
//jni dll
extern "C" JNIEXPORT jboolean JNICALL Java_winHook_WinHookUtil_setMouseHook(JNIEnv *env, jobject jObject)
{
HMODULE hModule=LoadLibrary("WinHook32.dll");
void* fnt=GetProcAddress(hModule, "HookMouseProc");
g_hookMouse=SetWindowsHookEx(WH_MOUSE, (HOOKPROC)fnt, hModule, NULL);
return JNI_TRUE;
}
i have no idea what is wrong. please help.
Edited by: user3530356 on 2010-10-03 16:19