rlev wrote:I have a program that start a external win32 app using CreateProcess API.
This external app is controlled by keyboard command....what i would like to do is disable the keyboard in this external app.
Is it a Console app or a GUI app?
rlev wrote:I have search online for answers and I found that a global keyboard hook could do this.
You do not need a global hook. CreateProcess() returns the ID of the spawned process's main thread. You can pass that ID to SetWindowsHookEx() to install a thread-specific hook into just the new process without having to hook any other running processes (if the new process is multi-threaded, then you would need a global hook, unless you call SetWindowsHookEx() on each individual thread). You do need to implement your hook inside a DLL, since you are hooking an external process.
Do keep in mind, however, that hooking is not always a good way to go, not to mention that it is subject to OS restrictions, such as security rights, UAC elevation, the inability to hook 64-bit apps with a 32-bit DLL, etc. So you might not be able to install the hook into the other process unless your app is running with admin rights and the app is not a 64-bit app.
You did not say where the AV is occuring. But that code is incomplete. For instance, it is missing a key requirement in global hooks - it is not sharing the HHOOK handle amongst multiple instances of the hook DLL (the code is installing a global hook, which is hooking every running process). That is important so the correct HHOOK value gets passed to CallNextHookEx(), but that in itself is not likely to be causing the AV.
rlev wrote:Also I found this thread:
viewtopic.php?f=10&t=905I tried to compile the example but I think the code is incomplete.
Why do you think that?