通过安装WH_CALLWNDPROC全局钩子将DLL注入所有进行窗口过程的进程

// HookDll.cpp : 定义 DLL 应用程序的导出函数。
//

#include "stdafx.h"
#include 

static HHOOK hHook=NULL;
HINSTANCE hInstance; //钩子函数所在模块的句柄

BOOL APIENTRY DllMain( HANDLE hModule, 
					  DWORD  ul_reason_for_call, 
					  LPVOID lpReserved
					  )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		hInstance = (HINSTANCE)hModule;
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		break;
	default:
		break;
	}

	return TRUE;
}


LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{

	// 一般来说,所有运行的进程(有窗口过程的)都会加载这个 钩子过程了
	return CallNextHookEx(hHook, nCode, wParam, lParam );
}

BOOL SetHook()
{
	hHook = SetWindowsHookEx(WH_CALLWNDPROC, HookProc, hInstance,NULL);
	return hHook != NULL;  
}

BOOL EndHook()
{
	return UnhookWindowsHookEx(hHook);
}

你可能感兴趣的:(c/c++)