GetFileTitleA function

Retrieves the name of the specified file.


short GetFileTitleA(
  LPSTR  Buf,
  WORD   cchSize




The name and location of a file.



The buffer that receives the name of the file.


Type: WORD

The length, in characters, of the buffer pointed to by the lpszTitle parameter.

Return value

Type: short

If the function succeeds, the return value is zero.

If the file name is invalid, the return value is unknown. If there is an error, the return value is a negative number.

If the buffer pointed to by the lpszTitle parameter is too small, the return value is a positive integer that specifies the required buffer size, in characters. The required buffer size includes the terminating null character.


GetFileTitle should only be called with legal file names; using an illegal file name has an undefined result.

To get the buffer size needed for the name of a file, call the function with lpszTitle set to NULL and cchSize set to zero. The function returns the required size.

GetFileTitle returns the string that the system would use to display the file name to the user. The display name includes an extension only if that is the user's preference for displaying file names. This means that the returned string may not accurately identify the file if it is used in calls to file system functions.

If the lpszTitle buffer is too small, GetFileTitle returns the size required to hold the display name. However, there is no guaranteed relationship between the required size and the characters originally specified in the lpszFile buffer. For example, do not call GetFileTitle with lpszTitle set to NULL and cchSize set to zero, and then try to use the return value as an index into the lpszFile string. You can usually achieve similar results (and superior performance) with C run-time library functions such as strrchr, wcsrchr, and _mbsrchr.


Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header commdlg.h (include Windows.h)
Library Comdlg32.lib
DLL Comdlg32.dll

See also

Common Dialog Box Library