Download source files and demo project - 102 Kb
Introduction
Based on DelayLoadProfileDLL.CPP, by Matt Pietrek for MSJ February 2000. This code is intended to be included in a DLL inserted through a global Windows Hook (CBT hook for example). It will replace functions from other DLLs (e.g. DDRAW.DLL) with functions from your DLL.
Functions are hooked by passing a parameter structure to the HookAPICalls()
function as follows:
SDLLHook D3DHook =
{
"DDRAW.DLL",
false, NULL,
{
{ "DirectDrawCreate", MyDirectDrawCreate },
{ NULL, NULL }
}
};
BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD fdwReason, LPVOID lpReserved)
{
if ( fdwReason == DLL_PROCESS_ATTACH )
{
hDLL = hModule;
DisableThreadLibraryCalls( hModule );
GetModuleFileName( GetModuleHandle( NULL ), Work, sizeof(Work) );
PathStripPath( Work );
if ( stricmp( Work, "myhooktarget.exe" ) == 0 )
HookAPICalls( &D3DHook );
}
return TRUE;
}
Now all that remains is to get your DLL loaded into the target process.