Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
debug assertion failed - what are the causes of this error?

- the code for the dll is same as the other projects but in others i don't get this error but in one project iam getting this error..

-
C++
if ( m_wndSplitter.CreateView(nRow, nCol, n_pViewClass, CSize(0, 0), &context) == FALSE )
	{
        TRACE( "Failed to Create View\n" );
		ASSERT(0);
		return NULL;
	}


-after this if() statement in other projects it goes to he particular dll's showwindow() function ..but why it is not going in this case?

-all the parameters in the if() are getting valid values .

What I have tried:

// c14OCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "..\main\CommonDlgRes.h"
#include "OutputContactRes.h"
#include "..\CommonDLLEx\CLabel.h"
#include "..\common\OfflinerCommon.h"
#include "c14OCDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// c14OCDlg

#define MAX_LEN	12

IMPLEMENT_DYNCREATE(c14OCDlg, CFormView)

c14OCDlg::c14OCDlg()
	: CFormView(c14OCDlg::IDD)
{
	//{{AFX_DATA_INIT(c14OCDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bInitialUpdate = FALSE;		
	m_pFrame         = NULL;
}

c14OCDlg::~c14OCDlg()
{
}

void c14OCDlg::DoDataExchange(CDataExchange* pDX)
{
	int MaxChars = MAX_LEN;
	int i = 0;
	
	CStringArray tmpOutputContact;
	tmpOutputContact.SetSize(m_pOutContact->GetSize());
	
	// get a copy for compares!
	if ( pDX->m_bSaveAndValidate == TRUE )
	{
		for (i = 0; i < m_pOutContact->GetSize(); i++ )
			tmpOutputContact[i] = m_pOutContact->GetAt(i);
	}

	try
	{

	CFormView::DoDataExchange(pDX);

	DDX_Control(pDX, IDC_STATIC_DEV_TITLE, m_lblTitle);

	int iIndex = 0;
	DDX_Text(pDX, EDIT_OUT1, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
	DDX_Text(pDX, EDIT_OUT2, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

    iIndex++;
	DDX_Text(pDX, EDIT_OUT3, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

    iIndex++;
	DDX_Text(pDX, EDIT_OUT4, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
	DDX_Text(pDX, EDIT_OUT5, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
	DDX_Text(pDX, EDIT_OUT6, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
	DDX_Text(pDX, EDIT_OUT7, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
	DDX_Text(pDX, EDIT_OUT8, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
    DDX_Text(pDX, EDIT_OUT9, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);
	
	iIndex++;
    DDX_Text(pDX, EDIT_OUT10, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
    DDX_Text(pDX, EDIT_OUT11, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
    DDX_Text(pDX, EDIT_OUT12, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
    DDX_Text(pDX, EDIT_OUT13, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);

	iIndex++;
    DDX_Text(pDX, EDIT_OUT14, (*m_pOutContact)[iIndex]);
	DDV_MaxChars(pDX, (*m_pOutContact)[iIndex], MaxChars);


	}
    catch(...)
	{
		// data failed, so restore old data
		if ( pDX->m_bSaveAndValidate )
			m_pOutContact->Copy(tmpOutputContact);
	}

	if ( pDX->m_bSaveAndValidate )
	{
		bool bChanged = false;
		for (i = 0; i < m_pOutContact->GetSize(); i++ )
		{
			if ( tmpOutputContact[i] != (*m_pOutContact)[i] )
			{
				bChanged = true;
				break;
			}
		}

		if (bChanged)
			GetDocument()->SetModifiedFlag( TRUE );
	}
}


BEGIN_MESSAGE_MAP(c14OCDlg, CFormView)
	//{{AFX_MSG_MAP(c14OCDlg)
	// NOTE - the ClassWizard will add and remove mapping macros here.
	ON_WM_SHOWWINDOW()
	ON_BN_CLICKED(IDC_RETURN, OnReturnKeyPress)	
	ON_WM_CLOSE()	
	ON_WM_TIMER()
	ON_EN_CHANGE(EDIT_OUT1, OnChange)
	ON_EN_CHANGE(EDIT_OUT2, OnChange)
	ON_EN_CHANGE(EDIT_OUT3, OnChange)
	ON_EN_CHANGE(EDIT_OUT4, OnChange)
	ON_EN_CHANGE(EDIT_OUT5, OnChange)
	ON_EN_CHANGE(EDIT_OUT6, OnChange)
	ON_EN_CHANGE(EDIT_OUT7, OnChange)
	ON_EN_CHANGE(EDIT_OUT8, OnChange)
    ON_EN_CHANGE(EDIT_OUT9, OnChange)
	ON_EN_CHANGE(EDIT_OUT10, OnChange)
	ON_EN_CHANGE(EDIT_OUT11, OnChange)
	ON_EN_CHANGE(EDIT_OUT12, OnChange)
	ON_EN_CHANGE(EDIT_OUT13, OnChange)
	ON_EN_CHANGE(EDIT_OUT14, OnChange)
	ON_EN_SETFOCUS(EDIT_OUT1, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT2, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT3, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT4, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT5, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT6, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT7, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT8, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT9, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT10, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT11, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT12, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT13, OnSetfocusOut)
	ON_EN_SETFOCUS(EDIT_OUT14, OnSetfocusOut)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// c14OCDlg diagnostics

#ifdef _DEBUG
void c14OCDlg::AssertValid() const
{
	CFormView::AssertValid();
}

void c14OCDlg::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// c14OCDlg message handlers

void c14OCDlg::GetData()
{

	m_pFrame = GetParentFrame();
	// get data
	LRESULT lResult = 0;
	lResult = m_pFrame->SendMessage(WM_GET_DATA, OUTPUT_CONTACTS);
	m_pOutContact = (CStringArray *)lResult;
}

void c14OCDlg::OnInitialUpdate() 
{
	GetData();
	
	
	CFormView::OnInitialUpdate();
	m_bInitialUpdate = TRUE;

	m_lblTitle.SetText("Output Contact Names");
	m_lblTitle.SetFontBold(TRUE);
	m_lblTitle.SetFontSize(CONST_TITLE_TEXT_SIZE);
}


//------------------------------------------------------------------------
// METH NAME: OnShowWindow(BOOL bShow, UINT nStatus) 
// ACTION   : if we are showing, make the first control active		
// RETURNS  :
// GLOBALS  : 
// COMMENTS : 
//------------------------------------------------------------------------
void c14OCDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CFormView::OnShowWindow(bShow, nStatus);
	
	if ( bShow == TRUE && m_bInitialUpdate == TRUE )
	{
		CWnd *wnd = GetDlgItem( EDIT_OUT1 );
		wnd->SetFocus();
	}	
}


//-----------------------------------------------------------------------------
// FUNCTION NAME : OnReturnKeyPress()
// ACTION		 : pass focus to the next control when the return-key is pressed.
// RETURN		 :
// GLOBAL		 :
// REFERENCE	 :
// COMMENT		 : ask the window to handle the job by means of window messaging.
//-----------------------------------------------------------------------------
void c14OCDlg::OnReturnKeyPress() 
{
	PostMessage( WM_NEXTDLGCTL, 0, 0L);
}


// =============================== EN_CHANGE Message Handler ==========================
void c14OCDlg::OnChange() 
{
	UpdateData(TRUE);
}



void c14OCDlg::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	if ( lHint == SAVING_FLAG_ )
		UpdateData( TRUE );
	else if ( lHint == LOADING_FLAG_)
		UpdateData( FALSE );
	else if ( lHint == UPDATE_FLAG_ )
	{
		GetData();
		UpdateData( FALSE );	
	}
}


void c14OCDlg::OnClose() 
{
	m_bInitialUpdate = FALSE;
	this->EnableWindow( FALSE );
	this->ShowWindow( SW_HIDE );
	
	CFormView::OnClose();
}

void c14OCDlg::OnSetfocusOut() 
{
	if ( m_pFrame )
	{
		sprintf(m_Tip.szLarge, "Enter up to %d characters for Output Contact name.", MAX_LEN);
		m_pFrame->SendMessage(WM_SB_TIP, MSG_STRING, (LPARAM)&m_Tip.szLarge);
	}
}

BOOL c14OCDlg::PreTranslateMessage(MSG* pMsg) 
{
#if 1 //Check for special charector
	HANDLE hCopyData;
	char *szText;
	CString szSpecial;

	if( pMsg->wParam == 'V' ) //Check for Paste
	{
		if( IsCTRLpressed() )
		{
			if( OpenClipboard() )
			{
				hCopyData = GetClipboardData(CF_TEXT);
				CloseClipboard();
				szText = (char*)GlobalLock(hCopyData);
				szSpecial = szText ;
				for (int n = 0; n < szSpecial.GetLength(); n++)
				{
					UINT uiKey = unsigned int(szSpecial[n]);

					if (!isdigit(szSpecial[n]) && CheckForSpecialChar(uiKey) )
						return TRUE;					
				}			

			}
		}
	}
	if ( pMsg->message == WM_CHAR )
	{
		return CheckForSpecialChar((unsigned int ( pMsg->wParam )));
	}	
#endif

	return CFormView::PreTranslateMessage(pMsg);
}
Posted
Updated 12-Apr-19 19:41pm
v2
Comments
Richard MacCutchan 21-Nov-18 5:02am    
Use you debugger to find out why CreateWindow failed. Check all the parameters being passed from your code.

1 solution

To find out, you need to look very closely at all the parameters you are passing to the function - and than means your code needs to be running when you check them. We can;t do that, as we can't run your code under the same conditions you do - we don't have any context for the code fragment, or any of the data you use.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Richard MacCutchan 13-Apr-19 3:12am    
I guess he gave up back in November.
OriginalGriff 13-Apr-19 3:32am    
Probably, yes ... it came up in the unanswered queue because Michael modified it, and I didn't look at the post date ... :blush:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900