Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 350125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:31:19+00:00 2026-05-12T11:31:19+00:00

I’ve downloaded and compiled the Microsoft detouring library. Inside my project I’ve included the

  • 0

I’ve downloaded and compiled the Microsoft detouring library. Inside my project I’ve included the header file and added the .lib file as a dependency. Everything compiles without errors. Now I’ve been trying to detour DrawText, but for some reason that detoured function doesn’t get called at all. Similiarly I tried detouring the Sleep function and that worked as intended and the function I detoured to was called.

I’m not very well-versed in the business of API programming nor any other low level activities. I suspect it might have something to do with the fact that I’m trying to do this inside a console application instead of having the detouring done inside a DLL. I just find it strange that it would be able to detour Sleep in that case.

Is there something wrong with my approach or does the fault lie in the code?

#include <windows.h>
#include <stdio.h>
#include "detours.h"

int ( WINAPI *Real_DrawText )(HDC a0, LPCSTR a1, int a2, LPRECT a3, UINT a4) = DrawTextA;

int Mine_DrawText(HDC hdc, LPCSTR text,  int nCount, LPRECT lpRect, UINT uOptions)
{
   printf("TEST");
   return Real_DrawText(hdc, text, nCount, lpRect, uOptions);
}

int main(int argc, char **argv)
{
    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourAttach(&(PVOID&)Real_DrawText, Mine_DrawText);
    DetourTransactionCommit();
    printf("Calling Sleep\n");
    Sleep(1000);
    printf("Second callout");
    Sleep(5000);

    DetourTransactionBegin();
    DetourUpdateThread(GetCurrentThread());
    DetourDetach(&(PVOID&)Real_DrawText, Mine_DrawText);
    DetourTransactionCommit();
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:31:20+00:00Added an answer on May 12, 2026 at 11:31 am

    Based on your code-example, it seems you’re only detouring your own process. Therefore detouring DrawText doesn’t output anything. Perhaps, you need to inject your code to desired target’s process memory and detour the API call from there. For example, you can create system wide CBT hook which works kind of a.. launch point to your detouring needs. Something like this, to point you out a direction:

    LRESULT CALLBACK CBTProcedure(int nCode, WPARAM wParam, LPARAM lParam)
    {
            if (nCode < 0)
                    return CallNextHookEx(g_hHook, nCode, wParam, lParam);
            else if (!g_pClient)
                    return 0;
    
            HWND hWnd = (HWND)wParam;
    
            if (!hWnd)
                    return 0;
    
            switch (nCode) {
                    case HCBT_ACTIVATE:
                            /** Here, you can check up against the handle to see,
                              * if the target window is the one you're looking for...
                              *
                              */
                            if (!g_pClient->IsRegisteredWindow(hWnd))
                                    if (g_pClient->RegisterWindow(hWnd)) {
                                    }
    
                    break;
    
                    case HCBT_DESTROYWND:
                            if (g_pClient->IsRegisteredWindow(hWnd))
                                    g_pClient->UnregisterWindow(hWnd);
    
                    break;
            }
    
            return 0;
    }
    
    bool __0XYOUROWN_API InstallHook()
    {
            // Call this one from your main process; set's up the system-wide hook.
    
            g_hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProcedure, g_hInstance, 0);
    
            /** #pragma data_seg("Shared")
              *         HHOOK g_hHook = NULL;
              * #pragma data_seg()
              */
    
            return g_hHook != NULL;
    }
    
    /** The actual DLL...
      *
      *
      */
    BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
    {
            switch (ul_reason_for_call) {
                    case DLL_PROCESS_ATTACH:
                            g_hInstance = (HINSTANCE)hModule;
    
                            if (::GetModuleHandle(_T("THEDESIREDMODULE.EXE")) != NULL) {
                                    g_pClient = new Client();
    
                                    if (g_pClient) {
                                            InitializeCriticalSection(&g_CriticalSection); // You can setup a critic. sec. for later synchronization...
                                            DetourTransactionBegin();
                                            DetourUpdateThread(GetCurrentThread());
                                            DetourAttach(&(PVOID&)Real_DrawTextW, Mine_DrawTextW);
                                            DetourTransactionCommit();
                                    }
                            }
    
                    break;
    
                    case DLL_THREAD_ATTACH: break;
    
                    case DLL_THREAD_DETACH: break;
    
                    case DLL_PROCESS_DETACH:
                            if (::GetModuleHandle(_T("THEDESIREDMODULE.EXE")) != NULL) {
                                    if (g_pClient) {
                                            DetourTransactionBegin(); 
                                            DetourUpdateThread(GetCurrentThread());
                                            DetourDetach(&(PVOID&)Real_DrawTextW, Mine_DrawTextW);
                                            DetourTransactionCommit();
    
                                            delete g_pClient;
    
                                            g_pClient = NULL;
                                    }
                            }
    
                    break;
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.