c++ - error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'HOOKPROC' -
i`m working on keylogger, , got
keylogger.h:
#pragma once #include <stdio.h> #include <windows.h> class keylogger { kbdllhookstruct kbdstruct; byte keystate[256]; wchar buffer[16]; public: hhook hkeyhook; keylogger(void); ~keylogger(void); lresult winapi keyevent(int ncode, wparam wparam, lparam lparam); };
keylogger.cpp:
#include "keylogger.h" keylogger::keylogger(void) { } keylogger::~keylogger(void) { } lresult winapi keylogger::keyevent(int ncode, wparam wparam, lparam lparam) { if( (ncode == hc_action) && ((wparam == wm_syskeydown) || (wparam == wm_keydown)) ) { kbdstruct = *((kbdllhookstruct*)lparam); getkeyboardstate((pbyte)&keystate); tounicode(kbdstruct.vkcode, kbdstruct.scancode, (pbyte)&keystate, (lpwstr)&buffer, sizeof(buffer) / 2, 0); printf("%x\t%c\n", buffer[0], buffer[0]); } return callnexthookex(hkeyhook, ncode, wparam, lparam); }
main.cpp:
#include "keylogger.cpp" int main(hinstance hinstance, hinstance hprevinstance, pstr szcmdline, int ncmdshow) { keylogger kl = keylogger(); kl.hkeyhook = setwindowshookex(wh_keyboard_ll, (hookproc) kl.keyevent, getmodulehandle(null), 0); msg message; while(getmessage(&message, null, 0, 0)) { translatemessage(&message); dispatchmessage(&message); } unhookwindowshookex(kl.hkeyhook); return 0; }
on following line kl.hkeyhook = setwindowshookex(wh_keyboard_ll, (hookproc) kl.keyevent, getmodulehandle(null), 0);
error c2440: 'type cast' : cannot convert 'overloaded-function' 'hookproc'
is there way fix this?
winapi c programming interface, doesn't know classes. callback should static:
static lresult winapi keyevent(int ncode, wparam wparam, lparam lparam);
then
kl.hkeyhook = setwindowshookex(wh_keyboard_ll, (hookproc) keylogger::keyevent, getmodulehandle(null), 0);
Comments
Post a Comment