Reputation: 15746
I'm using visual studio 2003 with CDetour.
This time I cannot give a SSCE so this is what I've done:
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;
}
I have hooked another functions such as LoadLibrary
(from kernel32.dll) with success the same way, this dll is of course loaded before Direct3DCreate9
on the main program, I have also tried this on a console wi32 program but my hooked function is still not called. Am I missing something?
Apparently CDetour is not related to MS Detours at all (found it googling for ms detours).
Upvotes: 0
Views: 777
Reputation: 15746
After you CreateDevice_Det.Detour( ...)
you must apply the detour, it's not auto.
CreateDevice_Det.Apply()
.
Upvotes: 0
Reputation: 1490
I dont see detourTransactionBegin(), DetourUpdateThread() and DetourTransactioncommit() calls here. API Hooking with MS Detours have a good explaination.
Upvotes: 1