Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Debug Assertion Failed error

Posted on 1999-07-27
Medium Priority
Last Modified: 2013-11-20

I'm new to programming in Visual C++ so I need some help. I am a BC++ programmer and have used OWL long time, but I want to learn MFC now.

I want to program an application who has only a Property Sheet. I have followed an example of the Kruglinski's book and I have only made one Property Page. The fact is that when I run the program, it sends the message Debug Assertion Failed! Program F:\FMAN\DEBUG\FMAN.EXE  File: afxwin1.inl  Line:22

I have to press the Abort button.
How can I solve it? this is second time that the same error occures but with different applications.

Here is a part of the main application code:
CFman::CFman():Opciones("Manejador de Unidades Fingerscan")
      // TODO: add construction code here,
      // Place all significant initialization in InitInstance

// The one and only CFman object

CFman theApp;

// CFman initialization

BOOL CFman::InitInstance()
      // Standard initialization
      // If you are not using these features and wish to reduce the size
      //  of your final executable, you should remove from the following
      //  the specific initialization routines you do not need.

#ifdef _AFXDLL
      Enable3dControls();                  // Call this when using MFC in a shared DLL
      Enable3dControlsStatic();      // Call this when linking to MFC statically

      // Since the dialog has been closed, return FALSE so that we exit the
      //  application, rather than start the application's message pump.
      return FALSE;

Here's my property sheet class:
CFingerScan::CFingerScan(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
      :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)

