Bonjour a tous,
Voila je suis sur le point de finir mon 1er hook, mais voila , il ne fonctionne que une fois. Il intercepte une fois le message voulu (WM_CLOSE ici) et puis plus rien. Je ne voi pas ou est le problème. Je vai mettre ici le code :
Le cpp :
static HHOOK hoHook;
static HINSTANCE hiDll;
/* Installe un hook. */
DLLEXPORT BOOL InstallHook(){
hoHook = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)getMsgHook,hiDll,0);
if(hoHook != NULL) return TRUE;
return FALSE;
}
/* désnstalle le hook. */
DLLEXPORT void UnInstallHook(){
UnhookWindowsHookEx(hoHook);
}
/* Fonction du hook. */
LRESULT CALLBACK getMsgHook(int code, WPARAM wParam, LPARAM lParam){
FilterMsg(code,wParam,lParam);
return CallNextHookEx(hoHook,code,wParam,lParam);
}
/* Traitement des messages interceptés. */
void FilterMsg(int code, WPARAM wParam, LPARAM lParam){
UINT uiMsg;
uiMsg = ((MSG*)lParam)->message;
switch(uiMsg){
case WM_CLOSE : MessageBox(NULL,"Message intercepted and stoped","ALT",MB_OK);
((MSG*)lParam)->message = WM_NULL;
break;
}
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
hiDll = hInst;
break;
case DLL_PROCESS_DETACH:
UnInstallHook();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
le header :
#include <windows.h>
#include <stdio.h>
#define DLLEXPORT __declspec(dllexport)
#define DLLIMPORT __declspec(dllimport)
LRESULT CALLBACK getMsgHook(int code, WPARAM wParam, LPARAM lParam);
void FilterMsg(int code, WPARAM wParam, LPARAM lParam);
Voila , j'espère que quelq'un saura le pourquoi du comment

Merci d'avance.