PRB: LB_DIR with Long Filenames Returns LB_ERR in Windows 95

ID: Q131286


The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK), on platform(s):
    • Microsoft Windows 95


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 query words: LongFileName LFN DlgDirList CB_DIR DlgDirListComboBox

Keywords : kbcode kbCtrl kbListBox kbGrpUser kbWinOS95
Version : WINDOWS:95
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: December 7, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.