我将 Visual Studio 2003 与 CDetour 一起使用。
这次我不能提供 SSCE,所以这就是我所做的:
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
CDetour CreateDevice_Det;
IDirect3D9* Direct3DCreate9_Hook( UINT SDKVersion )
{
MessageBox( GetForegroundWindow(), "Direct9 Create Hooked", "dForce.dll", MB_OK );
d3d = Direct3DCreate9(D3D_SDK_VERSION);
return d3d;
}
BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID reserved)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
{
HMODULE hd3d = GetModuleHandle( "d3d9.dll" );
if( hd3d == 0 )
{
MessageBox( GetForegroundWindow(), "d3d9.dll still not loaded", "dForce.dll", MB_ICONSTOP );
return FALSE;
}
DWORD lpAddr = (DWORD)GetProcAddress( hd3d, "Direct3DCreate9" );
if( lpAddr == 0 )
{
MessageBox( GetForegroundWindow(), "could not find valid d3d9.dll create device address", "dForce.dll", MB_ICONSTOP );
return FALSE;
}
CreateDevice_Det.Detour( (LPBYTE)lpAddr, (LPBYTE)Direct3DCreate9_Hook );
CString strDetoured;
strDetoured.Format( "CreateDevice Hooked! Address: %x", (LPVOID)lpAddr );
MessageBox( GetForegroundWindow(), strDetoured, "dFoce.dll", MB_ICONINFORMATION );
}break;
}
return TRUE;
}
我已经以同样的方式成功地钩住了另一个函数,例如LoadLibrary
(来自 kernel32.dll),这个 dll 之前当然是Direct3DCreate9
在主程序上加载的,我也在控制台 wi32 程序上尝试过这个,但我的钩子函数仍然没有被调用。我错过了什么吗?
已编辑
显然,CDetour 根本与 MS Detours 无关(发现它在谷歌上搜索 ms detours)。