首页
社区
课程
招聘
win864位用SetWindowsHookEx失败
发表于: 2014-4-18 11:26 3551

win864位用SetWindowsHookEx失败

2014-4-18 11:26
3551
#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直播授课

收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 228
活跃值: (115)
能力值: ( LV5,RANK:70 )
在线值:
发帖
回帖
粉丝
2
X64位下系统自带的TXT文本进程是64位的,你一32位模块想干嘛!?!?
2014-4-18 12:08
0
雪    币: 294
活跃值: (119)
能力值: ( LV5,RANK:70 )
在线值:
发帖
回帖
粉丝
3
thx~~~
2014-4-18 12:56
0
游客
登录 | 注册 方可回帖
返回
//