MFC Edit control produces debug assert on first action

Bryan Kelly 426 Reputation points
2025-04-26T21:03:46.9+00:00

Windows 11, Visual Studio 17.13.3, C++, MFC, dialog app

Question:  In the dialog constructor,  add code for an Edit Control to clear it and get a popup dialog stating: Debug Assertion Failed!

Details

I solicited Bing.com and ChatGPT (right name?) for example code and followed it.  Found a learn.microosft.com web page and followed it.  They give the same advice.  Evidently there is something I don’t recognize because both produced the same result.

Create an MFC project with C++, add a second dialog, and get that dialog to open, build, run, be sure that works.  In the second dialog, drop an Edit control and add code in the constructor to clear it.  At the bottom of the h file VS automatically added this.

class C_Show_Numbers : public CDialog

{

            ``DECLARE_DYNAMIC(C_Show_Numbers)

public:

            ``CEdit ec_show_numbers_3;

            ``afx_msg void OnEnChangeShowNumbers3();

};

In the dot cpp file I added this

C_Show_Numbers::C_Show_Numbers(CWnd* pParent /*=nullptr*/)

            ``: CDialog(IDD_SHOW_NUMBERS, pParent)

{``           ``ec_show_numbers_3.Clear();

            ``ec_show_numbers_3.SetWindowTextW(_T("third text"));``  ``}

The result is the dialog shown below.

edit_contol_assert_01 So what did I miss in the instructions?

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
1,074 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.