DOC: CFile::GetFileTitle May Return with File Extension

Last reviewed: July 31, 1997
Article ID: Q143409
4.00 WINDOWS NT kbprg kbdocerr kbdocfix

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC) included with: Microsoft Visual C++, 32-bit Edition, version 4.0

SUMMARY

Using the GetFileTitle() CFile member function to return the file's title may return the extension as well. However, the documentation for this member function does not fully describe this "by design" behavior.

This was corrected in Visual C++ 4.1.

MORE INFORMATION

The behavior of CFile::GetFileTitle() member function has changed in Windows 95. The expected behavior is described here.

From the Win32 SDK GetFileTitle() documentation:

In Windows 95, the GetFileTitle() function retrieves the same text that the system would compose in displaying a file name to the user. This text is intended to be used for display purposes only and is in accordance with the user's preferences for display of filenames. There are two important implications of this enhancement: First, an application cannot expect to use the resultant text to call file system functions because it is merely a display name; Second, in preserving the function's "insufficient buffer" case, the return value for that code path reflects the size of the text that would be composed in the normal case such that the caller may attempt to allocate sufficient storage and retrieve the result with a subsequent call to GetFileTitle(). More generally, there is no guaranteed connection between the resultant text or return value and the characters in the original buffer passed by the application.

In porting applications to Windows 95, you need to update any code that relies on such behavior in previous versions of the operating system. The most common case is code that deliberately calls GetFileTitle() with a NULL return buffer, passing size 0, and then uses the return value as an index into the original string. This technique is no longer supported. Applications can usually achieve similar results (and superior performance) with run-time library functions such as strrchr, wcsrchr, and _mbsrchr.


KBCategory: kbprg kbdocerr kbdocfix
KBSubcategory: MfcFileIO
Additional reference words: 4.00 4.10
Keywords : MfcFileIO kbdocerr kbdocfix kbprg
Technology : kbMfc
Version : 4.00
Platform : NT WINDOWS


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: July 31, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.