안녕하세요. 누구나 도와 주려고 미리 감사드립니다. 나는 CBT 윈도우 훅을 설정하려고하는데, Im은 전역 적으로 설정할 때 잘 작동하지만, 하나의 스레드에 연결할 때마다 실패합니다. 내가 아는 한, 임은 책에서 모든 것을하고있다. - 관리되지 않는 DLL에서 후크 프로 시저를 노출했다. - 내 응용 프로그램, dll 및 스레드 프로세스는 모두 32 비트이다. - 사용하는 스레드 ID가 정확하다 spy ++ 사용)SetWindowsHookEx가 스레드 ID와 함께 작동하지 않습니다.
C++ 코드에서 단 하나의 스레드를 연결하려고하면 관리 할 수 있습니다 ... 관리되지 않는 코드에서만 단일 스레드를 연결할 수 있습니까?
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetWindowsHookEx (int hookType, UIntPtr lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern UIntPtr GetProcAddress (IntPtr hModule, string procName);
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr LoadLibrary (string libraryName);
const int WH_CBT = 5;
void SetHook()
{
IntPtr dll = LoadLibrary(LIBRARY);
UIntPtr proc = GetProcAddress(dll, PROC);
uint threadId = GetAppWindowThreadId();
//assume that the threadId of the external window is correct, as I said I verified with spy++
//and assume that dll and proc both get correct values
IntPtr hookAddress = SetWindowsHookEx(WH_CBT , proc, dll, threadId);
//hookAddress is 0
}
Marshal.GetLastWin32Error는 무슨 말을해야합니까? –
nothing ... (의미 0) – Orran