Bonsoir,
je voulais savoir si il était possible de creer un hook lors du chargement d'un dll c'est à dire dans la fonction DllMain d'un dll, j'essaye de le faire mais n'y arrive pas :
#include "windows.h"
HHOOK hKeyb;
HINSTANCE hDll;
LRESULT CALLBACK KeybProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0) // do not process message
return CallNextHookEx(hKeyb, nCode, wParam, lParam);
MessageBox(NULL, "Appui", "Message", MB_OK);
return CallNextHookEx(hKeyb, nCode, wParam, lParam);
}
void Hook()
{
hKeyb = SetWindowsHookEx(WH_KEYBOARD, KeybProc, hDll, 0);
if(!hKeyb)
MessageBox(NULL, "Erreur", "Erreur", MB_OK);
}
void UnHook()
{
if(hKeyb)
UnhookWindowsHookEx(hKeyb);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
hDll = hinstDLL;
if(fdwReason == DLL_PROCESS_ATTACH)
{
Hook();
}
if(fdwReason == DLL_PROCESS_DETACH)
{
UnHook();
}
return TRUE;
}