示例代码:方便以后用的时候复制.
#include "stdafx.h"
#include <windows.h>
#include "include/detours.h"
#pragma comment(lib, "lib/detours.lib")
// target pointer for the uninstrumented MessageBox API
static int (WINAPI *SysMessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) = MessageBoxA;
// detour function that replaces the MessageBox API
int WINAPI HookMessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
{
return SysMessageBox(hWnd, "HookMsg调用中...", "证明HOOK成功了", uType);
}
int _tmain(int argc, _TCHAR* argv[])
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)SysMessageBox, HookMessageBox);
DetourTransactionCommit();
MessageBoxA(NULL, "", "", MB_OK);
return 0;
}