Simply: I want to evaluate messages that are send to a window by WinApi. This window is not part of my application.
So when messages are send to the window of let's say
notepad
I want to read them and forward them to the actual window proc of the notepad process. What is the right approach ?
I have this so far. But it seems not to work:
private static IntPtr hook = IntPtr.Zero;
private static IntPtr callWndProc(int code, IntPtr wParam, IntPtr lParam)
{
Console.WriteLine("hello world");
CWPSTRUCT a = new CWPSTRUCT();
Marshal.PtrToStructure(lParam, a);
Console.WriteLine(a.message);
return Windows.CallNextHookEx(hook, code, wParam, lParam);
}
static void Main(string[] args)
{
Process[] procs = Process.GetProcessesByName("notepad");
if (procs.Length > 0)
{
hook = Windows.SetWindowsHookEx(WH_CALLWNDPROC, Marshal.GetFunctionPointerForDelegate((HookProc)callWndProc), procs[0].Handle, procs[0].Id);
// last result: (126) The specified module could not be found.
// hook == 0
}
Console.ReadKey();
}