Re: Use of CFileDialog
From: TVR Fan (nosuch_at_address.com)
Date: 04/21/04
- Previous message: Christian ASTOR: "Re: Task switching from an Application"
- In reply to: Johan Rosengren: "Re: Use of CFileDialog"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 21 Apr 2004 09:31:23 +0100
I made the CFileDialog object a member rather than a local variable and the
access violation went away. Any ideas why? I know that when asigning image
lists to windows, the image list object needs to have object rather than
function scope (although, thinking about this, it could be because the image
list handle needs to persist but is invalidated when the image list object
is destroyed. I believe I can detach the handle from the object so I'm
guessing that I should be doing this with my image lists?) but the file
dialog is not used outside of the function it is declared in so the same
rules shouldn't apply.
I think the call stack went straight into MFC code but I could be wrong and
of course the problem has gone away now.
--- Al.
"Johan Rosengren" <johan.rosengren@telia.com> wrote in message
news:Ox2MndsJEHA.1000@TK2MSFTNGP11.phx.gbl...
> Al,
>
> Can you see the call stack after the crash? Also, the stuff you set,
filter,
> title and flags can be set in the constructor of the CFileDialog,
> simplifying your code a bit (which always helps when tracking down a bug
> :-)))
>
> Johan Rosengren
> Abstrakt Mekanik AB
>
> "TVR Fan" <nosuch@address.com> a écrit dans le message de
> news:Oc9UNWhJEHA.3292@TK2MSFTNGP11.phx.gbl...
> > 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 ) ;
> > > }
> > > }
> > >
> > >
> >
> >
>
>
- Previous message: Christian ASTOR: "Re: Task switching from an Application"
- In reply to: Johan Rosengren: "Re: Use of CFileDialog"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|