This is a small example project demonstrating how to use DetourCreateProcessWithDllEx in Microsoft Detours.
DetoursTarget
is our target application, which does no more than aShowMessage
call.DetoursHook
is the DLL that we're going to attach to it, which intercepts thatShowMessage
call and dumps it intostdout
instead.DetoursTest
is the project that's going to runDetoursTest
withDetoursHook
attached.
- Build Detours by opening Developer Command Prompt for your according Visual Studio version,
cd
-ing to Detours directory, and runningnmake
. - Copy x86
detours.lib
anddetours.pdb
toDetoursTest/
andDetoursHook/
directories. - Open
DetoursTest.sln
, build solution for x86, then run.
- Much like normal
CreateProcess
,DetourCreateProcessWithDllEx
takes an absolute path for first argument. - DLL name argument can be (should be? It's non-Unicode) a relative path if the DLL is in the target application directory.
- The "DLL must contain an exported function with ordinal #1." part of documentation means that you need to add a
.def
file (here,detours.def
) and point it at someBOOL APIENTRY
function that doesn't seem to be actually get called or anything.