CFileDialog problem when called from DLL

Proposed Answer CFileDialog problem when called from DLL

  • Monday, April 30, 2012 7:11 AM
     
      Has Code

    Hi,

    Inside the MFC dll I have a dialog with a button with the following function: pressing the button generates a CFileDialog object. Running DoModal for this object is suppose to bring up the Open/Save Dialog Box. Unfortunately, nothing happens when it gets to DoModal part (the app hangs). I do not get any access violations. And the debug does not clear up what makes the app hangs, but it does hang somewhere inside the MFC's filedlg.cpp. It works fine when i call the file dialog from inside the client app (.exe file)
    Can anybody help?

    Thanks.

    // In the Button
    
    CFileDialog FileDlg(TRUE, ".txt", NULL, OFN_NOCHANGEDIR, strFilter);
    if( FileDlg.DoModal() == IDOK )
    {	
       ...
    }


    • Edited by Lofty88 Monday, April 30, 2012 7:16 AM
    •  

All Replies

  • Tuesday, May 01, 2012 4:49 AM
     
     

    the code snippets you posted is from the MFC DLL application, right? The DLL cannot run alone. it should be called by other application.

    it is nomal that the dialog do not appear if you run the dll on you side,


    Please mark this reply as answer if it helps you! Thanks for your cooperation! Good Luck to you.

  • Tuesday, May 01, 2012 3:09 PM
     
     Proposed Answer

    Hi,

    Inside the MFC dll I have a dialog with a button with the following function: pressing the button generates a CFileDialog object. Running DoModal for this object is suppose to bring up the Open/Save Dialog Box. Unfortunately, nothing happens when it gets to DoModal part (the app hangs). I do not get any access violations. And the debug does not clear up what makes the app hangs, but it does hang somewhere inside the MFC's filedlg.cpp. It works fine when i call the file dialog from inside the client app (.exe file)


    Seems code is fine if it is working fine with respect to an app. When you are calling it from exe it is working fine. Exactly what is the second scenario are you running it from your dll side instead of app by providing exe path to your debug.Eventually this is not a problem with your file dialog . You are not able to launch your dialog itself . Just specify the path of the executable under you project option and try it again .hopefully it will work fine

    Thanks


    Rupesh Shukla

  • Wednesday, May 02, 2012 1:23 AM
     
      Has Code

    Hi,

    Yes, I am calling it from another dialog-based project. I've loaded the DLL onto my 2nd dialog-based project.

    In this 2nd dialog-based project, i have a button. When i click this button, it brought out the dialog (DLG A) from the DLL.

    This code brought out the dialog from DLL.

    m_hViewDll = AfxLoadLibrary(".\\ProjectA.dll");

    But when i click on a button in the dialog (DLG A) which is suppose to bring out the CFileDialog. It will hang.

    When i clicked on other buttons (in DLG A) which will bring out dialogs created by myself. it works fine. Only CFileDialog will hang the program.

    I am not suppose to run the 1st project in .exe format.

    • Edited by Lofty88 Wednesday, May 02, 2012 1:51 AM
    •  
  • Tuesday, May 08, 2012 1:57 AM
     
     

    If this DLL is dynamically linked against the MFC DLLs,any functions exported from this DLL which call into MFC must have the AFX_MANAGE_STATE macro added at the very beginning of the function.


    Rupesh Shukla