Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am trying to debug an application and I keep running into this error around the break point:
 
File f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\filelist.cpp
Line:255
 
What does this error mean? The following is my call stack around the point where a debug assertion error occurs:
 
    mfc100d.dll!CRecentFileList::Add(const char * lpszPathName, const char * lpszAppID)  Line 225 + 0x25 bytes  C++
    mfc100d.dll!CWinApp::AddToRecentFileList(const char * lpszPathName)  Line 84    C++
    mfc100d.dll!CDocument::SetPathName(const char * lpszPathName, int bAddToMRU)  Line 296  C++
    mfc100d.dll!COleDocument::SetPathName(const char * lpszPathName, int bAddToMRU)  Line 183   C++
    WinSTM.exe!CWinSTMDoc::CopyDoc(CWinSTMDoc * pDocNew, int chan)  Line 486 + 0x3b bytes   C++
    WinSTM.exe!CWinSTMView::CreateNewDoc(CWinSTMDoc * pDoc)  Line 2717  C++
    WinSTM.exe!CWinSTMView::OnImageAutoPlane()  Line 4789 + 0x11 bytes  C++
    mfc100d.dll!_AfxDispatchCmdMsg(CCmdTarget * pTarget, unsigned int nID, int nCode, void (void)* pfn, void * pExtra, unsigned int nSig, AFX_CMDHANDLERINFO * pHandlerInfo)  Line 82   C++
    mfc100d.dll!CCmdTarget::OnCmdMsg(unsigned int nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo)  Line 381 + 0x27 bytes  C++
    mfc100d.dll!CView::OnCmdMsg(unsigned int nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo)  Line 166 + 0x18 bytes   C++
    mfc100d.dll!CFrameWnd::OnCmdMsg(unsigned int nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo)  Line 969 + 0x23 bytes   C++
    mfc100d.dll!CWnd::OnCommand(unsigned int wParam, long lParam)  Line 2676    C++
    mfc100d.dll!CFrameWnd::OnCommand(unsigned int wParam, long lParam)  Line 371    C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult)  Line 2081 + 0x1e bytes  C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam)  Line 2067 + 0x20 bytes    C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  Line 248 + 0x1c bytes  C++
    mfc100d.dll!CMDIFrameWnd::OnCommand(unsigned int wParam, long lParam)  Line 48 + 0x23 bytes C++
    mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult)  Line 2081 + 0x1e bytes  C++
    mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam)  Line 2067 + 0x20 bytes    C++
    mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  Line 248 + 0x1c bytes  C++
    mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  Line 411    C++
    mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  Line 420 + 0x15 bytes   C++
    user32.dll!_InternalCallWinProc@20()  + 0x23 bytes
    user32.dll!_UserCallWinProcCheckWow@32()  + 0xb3 bytes
    user32.dll!_DispatchMessageWorker@8()  + 0xe6 bytes
    user32.dll!_DispatchMessageA@4()  + 0xf bytes
    mfc100d.dll!AfxInternalPumpMessage()  Line 183  C++
    mfc100d.dll!CWinThread::PumpMessage()  Line 900 C++
    mfc100d.dll!CWinThread::Run()  Line 629 + 0xd bytes C++
    mfc100d.dll!CWinApp::Run()  Line 822    C++
    mfc100d.dll!AfxWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow)  Line 47 + 0xd bytes   C++
    WinSTM.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow)  Line 26   C++
    WinSTM.exe!__tmainCRTStartup()  Line 547 + 0x2c bytes   C
    WinSTM.exe!WinMainCRTStartup()  Line 371    C
    kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes
    ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes
    ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes
 
Here are my autos/variable values:
 
-&psi    0x0024eb78 {0x00000000}  ATL::CComPtr<IShellItem> *
-ATL::CComPtrBase<IShellItem>    {p=0x00000000 } ATL::CComPtrBase<IShellItem>
-       p   0x00000000  IShellItem *
-       IUnknown    {...}   IUnknown
        __vfptr CXX0030: Error: expression cannot be evaluated
 
Here is the code where the assertion occurs:
void CDocument::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU)
{
	// store the path fully qualified
	TCHAR szFullPath[_MAX_PATH];
	ENSURE(lpszPathName);
	if ( lstrlen(lpszPathName) >= _MAX_PATH )
	{
		ASSERT(FALSE);
		// MFC requires paths with length < _MAX_PATH
		// No other way to handle the error from a void function
		AfxThrowFileException(CFileException::badPath);
	}
	if( AfxFullPath(szFullPath, lpszPathName) == FALSE )
	{
		ASSERT(FALSE);
		// MFC requires paths with length < _MAX_PATH
		// No other way to handle the error from a void function
		AfxThrowFileException(CFileException::badPath);
	}
	m_strPathName = szFullPath;
	ASSERT(!m_strPathName.IsEmpty());       // must be set to something
	m_bEmbedded = FALSE;
	ASSERT_VALID(this);
	// set the document title based on path name
	TCHAR szTitle[_MAX_FNAME];
	if (AfxGetFileTitle(szFullPath, szTitle, _MAX_FNAME) == 0)
		SetTitle(szTitle);
	// add it to the file MRU list
	if (bAddToMRU)
		AfxGetApp()->AddToRecentFileList(m_strPathName);
	ASSERT_VALID(this);
}
 
