PRB: LB_DIR with Long Filenames Returns LB_ERR in Windows 95Last reviewed: September 29, 1995Article ID: Q131286 |
The information in this article applies to:
SYMPTOMSSending 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.
CAUSEThe 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.
RESOLUTIONConvert 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 occurredNOTE: 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.
STATUSThis behavior is by design.
MORE INFORMATIONThis 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |