Solved

CFileDialog::DoModal Failure when using OFN_ENABLETEMPLATE

Posted on 2008-10-09
3
1,374 Views
Last Modified: 2013-11-20
I recently converted my MFC code from VS2003 to VS2005. I have a custom file open save dialog (CCustomFileDialog) and I enable the template resouce as shown in code below. The custom dialog show up OK but if I do CtrlC to copy a file or delete a file from within the dialog and then cancel out from the dialog, it closes OK but it errors out (CDERR_FINDRESFAILURE in CFileDialog::DoModal) when I try to open the custom dialog again.

If I open the dialog and selct file, open it or cancel out without doing (copy, delete etc), I am able to open the custom dialog again and again without any problems. I have attached the relevant code below. I would really appreciate if somebody could please point out what the problem could be.

Note:
This happens only on some of customer computers not on development computer.
It worked fine on same customer's computer when the code was in VS2003.
CCustomFileDialog::CCustomFileDialog( ...):CFileDialog(true) 
{ 
...
m_ofn.Flags |= (OFN_ENABLETEMPLATE); 
m_ofn.lpTemplateName = MAKEINTRESOURCE (IDD_FILE_OPENSAVE); // IDD_FILE_OPENSAVE is custom file open save dialog
m_ofn.hInstance = AfxGetResourceHandle(); 
...
}
 
CCustomFileDialog *pDlg = NULL; 
pDlg = new CFileDialogSC(...); 
if (pDlg->DoModal()== IDOK)
{
...
}
char buffer[256]; 
sprintf(buffer, "DoModal Failled Error %d", CommDlgExtendedError()); 
MessageBox(NULL, buffer, "", MB_OK); 
 
delete pDlg;

Open in new window

0
Comment
Question by:scdev
  • 2
3 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22685512
The MSDN says

----------------------------------------------
CDERR_FINDRESFAILURE The common dialog box function failed to find a specified resource.
----------------------------------------------

what not really isn't surprising ;-)

I assume the error comes because the 'new' OpenFileDialog comming with VS200´8 needs some more resources which could not be found in the resources included by your (VC6) resource file. To verify that, you should check your resource includes (e. g. by opening your .rc file in the text editor). If any of these includes points to a system resource file where both VC6 and VC8 have a own resource file you might have found the issue. Then, you would need to edit the project-specific resource include path in the project properties - if any - or check for the general include paths to make the new VC8 resource folder prior to that of the VC6 path. Or you were editing the include statement so taht it was pointing to the right reedource include file.

   
0
 

Author Comment

by:scdev
ID: 22956326
knock, knock?
0
 

Accepted Solution

by:
scdev earned 0 total points
ID: 23009894
BAD:
m_ofn.hInstance = AfxGetResourceHandle ();

GOOD:
      m_ofn.hInstance = AfxFindResourceHandle(MAKEINTRESOURCE (IDD_FILE_OPEN), RT_DIALOG);
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question