Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Mouse hook from JNI doesn't work

802678Oct 3 2010 — edited Oct 3 2010
Hello

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

Comments

paulgallstar

Update on this, its when there is an error with the spec, when I try and edit it, the spec tab freezes, click on another tab and go back to the spec there is no text.

Alan Lawlor

+1 : I get this problem intermittently also

Alan

I see it, not good.

1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 31 2010
Added on Oct 3 2010
1 comment
383 views