Is this just telling me that a pointer is bad?
 
Thanks!
Posted 26-Jul-11 13:08pm
Edited 1-Aug-11 10:51am
v2
Comments
Albert Holguin at 26-Jul-11 20:40pm
   
You didn't post what the error or assertion is. Post the error or assertion message, otherwise, there's no way to know what's wrong.
AndrewG1231 at 27-Jul-11 14:19pm
   
All the message says is, "Debug Assertion Failed! Program: C:...path to the .exe, File:f:\dd\vctools.....line:225" following the message, I press retry to debug and it causes a break at the mfc100d.dll call.
prdshukla at 29-Jul-11 11:21am
   
Can you post the code where you are hitting this issue..that could help to find it...
AndrewG1231 at 1-Aug-11 15:51pm
   
Done, took my a bit, but the code where the assertion occurs is posted.
Mic72 at 26-Jan-12 13:43pm
   
I have the same problem in the same source code: calling the CDocument::SetPathName the system fires an exception

if ( lstrlen(lpszPathName) >= _MAX_PATH )
{
ASSERT(FALSE);
// MFC requires paths with length < _MAX_PATH
// No other way to handle the error from a void function
AfxThrowFileException(CFileException::badPath);
}

but the size of lpszPathName is less than _MAX_PATH.
Have you solved your problem?
AndrewG1231 at 26-Jan-12 17:36pm
   
yes...my solution is listed below the question
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

So,after a lot of guidance from the c++/mfc forum, the answers to the questions here, and Ivor Horton's book on Visual Studio 2010 I was able to solve the error.
 
The error first was being thrown by the return value of E_INVALIDARG for the variable hr in
ENSURE(SUCCEEDED(hr))
After stepping back we found a stale memory value for
ShellCreateItemFromParsingName()
Making some break points and continuing to step back the problem code was narrowed the function where we were copying the document:
CString OldPath = GetPathName();
pDocNew->SetPathName(OldPath + " *");
	
CString OldTitle = GetTitle();
pDocNew->SetTitle(OldTitle + " *");
It seems that Visual Studio 2010 did not like the " *" being added to the file name or path. Once it was removed from both places problem was resolved. Now the program is fully functional. Thanks for all the help with the debugging techniques, they are valuable skills!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I had a customer with the same problem. For an unknown reason, a function higher in the stack decided that the file passed to CRecentFileList::Add() did not exist. This is strange because the file was either just opened or just saved to.
 
My solution was to overload CWinAppEx::AddToRecentFileList() in order to catch and ignore any exceptions. You can be extra safe and check the exception type if you want.
 
I like this solution because you shouldn't have to change your code if Microsoft changes the base class implementation in the future. And because it works for both saving and loading.
 
void CMyApp::AddToRecentFileList(LPCTSTR lpszPathName)
{
    try
    {
        // Call the base class
        CWinAppEx::AddToRecentFileList(lpszPathName);
    }
    catch (CException * e)
    {
        CString strCause;
        e->GetErrorMessage(strCause.GetBuffer(800), 800);
        strCause.ReleaseBuffer();
        TRACE("Exception in %s: %s.  -- Ignoring\n", __FUNCTION__, strCause);
        e->Delete();
    }
}
 
Enjoy.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I had this problem too, because the file path included \..\ in itself.
 
All I had to do was a PathCanonicalize before to remove these kinds of things.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I have the same problem in the same source code: calling the CDocument::SetPathName the system fires an exception
 
if ( lstrlen(lpszPathName) >= _MAX_PATH )
{
ASSERT(FALSE);
// MFC requires paths with length < _MAX_PATH
// No other way to handle the error from a void function
AfxThrowFileException(CFileException::badPath);
}
 
but the size of lpszPathName is less than _MAX_PATH.
Have you solved your problem?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 319
1 Kornfeld Eliyahu Peter 265
2 Maciej Los 249
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 175
0 OriginalGriff 5,107
1 DamithSL 4,157
2 Maciej Los 3,595
3 Kornfeld Eliyahu Peter 3,450
4 Sergey Alexandrovich Kryukov 2,741


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100