CFileDialog::DoModal() never returns in DLL
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

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

  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: 159
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
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,754

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  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,051

    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: 89
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,051

    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 02: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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center