PRB: Error with GetOpenFileName() and OFN_ALLOWMULTISELECT

Last reviewed: November 2, 1995
Article ID: Q99338
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT version 3.5
    

SYMPTOMS

Assume that the GetOpenFileName() function is called with the Flags parameter set to OFN_ALLOWMULTISELECT (allow for multiple selections in the list box) and OFN_NOVALIDATE (allow for invalid characters in the filename), the lpstrFile parameter points to a 2K buffer, and the corresponding nMaxFile is set appropriately to 2048.

When the GetOpenFileName() function call returns, the complete selection in the list box is not copied to the lpstrFile buffer, but the string in the buffer is truncated.

CAUSE

This is a problem with the GetOpenFileName() function in the current version of COMMDLG.DLL in that the OFN_NOVALIDATE flag cannot be used when multiple selections are allowed.

RESOLUTION

The following are two suggested solutions to this problem:

One solution for this problem is to not use the OFN_NOVALIDATE flag with the OFN_ALLOWMULTISELECT flag. That is, if only the OFN_ALLOWMULTISELECT flag is used, then multiple selections will be copied properly to the text buffer. Note that there is a buffer size limit of 2K bytes for the lpstrFile buffer, and characters are truncated after 2K bytes when the OFN_ALLOWMULTISELECT flag is used.

There is another solution, if both the OFN_ALLOWMULTISELECT and OFN_NOVALIDATE flags must be used simultaneously with GetOpenFileName(). Note that the entire string is always copied into the edit control even though the text gets truncated during the process of copying the text to the lpstrFile buffer. Therefore, one could write a hook procedure and read the entire string from the edit control and use it appropriately instead of using the lpstrFile buffer.


Additional reference words: 3.10 3.50
KBCategory: kbui kbprb
KBSubcategory: UsrCmnDlg


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.