BUG:File Open Common Dialog in Win95 Returns Invalid Filename

Last reviewed: October 3, 1996
Article ID: Q139972
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
  • Microsoft Windows 95, version 4.0

SYMPTOMS

Calling the ShowOpen method of the common dialog control to show the File Open common dialog box results in the following error:

   Run-time error '20477'
   Invalid filename

CAUSE

This error occurs the second time the ShowOpen method is called after multiple file names have been previously selected in the File Open dialog box. The only time this error occurs is when the Flags property of the common dialog box includes both cdlOFNAllowMultiselect (to allow multiple selections) and cdlOFNExplorer (to use the Windows Explorer File Open dialog box). Without the new shell, Microsoft Windows NT does not display the Windows Explorer Open File dialog box, so this problem only occurs with Microsoft Windows 95. In this case, clicking multiple files in the File Open dialog box and clicking Open causes the FileName property of the common dialog control to be filled with a NULL delimited string of filenames. When the ShowOpen method is called, an attempt is made to set the default file(s) to whatever the FileName property of the common dialog control is. The error results because the common dialog control does not know what to do when it encounters embedded NULLs in the FileName property.

WORKAROUND

NULLs must be used instead of spaces to delimit the list of file names because the Windows Explorer style Open File common dialog box with multiple selections enabled automatically includes support for long filenames. However, because the Open File dialog box does not accept a list of NULL delimited files when it is displayed, there is no way to have multiple files selected by default when displaying the Open File dialog box.

Use either of the following methods to avoid the error described above:

In your code, before the ShowOpen method is called again, reset the FileName property of the common dialog box to a single file or to no file at all.

- or -

Do not use the cdlOFNAllowMultiselect and cdlOFNExplorer flags at the same time. Search on "CommonDialog control," Topic: "Changes to CommonDialog Flags for Windows 95 and Windows NT," in the Visual Basic Help file for more information on the behavior of different combinations of these constants under different operating systems.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of the article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to reproduce problem (under Windows 95 only)

  1. Start Visual Basic, or if it is already running, click New Project on the File menu.

  2. In the toolbox, double-click CommonDialog to add a common dialog control to the form.

  3. In the toolbox, double-click the command button to add a new command button to the form.

  4. Add the following code to the Command1_Click procedure:

          Private Sub Command1_Click()
    
             CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
             CommonDialog1.ShowOpen
          End Sub
    
    

  5. On the Run menu, click Start or press the F5 key to run your application.

  6. Click the command button and in the resulting File Open dialog box select two or more files. Click Open to hide the File Open dialog box.

  7. Click the command button again to attempt to show the File Open dialog box again. Instead of the dialog box, a message box showing the above mentioned error is displayed.

REFERENCES

Visual Basic for Windows Help file version 4.0; Search on "CommonDialog control,"; Topic: "Changes to CommonDialog Flags for Windows 95 and Windows NT,".


Additional reference words: 4.00 vb4win vb4all buglist4.00 win95
KBCategory: kbprg kbbuglist
KBSubcategory: PrgCtrlsStd


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: October 3, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.