GetFolderPath() error!!

KaimTazz's Avatar, Join Date: Aug 2007
Go4Expert Member
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);
	}
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
What error does it gives?
0
KaimTazz's Avatar, Join Date: Aug 2007
Go4Expert Member
In dlgfile.cpp, within definition of GetFolderPath()..

It breaks the execution of program and displays AbortRetryIgnore message..No Error number!!
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
0
KaimTazz's Avatar, Join Date: Aug 2007
Go4Expert Member
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...
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Dialog type should be Folder Dialog and not of the type FileDialog but I am not sure of that.
0
rups's Avatar, Join Date: Aug 2007
Newbie Member
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.