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

  • SEARCH
  • Home
  • 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 8132169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:16:53+00:00 2026-06-06T09:16:53+00:00

I want to open a MFC modeless dialog from a MFC dll injected into

  • 0

I want to open a MFC modeless dialog from a MFC dll injected into another process, the dll’s job is to hook the winsock send & recv, and the dialog will be the interface to communicate with the dll. The dll should be able to run the hook while the dialog is running.

BOOL CDriverApp::InitInstance()
{
    CWinApp::InitInstance();

    if (!AfxSocketInit())
    {
        AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
        return FALSE;
    }

    AfxMessageBox("I'm In!");

    DetourTransactionBegin();
    DetourUpdateThread( GetCurrentThread() );
    DetourAttach( &(PVOID &)RealSend, MySend );
    DetourAttach( &(PVOID &)RealRecv, MyRecv );
    if ((DetourTransactionCommit()) == NO_ERROR)
    {
        AfxMessageBox("Winsock hooked");
    }
    dlg = new ControlDlg();
    m_pMainWnd = dlg;
    if(dlg->Create(IDD_CONTROL_DLG))
    {
        dlg->ShowWindow(SW_SHOW);
    }

    //ExitThread(0);
    return TRUE; <--- 
}

dlg is the dialog which is a member of CDriverApp

From what i have observed, the dialog is destroyed because the thread has exited and the memory that hold the dialog is removed.

The thread '_DllMainCRTStartup' (0x418) has exited with code 1657602048 (0x62cd0000).

I have read MFC modeless dialog close immediately thread, but my InitInstance() already returned true from the first place, so it’s a different problem (i think)

So, my question is how to prevent the dialog from destroyed? Or perhaps prevent the thread from exit? or is it doable with a modal dialog?

  • 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-06-06T09:16:54+00:00Added an answer on June 6, 2026 at 9:16 am

    This may be your problem:

    Regular DLLs must have a CWinApp-derived class and a single object of
    that application class, as does an MFC application. However, the
    CWinApp object of the DLL does not have a main message pump, as does
    the CWinApp object of an application.

    Note that the CWinApp::Run
    mechanism does not apply to a DLL, because the application owns the
    main message pump. If the DLL opens modeless dialogs or has a main
    frame window of its own, the application’s main message pump must call
    a routine exported by the DLL that in turn calls the
    CWinApp::PreTranslateMessage member function of the DLL’s application
    object.

    http://msdn.microsoft.com/en-US/library/f22wcbea(v=vs.80)

    EDIT:

    THis shows how to do what you are doing with a cWnd instead of a CDialog. Personally I think thats a better way to go.

    http://codinganswer.com/c/cwnd-in-a-new-thread-in-a-dll.html

    Here is an example of attaching a message hook to a modeless.

    http://support.microsoft.com/kb/q187988/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a html file and I want to open it from my mfc
I want open a path to vim from Screen's copy-mode by Ctrl-A f similarly
Want to open firefox from terminal at linux with firebug enabled // Terminal $
IDEA Want to open a dialog with youtube video, play when I open when
I want to open excel document from my program in java. Actually I want
I want to open a save file dialog, have the user enter a filename,
I want to open a file dialog box in user control. I used using
I want to open a folder window, in the appropriate file manager, from within
I want to open a page up in node and process the contents in
I use C# & Excel Intropt.dll for my project I want Open my xlsx

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.