CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    CFileDialog mulitple selection limit - is there a workaround ?

    In my attempt to capture multiple files using CFileDialog I discovered that there is a limit on the number of characters in the file name buffer. See http://support.microsoft.com/kb/179372

    I have used this code to get the file names and it works fine up to the point where the buffer is full. NB: m_vcsPathnames and m_vcsFilenames are std::vector<CString> types.

    Code:
    	// get  a list of the files to process
    	wchar_t szFilters[]= _T("All Files (*.*)|*.*||");
    
    	// Create an Open dialog; the default file name extension "*.*"
    	CFileDialog fileDlg(TRUE, _T(""), _T("*.*"),
          OFN_FILEMUSTEXIST| OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilters, this);
    	
    	m_vcsPathnames.resize(0);
    	m_vcsFilenames.resize(0);
    
    	if( fileDlg.DoModal ()==IDOK )
    	{
    		POSITION pos (fileDlg.GetStartPosition() ); 
    		while( pos )
    		{
    			CString csPathname( fileDlg.GetNextPathName( pos ) );  
    			int n = csPathname.ReverseFind('\\');
    			CString csFilename = csPathname.Right(csPathname.GetLength() - n - 1);   TRACE0("csFilename =: "); OutputDebugString(csFilename); TRACE0("\n");
    			m_vcsPathnames.push_back(csPathname);
    			m_vcsFilenames.push_back(csFilename);
    		}
    
    	}
    I really need to be able to capture very large numbers of files. Is there any possible work around for this limitation, other than completely writing my own CFileDialogExx class ?
    mpliam

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CFileDialog mulitple selection limit - is there a workaround ?

    Quote Originally Posted by Mike Pliam View Post
    In my attempt to capture multiple files using CFileDialog I discovered that there is a limit on the number of characters in the file name buffer. See http://support.microsoft.com/kb/179372
    The article states that the issue has been fixed since Windows NT SP 2.

    Regards,

    Paul McKenzie

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CFileDialog mulitple selection limit - is there a workaround ?

    Dang, I'm still running NT4 SP1.

  4. #4
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: CFileDialog mulitple selection limit - is there a workaround ?

    Where do you set: fileDlg.GetOFN().lpstrFile and fileDlg.GetOFN().nMaxFile ?

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: CFileDialog mulitple selection limit - is there a workaround ?

    Quote Originally Posted by Mike Pliam View Post

    I really need to be able to capture very large numbers of files. Is there any possible work around for this limitation, other than completely writing my own CFileDialogExx class ?
    CFileDialog is just a thin wrapper over GetOpenFileName. What's the problem to write a function that suits your needs? You do this every single day, don't you?
    Last edited by Igor Vartanov; May 4th, 2013 at 02:17 PM.
    Best regards,
    Igor

  6. #6
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: CFileDialog mulitple selection limit - is there a workaround ?

    Why use GetOpenFileName instead of CFileDialog ? It had the same restriction that
    CFileDialog had. BUt as has been mentioned, that restriction no longer exists. Example:

    Code:
        CFileDialog fileDlg(TRUE, _T(""), _T("*.*"),
          OFN_FILEMUSTEXIST| OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilters, this);
    
        const int minimum_number_of_files   = 1000;
        const int buffer_size = minimum_number_of_files  * (MAX_PATH + 1) + 1;
    
        vector<TCHAR> buffer(buffer_size);
    
        fileDlg.GetOFN().lpstrFile = &buffer[0];
        fileDlg.GetOFN().nMaxFile = buffer_size;
    
        // etc

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: CFileDialog mulitple selection limit - is there a workaround ?

    See also the Remarks section in CFileDialog class documentation.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured