43行 DetourAttach(&(PVOID&)CDetour::Real_Execute,(PVOID)(&(PVOID&)CDetour::Mine_Execute));報錯
第二個引數該怎么寫
// win32sqlceshi1.cpp : 定義應用程式的入口點。
//
#include "stdafx.h"
#include "win32sql.h"
#include "detours.h"
#pragma comment(lib, "detours.lib")
#pragma comment(lib, "detoured.lib")
#import "msado15.dll" no_namespace rename("EOF","adoEOF") rename("BOF","adoBOF")
//CLASS
class CDetour
{
public:
_RecordsetPtr Mine_Execute(_bstr_t CommandText, VARIANT * RecordsAffected, long Options);
static _RecordsetPtr(CDetour::* Real_Execute)(_bstr_t CommandText, VARIANT * RecordsAffected, long Options);
};
_RecordsetPtr CDetour::Mine_Execute(_bstr_t CommandText, VARIANT * RecordsAffected, long Options)
{
_RecordsetPtr ret =(this->*Real_Execute)(CommandText,RecordsAffected,Options);
return ret;
}
_RecordsetPtr(CDetour::*CDetour::Real_Execute)(_bstr_t CommandText, VARIANT * RecordsAffected, long Options)=(_RecordsetPtr(CDetour::*)(_bstr_t CommandText, VARIANT * RecordsAffected, long Options))&Connection15::Execute;
static int (WINAPI* OLD_MessageBoxW)(HWND hWnd,LPCWSTR lpText,LPCWSTR lpCaption,UINT uType) = MessageBoxW;
int WINAPI NEW_MessageBoxW(HWND hWnd,LPCWSTR lpText,LPCWSTR lpCaption,UINT uType)
{
//修改輸入引數,呼叫原函式
int ret = OLD_MessageBoxW(hWnd,L"輸入引數已被HOOK修改",L"[Detour測驗]",uType);
return ret;
}
VOID Hook()
{
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
//這里可以連續多次呼叫DetourAttach,表明HOOK多個函式
DetourAttach(&(PVOID&)OLD_MessageBoxW,NEW_MessageBoxW);
DetourAttach(&(PVOID&)CDetour::Real_Execute,(PVOID)(&(PVOID&)CDetour::Mine_Execute));
DetourTransactionCommit();
}
VOID UnHook()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
//這里可以連續多次呼叫DetourDetach,表明撤銷多個函式HOOK
DetourDetach(&(PVOID&)OLD_MessageBoxW,NEW_MessageBoxW);
DetourTransactionCommit();
}
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
{
Hook();
MessageBoxW(0,L"開始",L"測驗",0);
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/151707.html
標籤:C++ 語言
