SetWindowsHookEx functioning returning NULL

前提是你 提交于 2019-12-03 18:02:02

SetWindowsHookEx fail if it called not for GUI thread. more exactly if Win32Thread field of KTHREAD is 0. you call SetWindowsHookEx too early - thread yet not GUI thread (not initialized gui subsystem). so you need wait for this, before call SetWindowsHookEx. not sure, are possible catch exactly moment (after thread call NtGdiInit), when already possible call SetWindowsHookEx, but simplest way call WaitForInputIdle(pi.hProcess, INFINITE) with handle of new created process and only after it return WAIT_OBJECT_0 call SetWindowsHookExW

also, as separate note - for what you allocate STARTUPINFO and STARTUPINFO from heap ? (and not free it late). simply declare it as local variables in function. also STARTUPINFO must be initialized, how minimum asSTARTUPINFO si = { sizeof(si) } ; also you not close process and thread handles

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