I want to build a software test automation software and I'm playing around with Windows Hooks for that.
So I built the following C code. Can anyone tell me how to correct it ?
#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;
}
When I compile this I get the compiler errors:
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