PRB: LB_DIR with Long Filenames Returns LB_ERR in Windows 95

Last reviewed: September 29, 1995
Article ID: Q131286
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT version 3.51
        - Microsoft Windows 95 version 4.0
        - Microsoft Win32s version 1.3
    

SYMPTOMS

Sending an LB_DIR message to a list box that specifies a long filename in the lParam returns LB_ERR in Windows 95 but works fine in Windows NT version 3.51.

CAUSE

The implementation of list boxes in Windows 95 thunks down to 16-bit USER.EXE, and the LB_DIR command has not been enhanced to support long filenames.

RESOLUTION

Convert the long filename to its short form before passing it as the lParam to LB_DIR by using GetShortPathName(). Similarly, when calling DlgDirList() to fill a list box with filenames, make sure the lpPathSpec parameter refers to the short name of the file.

Sample Code

char  szLong [256], szShort [256];
DWORD dwResult; LONG lResult;

lstrcpy (szLong, "C:\\This Is A Test Subdirectory"); dwResult = GetShortPathName (szLong, szShort, 256); if (!dwResult)

   dwResult = GetLastError ();

lstrcat (szShort, "\\*.*"); lResult = SendDlgItemMessage (hdlg,
                              IDC_LIST1,
                              LB_DIR,
                              (WPARAM)(DDL_READWRITE),
          (LPARAM)(LPSTR)szShort);
if (LB_ERR == lResult)
   // an error occurred

NOTE: If a file with a long filename exists under the subdirectory specified, Windows 95 displays the short name in the list box, whereas Windows NT displays the long name.

STATUS

This behavior is by design.

MORE INFORMATION

This is not a problem under Windows NT because it always supported long filenames.

You can have an application check the system version and decide at run time if it should call GetShortPathName before passing the filename as lParam to the LB_DIR message. Windows NT will, however, take a short name and fill the list box with the filenames.


Additional reference words: 4.00 1.30 LongFileName LFN DlgDirList CB_DIR
DlgDirListComboBox
KBCategory: kbui kbcode kbpb
KBSubcategory: UsrCtl


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: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.