CFileDialog OFN_NOVALIDATE + How to append file extension

Hi,

I am facing one problem while appending file extension.
I have a derived class from CFileDialog.
I am using OFN_NOVALIDATE flag while creating CFileDialog object.
According to MSDN - If we use NOVALIDATE flag then
"No default extension is added to the text, nor is text copied to the buffer specified by lpstrFileTitle."

My code for Appending the file extension.

CString strfilename = GetPathName();
int pos = strfilename.ReverseFind('.');
if (pos < 0)
{
CString strExt = m_ofn.lpstrDefExt;
strfilename += ( _T(".") + strExt);

m_ofn.lpstrFile = strfilename.GetBuffer(MAX_PATH);
strfilename.ReleaseBuffer();
}

My application crashes while running.

My question is
1) Is this the right way to append directly in m_ofn.lpstrFile.

Any other way to append?
I am not using any hook procedure.

Thanks in Advance.
My MFC is very weak, but I think that CString::GetBuffer() returns an internal managed buffer. The caller (and filler) of the OFN structure usually provides the buffer, and if so, you seem to be overriding the pointer given by the caller with this code. But then again, I am not sure if this is the case for you exactly.

Furthermore, you are assigning the value of strfilename to lpstrFile. I thought you wanted lpstrFileTitle.
Topic archived. No new replies allowed.