Microsoft KB Archive/154744

= You receive error messages in an MFC application when you upgrade from an earlier version of Visual C++ to Visual C++ 4.2 or a later version =

Article ID: 154744

Article Last Modified on 11/21/2006

-

APPLIES TO

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

 Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

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

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

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

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q154744

<div class="symptoms_section">

SYMPTOMS
The error below may occur in an MFC application where one of the following is assigned a value by the programmer:

<pre class="fixed_text">  CWinApp::m_pszAppName CWinApp::m_pszRegistryKey CWinApp::m_pszExeName CWinApp::m_pszHelpFilePath CWinApp::m_pszProfileName

The following error is displayed in a message box:

<pre class="fixed_text">  Debug Assertion failed Program: my.exe File: dbgheap.c  Line: 1017 Expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

In Microsoft Visual C++ 6.0, the following error is displayed in a message box:

<pre class="fixed_text">  Debug Assertion failed Program: my.exe File: dbgheap.c  Line: 1011 Expression: _CrtIsValidHelpPointer(pUserData)

You may see this error when you upgrade from an earlier version of Visual C++ to Visual C++ versions 4.2 or later.

<div class="cause_section">

CAUSE
The CWinApp destructor in MFC included with Visual C++ 4.2 and later now frees the data assigned to the member variables shown above by passing the pointer to the free function. Doing this prevents memory leaks, which would occur if an MFC regular DLL were dynamically loaded and unloaded.

<div class="status_section">

STATUS
This behavior is by design.

<div class="resolution_section">

RESOLUTION
If you assign a value to m_pszAppName, m_pszRegistryKey, m_pszExeName, m_pszHelpFilePath, or m_pszProfileName, the data must be dynamically allocated on the heap. You may want to use the _tcsdup run-time library function to do this.

Also, free the memory associated with the current pointer before assigning a new value. Here is an example: // First free the string that was allocated by MFC in the startup // of CWinApp. The string is allocated before InitInstance is  // called. free((void*)m_pszProfileName);

// Change the name of the .INI file--CWinApp destructor will free // the memory. m_pszProfileName=_tcsdup(_T("d:\\somedir\\myini.ini"));

Additional query words: 4.10 port porting strdup

Keywords: kbtshoot kberrmsg kbprb KB154744

-

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

© Microsoft Corporation. All rights reserved.