Bonjour, voilà, je fais un système de hook et c'est la première fois que c'est pas global, donc j'ai quelques problèmes.

Ce que j'essaie de hooké en question, c'est une projection Adobe Flash.

Voilà le code du loader :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <windows.h>
 
int main(int argc, char *argv[])
{
    HWND w = FindWindowA("ShockwaveFlash", NULL);
    SetWindowTextA(w, "Game [init]");
 
    DWORD tid;
    GetWindowThreadProcessId(w, &tid);
 
    HINSTANCE dll = LoadLibraryA("gamehook.dll");
    FARPROC hookproc = GetProcAddress(dll, "_Z6hookerijl@12");
    HHOOK hKeyHook = SetWindowsHookExA(WH_CALLWNDPROC, (HOOKPROC)hookproc, dll, tid);
    if(hKeyHook == NULL)
    {
        LPSTR lpMsgBuf;
        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
 
        MessageBoxA(NULL, lpMsgBuf, "Error", MB_ICONERROR | MB_OK);
    }
    while(hKeyHook != INVALID_HANDLE_VALUE && w != NULL)
    {
        Sleep(1000);
    }
    UnhookWindowsHookEx(hKeyHook);
 
    return 0;
}
voilà le header de ma DLL :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
#ifndef __DFM_H__
#define __DFM_H__
 
#define IDC_ABOUT 30001
 
#include <windows.h>
 
__declspec(dllexport) LRESULT CALLBACK hooker(int nCode, WPARAM _wParam, LPARAM _lParam);
 
#endif
Et enfin, le code source de ma DLL :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "main.h"
 
__declspec(dllexport) LRESULT CALLBACK hooker(int nCode, WPARAM _wParam, LPARAM _lParam)
{
    if (nCode == HC_ACTION)
    {
        CWPSTRUCT hooked =  *((CWPSTRUCT*)_lParam);
        HWND hwin = hooked.hwnd;
        UINT uMsg = hooked.message;
        WPARAM wParam = hooked.wParam;
        LPARAM lParam = hooked.lParam;
        MessageBoxA(hwin, "ça marche !", "Test", MB_OK | MB_ICONINFORMATION);
    }
    return CallNextHookEx(NULL, nCode, _wParam, _lParam);
}
Donc si ça marche, une MessageBox s'affiche.

Or, il y a un problème, GetLastError() égal à ERROR_INVALID_PARAMETER, donc apparament l'ID du thread est invalide.

Je ne vois pas le problème, pouvez-vous m'aider ?

Cordialement, Iron.