2009-08-23 3 views
0

Ich möchte eine Software-Test-Automatisierungs-Software erstellen und ich bin mit Windows-Hooks dafür herumspielen.Brauchen Sie Hilfe mit Windows Journal Record Hook

Also habe ich den folgenden C-Code erstellt. Kann mir jemand sagen, wie ich das korrigieren kann?

#include "windows.h" 

// the call back function 
LRESULT CALLBACK JournalRecordProc(int code, WPARAM wParam, LPARAM lParam) 
{ 

    HHOOK hhk = 0; 

    if (code > 0) 
    { 
     // save Data in File 
    } 

    if (code < 0) 
    { 
     // work done: now pass on to the next one that does hooking 
     CallNextHookEx(hhk, code, wParam, lParam); 
    } 

    /* 
    if (code ==) 
    { 
     // ESC button pressed -> finished recording 
     UnhookWindowsHookEx(hhk); 
    } 
    */ 

} 

int main() 

{ 
    int iRet = 0; 

    HHOOK hHook = 0; 

    HINSTANCE hMod = 0; 

    HOOKPROC (*hHookProc)(int, WPARAM, LPARAM); 

     hHookProc = &JournalRecordProc; 

    // type of hook, callback function handle, hinstance [dll ?], 0 for systemwide 
    hHook = SetWindowsHookEx(WH_JOURNALRECORD, hHookProc, hMod, 0); 

    return iRet; 
} 

Als ich das kompilieren bekomme ich die Fehler Compiler:

error C2440: '=': 'LRESULT (__stdcall 
*)(int,WPARAM,LPARAM)' kann nicht in 'HOOKPROC (__cdecl 
*)(int,WPARAM,LPARAM)' konvertiert werden (could not be converted) 

error C2440: 'Funktion': 'HOOKPROC (__cdecl *)(int,WPARAM,LPARAM)' kann nicht in 'HOOKPROC' konvertiert werden (could not be converted) 

warning C4024: 'SetWindowsHookExA': Unterschiedliche Typen für formalen und übergebenen Parameter 2 

Antwort

2

Es gibt keine Notwendigkeit, eine separate hHookProc Variable zu deklarieren - nur Ihre Prozedur SetWindowsHookEx passieren direkt:

hHook = SetWindowsHookEx(WH_JOURNALRECORD, JournalRecordProc, hMod, 0); 

Sie Außerdem benötigen Sie ein gültiges Modulhandle:

HINSTANCE hMod = GetModuleHandle(NULL); 

Nachdem Sie diese Änderungen vorgenommen und Ihre JournalRecordProc einen Wert zurückgegeben haben, wird alles jetzt kompiliert und funktioniert für mich (in diesem Fall ist SetWindowsHookEx auf jeden Fall erfolgreich).

+0

Vielen Dank! Ich wusste nicht, dass ich den Namen der Funktion (JournalRecordProc - für die Funktion handle) direkt in den Funktionscall von SetWindowsHookEx() setzen kann :-) –