none
Problem with Multiple File Selection Dialog in Windows7

    Question

  • Did anyone encounter a problem with the common dialog for file selection when multiple selection is enabled?
    I have a software that works correctly on Windows XP and Vista, but fails on Windows7.
    The problem occurs, when you select a lot of files in the dialog, so that the string with all filenames is longer than 260 characters. In this case the string is cut at that point.
    Now I am wondering if this problem is specific to my software or if it's a general problem on Windows7.

    Thursday, November 12, 2009 8:10 AM

Answers

  • 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
    • Marked as answer by Shanadas Thursday, December 03, 2009 6:11 PM
    Wednesday, November 18, 2009 12:38 PM

All replies

  • 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" =========
    • Proposed as answer by Shanadas Friday, November 13, 2009 8:10 PM
    Friday, November 13, 2009 8:08 PM
  • 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
    • Marked as answer by Shanadas Thursday, December 03, 2009 6:11 PM
    Wednesday, November 18, 2009 12:38 PM