CFileDialog Multi-Select problem
Jeff Pek -- jpek@bizserve.com Monday, July 29, 1996 Environment: VC++1.52c, Win95 Hi all - I'm running into a strange problem I wonder if anyone has seen before... I have a CFileDialog-derived class that allows the selection of more than one file via the OFN_ALLOWMULTISELECT flag. Excerpt of ctor: CChooseDisplayFileDlg::CChooseDisplayFileDlg( CWnd *pParentWnd ) : CFileDialog( TRUE, NULL, NULL, OFN_HIDEREADONLY, NULL, pParentWnd ) { // Set up OPENFILENAME structure information const size_t kFileNameBufSize = 1024; // Dialog Caption CString promptMsg; promptMsg.LoadString( IDS_SELECTDISPLAYPROMPT ); m_ofn.lpstrTitle = new char[ promptMsg.GetLength()+1 ]; strcpy( (char*)m_ofn.lpstrTitle, promptMsg ); // Space for m_ofn.lpstrTitle gets deleted in dtor // Set flags m_ofn.Flags |= OFN_FILEMUSTEXIST; // Allow multi-file selection; need to provide a buffer m_ofn.Flags |= OFN_ALLOWMULTISELECT; m_ofn.lpstrFile = m_strFileName.GetBuffer( kFileNameBufSize ); m_ofn.nMaxFile = kFileNameBufSize; } Everything is fine as long as one doesn't double click a file in the file list box (id lst1). When this happens, a system dialog appears with the error message "Insufficient memory to perform operation." When the dialog box is dismissed, we go back to the OFN dialog (i.e. nothing happens). If you select a file and then press OK, everything works fine. Any ideas? Thanks - Jeff Pek jpek@bizserve.com
Jeff Pek -- jpek@bizserve.com Tuesday, July 30, 1996 Environment: VC++ 1.52, Windows 95 Hi all - I'm running into a strange problem I wonder if anyone has seen before... I have a CFileDialog-derived class that allows the selection of more than one file via the OFN_ALLOWMULTISELECT flag. Excerpt of ctor: CChooseDisplayFileDlg::CChooseDisplayFileDlg( CWnd *pParentWnd ) : CFileDialog( TRUE, NULL, NULL, OFN_HIDEREADONLY, NULL, pParentWnd ) { // Set up OPENFILENAME structure information const size_t kFileNameBufSize = 1024; // Dialog Caption CString promptMsg; promptMsg.LoadString( IDS_SELECTDISPLAYPROMPT ); m_ofn.lpstrTitle = new char[ promptMsg.GetLength()+1 ]; strcpy( (char*)m_ofn.lpstrTitle, promptMsg ); // Space for m_ofn.lpstrTitle gets deleted in dtor // Set flags m_ofn.Flags |= OFN_FILEMUSTEXIST; // Allow multi-file selection; need to provide a buffer m_ofn.Flags |= OFN_ALLOWMULTISELECT; m_ofn.lpstrFile = m_strFileName.GetBuffer( kFileNameBufSize ); m_ofn.nMaxFile = kFileNameBufSize; } Everything is fine as long as one doesn't double click a file in the file list box (id lst1). When this happens, a system dialog appears with the error message "Insufficient memory to perform operation." When the dialog box is dismissed, we go back to the OFN dialog (i.e. nothing happens). If you select a file and then press OK, everything works fine. Any ideas? Thanks - Jeff Pek jpek@bizserve.com
Mike Blaszczak -- mikeblas@nwlink.com Saturday, August 03, 1996 [Mini-digest: 2 responses] At 05:19 PM 7/29/96 -0400, you wrote: >Environment: VC++1.52c, Win95 Thanks. But you don't mention which memory model you're using. > [...] Excerpt of ctor: > [other code] > strcpy( (char*)m_ofn.lpstrTitle, promptMsg ); > [other code] This is an incredibly suspicious cast. Why do you have (char*) there? Depending on what memory model you're using, this could mean that you're trashing memory randomly as you run. .B ekiM http://www.nwlink.com/~mikeblas/ These words are my own. I do not speak on behalf of Microsoft. -----From: Todd BrandelJeff Pek wrote: > > Environment: VC++ 1.52, Windows 95 > ... > Everything is fine as long as one doesn't double click a file in the file > list box (id lst1). When this happens, a system dialog appears with the > error message "Insufficient memory to perform operation." When the dialog > box is dismissed, we go back to the OFN dialog (i.e. nothing happens). If > you select a file and then press OK, everything works fine. > > Any ideas? > Jeff, I ran into this problem a while back. I was allocating most of the stack for an object that should have been on the heap. I moved the object to the heap and everything was fine. I don't know if the multiseltion has anything to do with the problem, I wasn't using it. -- Todd Brandel - EDS / Simucar tdb@simucar.gmr.com Any opinions expressed are my own.
Jeff Pek -- jpek@bizserve.com Wednesday, August 07, 1996 > Thanks. But you don't mention which memory model you're using. > > > [...] Excerpt of ctor: > > > [other code] > > strcpy( (char*)m_ofn.lpstrTitle, promptMsg ); > > [other code] > > This is an incredibly suspicious cast. Why do you have (char*) there? > Depending on what memory model you're using, this could mean that > you're trashing memory randomly as you run. Thank you for the response, Mike. You're right -- this does appear to be a suspicious cast. I'm using Large Memory Model, so it amounts to simply avoiding the constness complaint that the compiler has if one tries to use lpstrTitle without the cast. I don't recall if my original post included the preceding line, which allocated lpstrTitle with new char[]. To be more correct, I probably could have used an intermediate char *, strcpy'd into that, and then assigned lpstrTitle to it. Anyway, I'm pretty sure that has nothing to do with my problem. Thanks! Jeff
| Вернуться в корень Архива |