Try to dig up hook installing.
Code:
g_patch_hhook = SetWindowsHookEx(WH_GETMESSAGE, patch_GetMsgProc,
g_hinstance, client_thread_id);
if(g_patch_hhook == 0)
{
api_error("Failed to install hook in client");
return false;
}
WinAPI SDK says:
Code:
HHOOK SetWindowsHookEx(
int idHook, // type of hook to install
HOOKPROC lpfn, // address of hook procedure
HINSTANCE hMod, // handle of application instance
DWORD dwThreadId // identity of thread to install hook for
);
An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.
So, try to vary thease things, and call SetLastError(0) before SetWindowsHookEx() call, and call GetLastError() and FormatMessage() after.