Friday, October 29, 2010

Debug Assertion failed - Error message when upgrading Visual C++ to Visual C++ 4.2 or a later version mfc , vc++ , c++

When upgrading vc++ to Visual c++ 4.2 or later you may receive the following error message

Debug Assertion failed
Program: my.exe
File: dbgheap.c
Line: 1017

The reason for this error message is

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.

To solve this issue

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.

// Change the name of the .INI file--CWinApp destructor will free
// the memory.

No comments:

Post a Comment