CFileDialog fileDlg debug assertion error
-
Hi, Am using
CFileDialog fileDlg
VC++2008 version. Button use to open
CFileDialog
below code i used. My problem is more then 5 times i call this function. It shows 'debug assertion error' File: f:\dd\vc7libs\ship\atlmfc\src\wincore.cpp line:398 finally debug goes here
// all other messages route through message map CWnd\* pWnd = CWnd::FromHandlePermanent(hWnd);
Here My Code
TCHAR szFilters[]= _T("MyType Files (*.my)|*.my|All Files (*.*)|*.*||");
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg(TRUE, _T("my"), _T("*.my"),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if(fileDlg.DoModal() == IDOK)
{
CString pathName = fileDlg.GetPathName();
// Implement opening and reading file in here.
//Change the window's title to the opened file's title.
CString fileName = fileDlg.GetFileTitle();
SetWindowText(fileName);
} -
Hi, Am using
CFileDialog fileDlg
VC++2008 version. Button use to open
CFileDialog
below code i used. My problem is more then 5 times i call this function. It shows 'debug assertion error' File: f:\dd\vc7libs\ship\atlmfc\src\wincore.cpp line:398 finally debug goes here
// all other messages route through message map CWnd\* pWnd = CWnd::FromHandlePermanent(hWnd);
Here My Code
TCHAR szFilters[]= _T("MyType Files (*.my)|*.my|All Files (*.*)|*.*||");
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg(TRUE, _T("my"), _T("*.my"),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if(fileDlg.DoModal() == IDOK)
{
CString pathName = fileDlg.GetPathName();
// Implement opening and reading file in here.
//Change the window's title to the opened file's title.
CString fileName = fileDlg.GetFileTitle();
SetWindowText(fileName);
}You did not show the line that asserts so I can only guess that it checks if
pWnd
isNULL
(I have no VS2008 here but it seems that the code snippet is from theAfxWndProc
function). From that line debug backwards to identify the invalid window handle that finally leads to the assertion. Because your code snippet using theCFileDialog
is just a copy of the MSDN example code I guess that the assertion is not related to the file dialog but to some other window or you did not showed the used code. In the latter case you might try to pass also thepParentWnd
to the file dialog. -
Hi, Am using
CFileDialog fileDlg
VC++2008 version. Button use to open
CFileDialog
below code i used. My problem is more then 5 times i call this function. It shows 'debug assertion error' File: f:\dd\vc7libs\ship\atlmfc\src\wincore.cpp line:398 finally debug goes here
// all other messages route through message map CWnd\* pWnd = CWnd::FromHandlePermanent(hWnd);
Here My Code
TCHAR szFilters[]= _T("MyType Files (*.my)|*.my|All Files (*.*)|*.*||");
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg(TRUE, _T("my"), _T("*.my"),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if(fileDlg.DoModal() == IDOK)
{
CString pathName = fileDlg.GetPathName();
// Implement opening and reading file in here.
//Change the window's title to the opened file's title.
CString fileName = fileDlg.GetFileTitle();
SetWindowText(fileName);
}Hi, Are you running this code on a Microsoft operating system older than Vista? If so... this is most likely happening because the once you hit the OK button... the window closes. The older MFC versions use the SendMessage function[^] and send a CDM_GETSPEC message[^] to the CFileDialog window and get the file name and the CDM_GETFILEPATH message[^] to get the path. You can potentially avoid this by setting the CFileDialog::m_ofn.lpstrFile[^] member to a local buffer. Best Wishes, -David Delaune