Question

I have used in module this helper class: http://tinyurl.com/pb3vxw6 and I have following problem: SetWindowsHookEx always returns zero value. As I mentioned this API function is not documented. Is this API function still supported in Win CE 6.0 devices? Should I use another API function? How can realize keyboard hooks in another way?

public void Start()
{
    if (hHook != 0)
    {
         // Unhook the previouse one
         this.Stop();
    }

    hookDeleg = new HookProc(HookProcedure);
    // in hHook returned zero value  
    hHook = SetWindowsHookEx(WH_KEYBOARD_LL, hookDeleg, GetModuleHandle(null), 0);

    if (hHook == 0)
    {  // Exception throwed
       throw new SystemException("Failed acquiring of the hook.");
       // May be better?
       // Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());

    }
}
Was it helpful?

Solution

Is this program or DLL? You need dll to get keyboard hook working (and hook keyboard your dll). I should past hInstance instead GetModuleHandle(null). So when you hook keyboard windows actually calls that dll.

OTHER TIPS

You do not really need a DLL but undcoumented can mean not implemented.

http://www.hjgode.de/wp/2009/12/04/hooking-the-keyboard-message-queue-in-compact-framework-code/ The code above worked on several devices.

What is GetLastError giving?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top