Solved

CFileDialog::DoModal Failure when using OFN_ENABLETEMPLATE

Posted on 2008-10-09
3
1,378 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

713 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