C++ SetWindowsHookEx WH_KEYBOARD_LL Correct Setup

时光怂恿深爱的人放手 提交于 2019-12-04 07:30:18

You can't block on a syscall (the getchar), you have to be running a window loop and processing messages before your hook gets called.

On Windows XP, you need, you need to pass hInstance (from WinMain) as the third argument to SetWindowsHookEx. For example:

int WINAPI WinMain
( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  LPTSTR lpCmdLine, int nCmdShow ) {

  hookHandle = SetWindowsHookEx ( WH_KEYBOARD_LL, keyHandler, hInstance, 0 );

// ...

I suggest simle first;

// VB: Retrieve the applications instance HINSTANCE appInstance = GetModuleHandle(NULL);

and then: hookHandle = SetWindowsHookEx(WH_KEYBOARD_LL, keyHandler, appInstance, 0);

// ..., but there are another errors later, too

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!