FIX: CMenu::GetMenuString Truncates Strings Longer Than 256 Characters

ID: Q217208


The information in this article applies to:


SYMPTOMS

CMenu::GetMenuString truncates menu strings longer than 256 characters. This problem is most commonly seen when retrieving a file name from the "most recently used" list on the File menu. These file names are occasionally longer than 256 characters.


CAUSE

The CMenu member function int CMenu::GetMenuString(UINT nIDItem, CString& rString, UINT nFlags) const, hard codes the maximum length for a retrieved menu string at 256 characters. See VC98\MFC\Include\Afxwin.h, line 1043.


RESOLUTION

To work around this problem, use the LPTSTR version of this function; for example, int CMenu::GetMenuString(UINT nIDItem, LPTSTR lpString, int nMaxCount, UINT nFlags) const.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:

Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

Q194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed


MORE INFORMATION

Steps to Reproduce Behavior

  1. Use CMenu::AppendMenu(UINT nFlags, UINT nIDNewItem, LPCTSTR lpszNewItem) to append a menu item longer than 256 characters in length.


  2. Retrieve the menu item using CMenu::GetMenuString(UINT nIDItem, CString& rString, UINT nFlags).


RESULTS: Note that the string is truncated to a length of 255 characters.

Additional query words:


Keywords          : kbservicepack kbMFC KbUIDesign kbVC600bug kbVS600sp2 kbVS600SP1 kbVS600sp3fix 
Version           : winnt:6.0
Platform          : winnt 
Issue type        : kbbug 

Last Reviewed: May 19, 1999