// dlltest.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
HHOOK g_hh = 0;
HANDLE g_hm = 0;
char *szWindowName = "dddtese";
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
OutputDebugStringA("按键\r\n");
if ((wParam==VK_HOME)&&((lParam&(1<<31))==0))
{
OutputDebugStringA("Hmoe\r\n");
}
return CallNextHookEx(g_hh,code,wParam,lParam);
}
extern "C" __declspec(dllexport)void SetHook()
{
OutputDebugString("注入\r\n");
HWND hwnd = ::FindWindow(NULL,szWindowName);
DWORD pid = 0;
DWORD tid = 0;
HINSTANCE hmod = NULL;
if(hwnd)
{
OutputDebugStringA("找到窗口\r\n");
tid = ::GetWindowThreadProcessId(hwnd,NULL);
g_hh = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,(HINSTANCE)g_hm,tid);
if(g_hh == NULL)
OutputDebugStringA("错误\r\n");
}
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if(ul_reason_for_call == DLL_PROCESS_ATTACH)
{
__asm int 3
g_hm = hModule;
SetHook();
}
return TRUE;
}
我把这个dll注入到目标进程里面,SetWindowsHookEx成功后按任何键却没有进入KeyboardProc,高手解答一下为什么
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课