Salut,
je commence en C++, et je voudrais creer un hook global avec Dev-C++
Le code de la dll et de l'exe se compile sans erreur, les fonction de
mises en place et de désinstallation des hooks marchent, mais le Hook,
ne s'effectue pas!!
Voila le code de la dll :
#include <windows.h>
HHOOK hhk;
HINSTANCE hThisMod;
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam);
__declspec (dllexport) int InitHook (void);
__declspec (dllexport) int EndHook (void);
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if ( nCode < 0 || nCode == HC_NOREMOVE )
return CallNextHookEx(hhk, nCode, wParam, lParam);
// Pour éviter les répétitions
if (((DWORD)lParam & 1<<30) != FALSE)
return CallNextHookEx(hhk, nCode, wParam, lParam);
if (wParam== 'A')
{
MessageBeep(MB_OK);
return 1;
}
return CallNextHookEx(hhk, nCode, wParam, lParam);
}
BOOL APIENTRY DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv)
{
if (reason==DLL_PROCESS_ATTACH)
hThisMod = hinst;
return 1;
}
__declspec (dllexport) int InitHook (void)
{
if (!hhk)
hhk = SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC)KeyboardProc, hThisMod, 0);
return 1;
}
__declspec (dllexport) int EndHook (void)
{
if (hhk)
{
UnhookWindowsHookEx (hhk);
return 1;
}
return 0;
}
La fonction InitHook me renvois 1 (donc la fonction est bien appelé
et elle retourne une valeur), et la fonction EndHook 0 (donc le hook
n'a pas lieu)..
Mais par contre je comprends pas pourquoi !!
Ca fait un bout de temps que je cherches et toute aide est bienvenue.