-
-
win864位用SetWindowsHookEx失败
-
发表于:
2014-4-18 11:26
3551
-
win864位用SetWindowsHookEx失败
#include <windows.h>
HHOOK g_HookHandle;
HINSTANCE h_dll;
int WINAPI DddMain( HINSTANCE hDllHandle, DWORD dwReason, LPVOID lpreserved )
{
h_dll = hDllHandle;
return true;
}
LRESULT CALLBACK FunProc(int code,WPARAM wParam,LPARAM lParam)
{
MessageBoxA(NULL,"key press","hook insert",0);
return CallNextHookEx(0,code,wParam,lParam);
}
extern "C" _declspec(dllexport) void SetHook()
{
DWORD tid = 0;
HWND gameh = FindWindowA(NULL,"wlan.txt - 记事本");
if (gameh ==0)
{
return;
}
tid = GetWindowThreadProcessId(gameh,NULL);
g_HookHandle = SetWindowsHookEx(WH_KEYBOARD,FunProc,h_dll,tid);
}
extern "C" _declspec(dllexport) void UnHook()
{
UnhookWindowsHookEx(g_HookHandle);
}
// HookDemo.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
typedef void (*lpFun)();
HINSTANCE hdll;
lpFun SetHook;
lpFun UnHook;
int _tmain(int argc, _TCHAR* argv[])
{
hdll = LoadLibraryA("HookDll.dll");
if (hdll!=NULL)
{
printf("yes");
SetHook = (lpFun)GetProcAddress(hdll,"SetHook");
UnHook = (lpFun)GetProcAddress(hdll,"UnHook");
}
if (SetHook!=NULL)
{
printf("setHOOK");
SetHook();
}
getchar();
UnHook();
if (hdll!=NULL)
{
FreeLibrary(hdll);
}
system("pause");
return 0;
}
setHOOK也能输出。但是打开txt输入就是不跳messagebox
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课