2

Error:

error:com.sun.jna.Pointer connot be cast to com.sun.jna.platform.win32.WinDef.LPARAM error location:return User32.INSTANCE.CallNextHookEx(hHook, nCode, wParam, keyInfo.getPointer());

Code:

HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);

HOOKPROC lpfn = new LowLevelKeyboardProc()
{
    int count = 1;

    public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT keyInfo)
    {
        System.out.println("nCode =" + nCode + ", wParam =" + wParam 
            + ", vkCode=" + keyInfo.vkCode);
        count++;

        if (count > 100)
        {
            quit = true;
        }

        return User32.INSTANCE.CallNextHookEx(hHook, nCode, wParam, keyInfo.getPointer());
    }
};

1 Answer 1

2

You need to manually construct the LPARAM from the pointer's value as seen in the JNA KeyHook example.

Pointer ptr = keyInfo.getPointer();
long peer = Pointer.nativeValue(ptr);
return User32.INSTANCE.CallNextHookEx(hHook, nCode, wParam, new LParam(peer));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.