Hi 2 all!
I have a problem with hooks! I wrote a function in my dll, wich i call from the main program. Here is the text of my dll and the main code:
dll:
Code:
#include <windows.h>
__declspec(dllexport)LRESULT CALLBACK HookProcedure(int code, WPARAM wParam, LPARAM lParam)
{
HHOOK hHook;
if(code<0) return CallNextHookEx(hHook, code, wParam, lParam );
MessageBox(NULL, "HOOK!", "hook", 0);
return CallNextHookEx(hHook, code, wParam, lParam );
}
main prog:
Code:
#include <windows.h>
#pragma comment(lib, "myhookdll")
__declspec(dllimport)LRESULT CALLBACK HookProcedure(int ,WPARAM, LPARAM);
......
case WM_CREATE:
hHook = SetWindowsHookEx( WH_KEYBOARD, (HOOKPROC)HookProcedure, GetModuleHandle(NULL), 0 );
if( hHook == NULL )
{
wsprintf(c, "%d", GetLastError());
MessageBox(hwnd, c, "Can't set hooK", 0);
}
When my program starts, it receives mesages from keyboard and show message box. But after i minimize my program the hook doesn't work. It seems like i set an a local hook, without using dll.
Help, plz. What is the problem?!