Re: Use of CFileDialog

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: TVR Fan (nosuch_at_address.com)
Date: 04/19/04


Date: Mon, 19 Apr 2004 14:51:23 +0100

Ok, so if I had used "Flags |=" instead of "Flags =", I wouldn't have been
writing that message! I'm still getting an access violation though when the
CFileDialog goes out of scope. Presumably its destructor is trying to access
a null pointer somewhere?

--- Al.

"TVR Fan" <nosuch@address.com> wrote in message
news:enS3k9gJEHA.3040@TK2MSFTNGP09.phx.gbl...
> I'm trying to use CFileDialog to allow the user to select an existing
file,
> but it asserts in DoModal because (m_ofn.Flags & OFN_ENABLEHOOK) is ok. If
I
> set that flag, it'll assert because (m_ofn.lpfnHook != NULL) is false. I
> didn't think I needed to provide a hook function. If I do, how should I
> provide it and what should it do?
>
> If I bypass those two asserts, the dialog comes up but displays no files.
> Have I created the filter string incorrectly?
>
> Finally, it dies with an access violation in the destructor. I'm guessing
> this will stop if I fix the other two issues.
>
> I'm developing with VC++6 on Windows XP. Here's my code:
>
> void CWPSched10Task::OnBtnCmdfind()
> {
> CFileDialog dlgFileOpen ( TRUE ) ;
> const uiFilterStringLen = 256 ;
> TCHAR caFilter[uiFilterStringLen] ;
> CString strFilterString ;
> CString strDialogTitle ;
>
> int i = 0 ;
> for ( i=0 ; i<256 ; caFilter[i++]=0 ) {}
>
> strDialogTitle.LoadString ( IDS_SELECTFILETORUN ) ;
> strFilterString.LoadString ( IDS_CMD_FILES ) ; // Just the string
> "Command files"
> _tcscpy ( caFilter, (LPCTSTR)strFilterString ) ;
> _tcscpy ( &(caFilter[_tcslen(caFilter)+1]), _T("cmd") ) ; // Results
in
> "Command files\0cmd\0\0\0\0\0..."
>
> dlgFileOpen.m_ofn.lStructSize = sizeof( OPENFILENAME );
> dlgFileOpen.m_ofn.hwndOwner = this->m_hWnd ;
> dlgFileOpen.m_ofn.Flags = OFN_DONTADDTORECENT |
> OFN_FILEMUSTEXIST |
> OFN_HIDEREADONLY |
> OFN_PATHMUSTEXIST |
> OFN_NOCHANGEDIR ;
> dlgFileOpen.m_ofn.lpstrFilter = caFilter ;
> dlgFileOpen.m_ofn.nFilterIndex = 0 ;
> dlgFileOpen.m_ofn.lpstrInitialDir = _T("") ;
> dlgFileOpen.m_ofn.lpstrTitle = (LPCTSTR)strDialogTitle ;
>
> if ( dlgFileOpen.DoModal() == IDOK )
> {
> // Get the path & store it.
> MessageBox ( _T("Need to store the command"), _T("Development Note"),
> MB_OK ) ;
> }
> }
>
>



Relevant Pages

  • Re: Use of CFileDialog
    ... CFileDialog goes out of scope. ... it dies with an access violation in the destructor. ... > CString strFilterString; ...
    (microsoft.public.win32.programmer.ui)
  • Re: Use of CFileDialog
    ... title and flags can be set in the constructor of the CFileDialog, ... >> Have I created the filter string incorrectly? ... it dies with an access violation in the destructor. ...
    (microsoft.public.vc.mfc)
  • Re: Use of CFileDialog
    ... title and flags can be set in the constructor of the CFileDialog, ... >> Have I created the filter string incorrectly? ... it dies with an access violation in the destructor. ...
    (microsoft.public.win32.programmer.ui)
  • Re: Use of CFileDialog
    ... I made the CFileDialog object a member rather than a local variable and the ... access violation went away. ... guessing that I should be doing this with my image lists?) ... I think the call stack went straight into MFC code but I could be wrong and ...
    (microsoft.public.vc.mfc)
  • Re: Use of CFileDialog
    ... I made the CFileDialog object a member rather than a local variable and the ... access violation went away. ... guessing that I should be doing this with my image lists?) ... I think the call stack went straight into MFC code but I could be wrong and ...
    (microsoft.public.win32.programmer.ui)