Microsoft KB Archive/156067

= FIX: Setting Tooltip Text in OnToolHitTest Causes Assertion =

Article ID: 156067

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q156067

<div class="symptoms_section">

SYMPTOMS
Attempting to set the text for a tooltip in the OnToolHitTest function of a CWnd by assigning a resource ID to the TOOLINFO struct's lpszText member causes the following assertion to occur:

<pre class="fixed_text">  Debug assertion failed File: dbgheap.c  Line: 1011

For example, setting the TOOLINFO struct as follows: pTI->lpszText= MAKEINTRESOURCE(SomeId); pTI->hinst=AfxGetInstanceHandle; where pTI is a pointer to the TOOLINFO struct, will cause the problem. Setting the TOOLINFO struct members in this manner allows the programmer to specify a resource that the tooltip uses to get the text for the tooltip.

<div class="cause_section">

CAUSE
The CWnd::FilterToolTipMessage function contains the following code: if (tiHit.lpszText != LPSTR_TEXTCALLBACK) free(tiHit.lpszText); Because lpszText is not set to LPSTR_TEXTCALLBACK, the free function is called. However, a resource ID, rather than a string, was specified in the OnToolHitTest function, and therefore the assertion occurs.

<div class="resolution_section">

RESOLUTION
Instead of specifying a resource ID to load, load the resource and assign the text to the TOOLINFO struct's lpszText member as follows: pTI->lpszText = (char *)malloc(200, sizeof(char)); if (::LoadString(AfxGetInstanceHandle,pTI->uId, pTI->lpszText,200)==0) {     ASSERT(FALSE);   //String resource doesn't exist } MFC frees the allocated buffer after it has added the tool (that is, after it has sent the TTM_ADDTOOL message).

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem has been fixed in Visual C++ version 5.0.

Additional query words: kbVC400bug tool tip

Keywords: kbbug kbfix kbnoupdate kbtooltip kbuidesign kbvc500fix KB156067

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.