CFingerScan::CFingerScan(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
      :CPropertySheet(pszCaption, pParentWnd, iSelectPage)


And here's the property page class:
CSetupPage::CSetupPage() : CPropertyPage(CSetupPage::IDD)
            // NOTE: the ClassWizard will add member initialization here


void CSetupPage::DoDataExchange(CDataExchange* pDX)
            // NOTE: the ClassWizard will add DDX and DDV calls here

BEGIN_MESSAGE_MAP(CSetupPage, CPropertyPage)
            // NOTE: the ClassWizard will add message map macros here

// CSetupPage message handlers

That's all, as you can see, is very simple, what is wrong with this code?

Thanks in advance
Question by:demarcy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 23

Expert Comment

ID: 1311723
When ASSERTION message comes.. don't hit abort. Hit Retry and then see where in your code the assertion happened..

What i suspect is that u have called a function on invalid window handle.

From what i can see... InitInstance function doe snot seem to be complete. This is the place where u property sheet will be created and set as mainwindow of the application.

See where exacly this assertion is coming from. Then u can add some more info to your question..

Expert Comment

ID: 1311724
It seems to be a Dialog based application.
Can you please tell me when exactly (Line) you get the assertion failure.


Author Comment

ID: 1311725
Well... I have got that error twice, the first time was on a dialog based application. I have continued trying to depelop it since it's the best for my purposes, so let me explain more about the code.

To have a dialog box (the application) which has no buttons, for obvious reasons. To exit it, the user will need only to press the cross button on the top right corner. On that dialog, I have a Tab Control, IDC_OPTIONS, inside that control I want to place a child dialog box depending on the tab selected. I have only one dialog created now, the one to be placed on the first tab, IDD_SETUP. In Borland OWL I only call the constructor for the dialog (in the constructor for the FrameWindow object) and then use ShowWindow method with SW_SHOW attribute to show the window (in the SetupWindow method). I have tried to do almost the same in MFC but I got those strange errors.

Line where assertion is launched:
Opciones = (CTabCtrl *)this->GetDlgItem( IDC_OPTIONS );

I debug when assertion comes and the application continues over that instruction, so I guess the problem is there.
By debugging, after the call to GetDlgItem method returns a value of 0x00000000, so I think Opciones isn't being created well.

Where is the problem? do you have a program that uses a Tab Control? that way I would be able to study the right way to do it.

Please don't suggest me to use a PropertySheet and PropertyPages classes instead. I want to use a Tab Control :)

Thanks a lot
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.


Author Comment

ID: 1311726
Ah! and of course I have just before Opciones = (CTabCtrl *)this->GetDlgItem( IDC_OPTIONS );  the call of the constructor this way Opciones = new CTabCtrl( );

I use this opportunity to ask you in what cases I define an object as a pointer and in what cases as a normal variable. At the moment, I have declared Opciones as CTabCtrl*. In some examples I have seen declarations like CtabCtrl Opciones; in the last case, methods and member variables are called using . instead of ->. The method GetDlgItem can only return a pointer to the object?

Thanks again

Expert Comment

ID: 1311727
where exactly the code has been given.(In which message handler)
Can you get the handle of this pointer?


Author Comment

ID: 1311728
I have realized that it isn't the same thing to call an initialization method from one or other method. I placed Opciones = (CTabCtrl *)this->GetDlgItem( IDC_OPTIONS ); in the dialog constructor and an assertion was launched. I placed it on the onInitDialog and after it, I could safely use InsertItem, and at least when I run the application, the Tab control is shown with the corresponding added tabs.

The problem now is when I try to show a dialog according to the tab selected. An assertion accures again. These are some questions refering to the way to do it:
1) Do I have to declare the child dialog (to be placed when a tab is selected) as CSetupPage* Setup, or CSetupPage Setup. That is, as a pointer or not.
2) How and where do I have to call the constructor to assign the resource ID with the object. That dialog is child of the TabControl, so I'm trying Setup = new CSetupPage( Opciones ) on the onInitDialog of the main dialog, because Opciones is there assigned.
3) Where and how do I have to show the dialog. I cannot use DoModal, since the dialog is a child. (I have tried it, I have used DoModal in the onPaint method, that way the application doesn't fail, but the dialog is shown as modal and under the main window. If I use ShowWindow method, assertion comes.

When an assertion error arrives, I realized that hWnd variable is 0x00000000 so the dialog isn't created well.

I hope you can help me.. if you don't understand something or need more information, please post a comment. I could even post the whole code.. it is too simple and too small, so it is no problem.


Expert Comment

ID: 1311729

Author Comment

ID: 1311730
It is set this way:

IDD_SETUP DIALOGEX 0, 0, 442, 196

So, it has no border and it's a child dialog. When I worked with OWL, I set the dialog that way and it worked


Accepted Solution

speedup earned 150 total points
ID: 1311731
most of the codes created by classwizard as you list them above.
the most possible cause of the assertion failure is the null pointer.
the following steps can help you find the bug:
1. press debug or retry button when assertion failure appears.
2. the highlight bar stops where the null pointer is refered. try to check if the pointer isn't allocated.
3. if the pointer points to a block of memory, go to the contruction of the class ( for example, new MyClass() ). put breakpoint on it.
4. run the program again. and it breaks where you put breakpoint. press F11 to trace into the codes to see where the problem is.

and you can list the related codes here to make clarity for me.

Expert Comment

ID: 1311732
I have done so and I found that the program fails on an instruction that uses de hWnd, I think it's the hWnd of the control I'm trying to show (it is 0x000000). I could finally placed the tab control, but the font by default is too ugly, so I will try to learn how to change the font. But the main problem is that when I run the application, the hourglass cursor stays for long, so I don't know if I'm doing well when I created the tab control, for that reason  I have asked for some examples of using tabctrl.

This is where I create the control
      // TODO: add member initialization code here
      Opciones = new COpciones();
Here is where I make it visible

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
      RECT rect;

      if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
            return -1;
      // create a view to occupy the client area of the frame
      if (!m_wndView.Create( NULL, NULL, AFX_WS_DEFAULT_VIEW,
            CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
            TRACE0("Failed to create view window\n");
            return -1;
      rect.left   = 0;    = 0;
      rect.right  = 0;
      rect.bottom = 0;
      Opciones->Create(TCS_TABS|WS_VISIBLE|WS_TABSTOP, CRect(10, 10, 20, 20), this, AFX_IDW_PANE_FIRST);
      Opciones->InsertItem(0, "Configuración");
      Opciones->InsertItem(1, "Directorios");
      Opciones->InsertItem(2, "Transacciones");
      Opciones->InsertItem(3, "Usuarios");
      Opciones->InsertItem(4, "Acerca de...");
      return 0;

The TRect parameter doesn't work, so I cannot control de size and position of the control (????????). The control is shown if and only if I use AFX_IDW_PANE_FIRST as the ID of the control.

Any further help will be appreciated

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question