Bonjour,
J'essaye de faire un hook (mon 1er) mais a chaque fois qu'il se lance j'ai un pb d'affectation mémoire.
en fait le HOOK récupère les actions clavier et reagit au moment d'une action sur la fleche du bas.
A la compilation (DEVC++) il n'y a aucune erreur.
Voici le code (seulement les parties avec le HOOK):
#include <windows.h>
#include "psapi.h" // Pour les process mettre la librairie -lpsapi
#include <stdio.h>
#include <ctype.h> // Pour tolower
#include <stdlib.h>
#include <time.h>
HHOOK hhk = 0;
[...]
////////////////////////////////////////////////////////////////////////////////
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK GetKey(HWND, WPARAM, LPARAM);
[...]
LRESULT CALLBACK GetKey(int nCode, WPARAM wParam, LPARAM lParam)
{
MSG *lpmsg;
lpmsg = (MSG*) lParam;
if(nCode < 0) goto defRet;
if(lpmsg->message == WM_KEYDOWN && lpmsg->wParam == VK_DOWN)
{
MessageBox (NULL, "ok" , "ok", 0);
return 1;
}
defRet:;
return (CallNextHookEx(hhk, nCode, wParam, lParam));
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
hhk = SetWindowsHookEx(WH_KEYBOARD, GetKey, 0, GetCurrentThreadId());
break;
[...]
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
Fin:;
if(hhk) UnhookWindowsHookEx(hhk);
exit(0);
}
return 0;
}
Voila si vous pouvez m'aider.
GuitouLeFoux
"Le secret du sage est de briller dans l'ombre"