I have only used to Detours 1.5 before, and the documentation for 3.0 isn't great. So in case anyone struggles:
PHP Code:
PVOID SetDetour( PVOID* ppTarget, PVOID pHandler )
{
if ( DetourTransactionBegin( ) != NO_ERROR )
return FALSE;
if ( DetourUpdateThread( GetCurrentThread( ) ) != NO_ERROR )
{
DetourTransactionCommit( );
return NULL;
}
PDETOUR_TRAMPOLINE pTrampoline = NULL;
if ( DetourAttachEx( ppTarget, pHandler, &pTrampoline, NULL, NULL ) != NO_ERROR )
{
DetourTransactionCommit( );
return NULL;
}
if ( DetourTransactionCommit( ) != NO_ERROR )
{
DetourTransactionAbort( );
return NULL;
}
return pTrampoline;
}
Retouring works the same, call
DetourDetach as opposed to
DetourAttach/DetourAttachEx
PHP Code:
g_lpDispatchMessage = reinterpret_cast<PVOID*>( 0x14317DCD0 );
oDispatchMessage = reinterpret_cast<tDispatchMessage>( SetDetour( &g_lpDispatchMessage, hkDispatchMessage ) );
RemoveDetour( &g_lpDispatchMessage, hkDispatchMessage );