GetFolderPath() error!!

Go4Expert Member
23Aug2007,17:38   #1
KaimTazz's Avatar
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);
	}
Go4Expert Founder
23Aug2007,17:58   #2
shabbir's Avatar
What error does it gives?
Go4Expert Member
23Aug2007,18:08   #3
KaimTazz's Avatar
In dlgfile.cpp, within definition of GetFolderPath()..

It breaks the execution of program and displays AbortRetryIgnore message..No Error number!!
Go4Expert Founder
23Aug2007,19:01   #4
shabbir's Avatar
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.
Go4Expert Member
24Aug2007,11:10   #5
KaimTazz's Avatar
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...
Go4Expert Founder
24Aug2007,11:32   #6
shabbir's Avatar
Dialog type should be Folder Dialog and not of the type FileDialog but I am not sure of that.
Newbie Member
30Aug2007,23:58   #7
rups's Avatar
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.