CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2013
    Posts
    5

    CFileDialog::DoModal() never returns in DLL

    Hello everyone.

    I have problem in using CFileDialog:oModal() function in DLL.
    I have no trouble in doing such function call in EXE application. Also, I have no trouble to show CColorDialog and my own dialog by using "DoModal()" functions.
    To show your the issue more clearly, I attach a solution which includes 3 projects as shown below
    Name:  sln.png
Views: 1761
Size:  14.1 KB

    1. The "DLL_Caller" project is to call the DLL "DLLTest.dll".
    2. The "DLLTest" project is to create the DLL.
    3. The "DLLTest_EXE" project has the same code as the "DLLTest" project, but a EXE version.

    My development enviroment is Visual Studio2008 SP1.

    Any help will be appreciated!

    -Fan

    DLLTest.zip

  2. #2
    Join Date
    May 2013
    Posts
    5

    Re: CFileDialog::DoModal() never returns in DLL

    By the way, I don't think the issue is related to "AFX_MANAGE_STATE" macro. Because I can call CColorDialog:oModal() successfully in DLL mode.
    Thanks!

    -Fan

  3. #3
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: CFileDialog::DoModal() never returns in DLL

    Quote Originally Posted by sigmawave View Post
    Hello everyone.

    I have problem in using CFileDialog:oModal() function in DLL.
    What exactly is the problem you are experiencing? You don't say what is the problem.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    May 2013
    Posts
    5

    Re: CFileDialog::DoModal() never returns in DLL

    Quote Originally Posted by 2kaud View Post
    What exactly is the problem you are experiencing? You don't say what is the problem.
    Thank you for your quick reply.

    My problem is the application hangs in the CFileDialog:oModal() call in the DLL mode. The file open/save dialog doesn't show at all. The function runs fine in the EXE application.

    The problem happens in CFileDialog only. The CColorDialog:oModal() function works. I'm talking about in MFC DLL (no matter it is a Extension DLL or not).

    In the "MFC Application" mode, everything is working properly.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: CFileDialog::DoModal() never returns in DLL

    However my simple sample works fine with dll.
    Attached Files Attached Files
    Best regards,
    Igor

  6. #6
    Join Date
    May 2013
    Posts
    5

    Re: CFileDialog::DoModal() never returns in DLL

    Quote Originally Posted by Igor Vartanov View Post
    However my simple sample works fine with dll.
    Thank you, Igor.

    I just copied your code to replace my code. The dialog still doesn't show up.

    Name:  filedlg.png
Views: 1107
Size:  21.1 KB
    Would you mind looking at my code to find what is wrong with my DLL?

    Regards,

    -Fan

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: CFileDialog::DoModal() never returns in DLL

    Code:
    BOOL CDLLTestApp::InitInstance()
    {
    	CWinApp::InitInstance();
    
    	CTestDlg dlg;
    	m_pMainWnd = &dlg;
    
    	INT_PTR nResponse = dlg.DoModal();
    
    	return TRUE;
    }
    Code:
    >	DLLTest.dll!CDLLTestApp::InitInstance()  Line 66	C++
     	DLLTest.dll!InternalDllMain(HINSTANCE__ * hInstance, unsigned long dwReason, void * __formal)  Line 100 + 0x13 bytes	C++
     	DLLTest.dll!DllMain(HINSTANCE__ * hInstance, unsigned long dwReason, void * lpReserved)  Line 272	C++
     	DLLTest.dll!__DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved)  Line 512 + 0x11 bytes	C
     	DLLTest.dll!_DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved)  Line 476 + 0x11 bytes	C
    You must not block DllMain, never do that. Your another code with running the dialog from EntryFunction works with file dialog just perfect.
    Last edited by Igor Vartanov; May 22nd, 2013 at 01:53 AM.
    Best regards,
    Igor

  8. #8
    Join Date
    May 2013
    Posts
    5

    Re: CFileDialog::DoModal() never returns in DLL

    Quote Originally Posted by Igor Vartanov View Post
    Code:
    BOOL CDLLTestApp::InitInstance()
    {
    	CWinApp::InitInstance();
    
    	CTestDlg dlg;
    	m_pMainWnd = &dlg;
    
    	INT_PTR nResponse = dlg.DoModal();
    
    	return TRUE;
    }
    Code:
    >	DLLTest.dll!CDLLTestApp::InitInstance()  Line 66	C++
     	DLLTest.dll!InternalDllMain(HINSTANCE__ * hInstance, unsigned long dwReason, void * __formal)  Line 100 + 0x13 bytes	C++
     	DLLTest.dll!DllMain(HINSTANCE__ * hInstance, unsigned long dwReason, void * lpReserved)  Line 272	C++
     	DLLTest.dll!__DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved)  Line 512 + 0x11 bytes	C
     	DLLTest.dll!_DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved)  Line 476 + 0x11 bytes	C
    You must not block DllMain, never do that. Your another code with running the dialog from EntryFunction works with file dialog just perfect.

    Thank you for your work!
    Now I see what is the problem. I made change. It is working.
    Best regards,

    -Fan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured