-4

I want unhook all hook messages (ring 3) and not is able because in Java seems that not is possible the cast from int for HHOOK type.

Someone know how solve this?

import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.User32;

public static void main(String[] args) {

    final User32 lib = User32.INSTANCE;

        for(int i = 9999999; i >= 0; i--)

            lib.UnhookWindowsHookEx((HHOOK(i)); // Here is the trouble

}

Thank you.

1 Answers1

0

You can't.

While in native Win32 various handles are basically an integer type, they are not pointers and they are not really indexes, and you are not suppose to brute force unhooking the way you are trying to do.

In any case, in the JNA, the HHOOK type is an object, and it has no API for creating one from in type.

I am not sure what you are trying to do, but you should save any HHOOK you receive from SetWindowsHookEx, and only call UnhookWindowsHookEx on those objects.

Lev M.
  • 6,088
  • 1
  • 10
  • 23
  • thank you by answer. *"`save any HHOOK you receive from SetWindowsHookEx, and only call UnhookWindowsHookEx on those objects`"* this require a enumeration of all message hooks, right? if yes, will be hard implement this in Java using JNA. –  Nov 17 '18 at 14:32
  • I don't know what you mean by "this require a enumeration of all message hooks, right" - your program should only unhook the messages it has hooked. I am not sure Win32 API will even let you unhook a hook belonging to another process even if you somehow obtain it. – Lev M. Nov 17 '18 at 14:54