Thursday, March 6, 2008

Windows CE Keyboard Hook (Error 31)

http://msdn.microsoft.com/chats/transcripts/mobileembedded/06_0830_msdn_wince.aspx


PaulT_MVP (Expert):
Q: I have two .NET EXEs both installing a WH_KEYBOARD_LL keyboard hook on Windows Mobile 5 Smartphone and the second EXE fails to create it's hook; GetLastError returns 31, which means "A device attached to the system is not functioning." What is going on?
A: Rob, I just tried this with two *unmanaged* EXEs and the second gets NULL back from SetWindowsHookEx, also. I think that having two keyboard hooks must not be supported.

Pablo Candelas Gonzalez (Expert):
Q: Exactly, the 2nd SetWindowsHookEx returns 0, with GetLastError returning 31. How can it be the case that two separate .NET exes cannot install a keyboard hook? Think about that... two apps that have nothing to do with each other prevent the other app from creating the hook. horrible, eh? There must be a solution?
A: About SetWindowsHookExW, I am pretty sure GWES only supports one Keyboard Hook and not more… this is cached, thus the second time you try to call this API it will return the not so useful ERROR_GEN_FAILURE. Sorry for the unfortunate limitation, but that is the way it is today.

No comments: