ID: Q131286
The information in this article applies to:
- Microsoft Windows 95
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.
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.
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.
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.
This behavior is by design.
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
Issue type : kbprb
Last Reviewed: January 2, 1999