CFileDialog mulitple selection limit - is there a workaround ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

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

  1. #1
    Join Date
    May 2002
    Posts
    1,727

    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,444

    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 online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,441

    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,640

    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,051

    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 03:17 PM.
    Best regards,
    Igor

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

    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
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,058

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

    See also the Remarks section in CFileDialog class documentation.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center