1
votes

We have an application built against MFC9 (VC2008). The application is an SDI application, and shows a file open dialog during InitInstance(). Showing that dialog causes comdlg32.dll to be loaded. Some minutes later, the comdlg32.dll is unloaded automatically. After this, the next function depending on the DLL will crash.

How can this be avoided? What governs the automatic unloading/loading of the DLL?

Further info:

  • We don't see this problem on WinXP with the same application.
  • On Win7, this behavior only occurred since the beginning of this year - maybe some MFC update is related to this?
  • A small test application does not exhibit the problematic behavior - the comdlg32.dll is re-loaded when needed.
  • We’ve found a statement by Microsoft that it isn’t recommended to use modal dialogs in InitInstance() of MDI applications (http://support.microsoft.com/kb/173261) - we have an SDI application, though.
  • We don't directly use comdlg32.dll in any way, only indirectly through the MFC.
2

2 Answers

2
votes

You have to call InitCommonControlsEx in your application on startup. This will initialize the comdlg32.dll and also increase the reference count of the dll, so it won't get unloaded after closing a file-open/save dialog.

0
votes

You don't say whether you customize your dialog or it is just a straight up file dialog. I think starting with Vista, the common file dialog was changed some. I know if you compare older MFC code with newer, you will see that the MFC code has been changed to take advantage of those changes. For instance, the IFileDialogEvents and IFileDialogControlEvents were implemented in MFC to support the way Vista and later versions of the OS customize file dialogs.

I don't know if I have an answer, but just for grins I would probably make sure I call AfxOleInitialize() sometime in InitInstance() before I tried to call the file dialog.

The other thing I would try for sure (since it works under XP) would be in the constructor of your CFileDialog would be to make sure to set bVistaStyle to FALSE. This ensures m_bVistaStyle is set to FALSE which it is set at when running under XP.