none
Multiple File Selection Bug in Windows7

    Question

  • My software uses a file selection dialog derived from CFileDialog with multiple selection enabled. The code is similar to the code in the Knowledge Base article http://support.microsoft.com/kb/131462/en-us.
    Now I recognized that this code does not work correctly on Windows7.
    The reason is, that the function "CommDlg_OpenSave_GetSpec(GetParent(hwnd), NULL, 0);" always returns zero because GetParent(hwnd) is always zero. The function should normally return the required space for the filenames which works well on XP and Vista.
    As a result the program does not recognize when more space than 260 characters are needed for the complete selection string with all filenames and cut the string.
    The mean thing is, that you won't encounter an error unless you select a lot of files and I guess a lot of programs use this code.
    Does anybody know a workaround for this problem?

    • Changed type Wesley Yao Wednesday, November 18, 2009 3:45 AM
    • Changed type Bernd H Wednesday, November 18, 2009 12:34 PM
    Wednesday, November 11, 2009 5:10 PM

All replies

  • The one time I tried to deal with this, I simply modified the m_ofn.lpstrFile property to point to an extremely large buffer (16 kb), and said to myself "I hope that noone ever wants to select more than 16 kb worth of files at once."

    It doesn't solve the problem you describe, but you don't hit it until many, many more files are selected.

    Edit: I should clarify -- I ended up directly calling GetOpenFileName instead of using a CFileDialog in my application, but I think the principle should hold.

    Wednesday, November 11, 2009 6:45 PM
  • Hi Bernd,

    Thanks for the post.

    I have tried to reproduce your issue .But it worked fine for me even with 720 characters on Windows 7.
    So can you please confirm,where you are getting the string truncated?

    Refer the screenshot below :




    Is the string getting truncated over here in the File name field of dialog box or in the code executing after this?

    Hope this helps.
    ========= "Mark this as answer,if it really helps" =========
    Friday, November 13, 2009 8:11 PM
  • We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by editing your initial post and click the button "Change Type" at the top of the post. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

    Thank you!


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, November 18, 2009 3:45 AM
  • Hi Shanadas,

    the dialog displays the string correctly, but it its truncated when it is written back into the OPENFILENAME struct, because the default length OPENFILENAME::nMaxFile is 260 characters. The knowledge base article http://support.microsoft.com/kb/131462/en-us  shows how to evaluate the amount of memory needed to hold the string and (if it is larger than the default length) reallocs the correct amount of memory for it. I debugged the code and found that the function CommDlg_OpenSave_GetSpec(GetParent(hwnd), NULL, 0); always returns zero because GetParent(hwnd) is always zero on Windows7.
    The result is, that the memory is never reallocated. When the function that calls the dialog then reads OPENFILENAME::lpstrFile it gets the truncated string.

    Regards,
    Bernd
    Wednesday, November 18, 2009 12:33 PM
  • I am also having this kind of problem, that is, GetParent() is returning NULL in a class that inherits the CFileDialog when running the program in Windows 7.
    Monday, November 30, 2009 3:46 PM