GetFolderPath() error!!

Discussion in 'MFC' started by KaimTazz, Aug 23, 2007.

  1. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Hi all!!
    I need to get Folder path but getFolderPath() gives error..Can anybody help me to know WHY??

    Code:
    CFileDialog dlg(TRUE,NULL,NULL,OFN_EXPLORER|OFN_OVERWRITEPROMPT,"JPEG Files (*.*)|*.*||");
    	
    	INT_PTR ptr = dlg.DoModal();
    	if(ptr==IDOK)
    	{
    		UpdateData();
    		CString str = dlg.GetFolderPath();
    		m_path1.Format("%s",str);
    		UpdateData(FALSE);
    	}
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    What error does it gives?
     
  3. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    In dlgfile.cpp, within definition of GetFolderPath()..

    It breaks the execution of program and displays AbortRetryIgnore message..No Error number!!
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I am not sure why it should happen but my assumption is the folder is returning but str does not have the necessary buffer to hold the data.
     
  5. KaimTazz

    KaimTazz New Member

    Joined:
    Aug 8, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    same str giving no such problem with GetPathName( )!! I have passed OFN_EXPLORER as style but even then GetFolderPath() is not returning desired result. Did i make any mistake in code above??
    or i have to do it some other way...
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Dialog type should be Folder Dialog and not of the type FileDialog but I am not sure of that.
     
  7. rups

    rups New Member

    Joined:
    Aug 30, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    The MSDN documentation says that

    "You can call the GetFolderPath() method only while the dialog box is being displayed. After the dialog box has been closed, this function will no longer work, and the method will fail with an assertion."

    http://msdn2.microsoft.com/en-us/library/xz5y6xhy(VS.80).aspx


    Since you are closing the File Open dialog, that is the reason you get this assertion. The code for GetFolderPath() checks this line ASSERT:):IsWindow(m_hWnd)). As m_hWnd is NULL in this case, the error occurs.


    Hope this helps.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice