Question

I have a big problem with SetWindowsHookEx and WH_CALLWNDPROC! When use SetWindowsHookEx for local hook

HHOOK hook = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, GetModuleHandle(NULL), GetCurrentThreadId());

all work fine, but when i try set global hook or hook for other program:

HHOOK hook = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, GetModuleHandle(NULL), threadId);

where threadId = GetWindowThreadProcessId(window, NULL);
and HWND window = ::FindWindow(NULL,"Program title");

i get NULL in hook...

I read very much for hooking but, i don't understand where is worng... I have a headache for a few days. Thank you in advance and sorry for my english.

Était-ce utile?

La solution

One way to do it:

  1. Put your CallWndProc function in a DLL
  2. Export that function using a def file with the following content:

LIBRARY

EXPORTS

    CallWndProc
  1. Done!
  2. (Try to always use GetLastError when a Win32 API Fails, and give the result when you ask something)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top