Can someone explain the problem with this?

This is a discussion on Can someone explain the problem with this? within the Windows Programming forums, part of the Platform Specific Boards category; I'm pulling my hair out at tho moment over run time errors, I seem to get another exception / debug ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Location
    England
    Posts
    121

    Can someone explain the problem with this?

    I'm pulling my hair out at tho moment over run time errors, I seem to get another exception / debug assert error for every other line I write.

    One that's causing me confusion is:

    Code:
    BOOL CMyPropPage::OnSetActive() 
    {
    	CMyFormDoc* pDoc = (CMyFormDoc*)GetDocument();
    
    	return CPropertyPage::OnSetActive();
    }
    The reported error is on line 45 of objcore.cpp. Can anyone solve this and give me some tips on why these things occur?

    -edit-
    I'm using MFC and VC6 with an appwizard generated MDI using doc/view.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    >Can anyone solve this and give me some
    >tips on why these things occur?

    Difficult. Have you tried using the debugger ? And can you post your whole code at least for the part where the error occurs ? Because the function 'as is' makes no sense but should not crash.

    If you get debug assertions, it should tell you where it fails and what it checks. Jump into the line and see what it checks when the assertion fails.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Location
    England
    Posts
    121
    I've got a full function but in trying to find the source of the error I had commented everything out except that line, my full function is

    Code:
    /////////////////////////////////////////////////////////////////////////////
    // CMyPropPage message handlers
    
    CTykeDoc* CMyPropPage::GetDocument() // non-debug version is inline
    {
    	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTykeDoc)));
    	return (CTykeDoc*)m_pDocument;
    }
    
    
    
    BOOL CMyPropPage::OnSetActive() 
    {
    	CTykeDoc* pDoc = (CTykeDoc*)m_pDocument->IsKindOf(RUNTIME_CLASS(CTykeDoc));//GetDocument();
    
    
    	
    
    
    	//** get pointers to the recordsets
    	m_pMyDaoRecordSet      = pDoc->m_pMyDaoRecordSet;
    
    
    	UINT nCount =PopulateCustomerList();
    	
    	if( nCount > 0 )
    	{
    		this->m_CustomerList.SetCurSel( 0 );
    	}
    
    	//CreateTabs();
    
    	return CPropertyPage::OnSetActive();
    }
    
    
    UINT CMyPropPage::PopulateCustomerList()
    {
    	
    	UINT nCount = 0;
    	ASSERT( m_pMyDaoRecordSet->IsOpen() == TRUE);
    		
    
    	try{
    
    
    	if( !m_pMyDaoRecordSet->IsBOF() )
    	{
    		m_CustomerList.ResetContent();
    		
    		m_pMyDaoRecordSet->MoveFirst();
    
    		while( !m_pMyDaoRecordSet->IsEOF() )
    		{
    			m_CustomerList.AddString( m_pMyDaoRecordSet->m_CCompany_Name );
    			m_pMyDaoRecordSet->MoveNext();
    			nCount++;
    		}
    	}
    
    	}
    	catch(CDaoException* e;)
    	{
    		e->ReportError();
    		e->Delete();
    	}
    
    	return nCount;
    }
    I can send the full thing as an attachment if needed but it's too much to post here.

    Here's the line it fails on in objcore:
    Code:
    BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
    {
    	ASSERT(this != NULL);
    	// it better be in valid memory, at least for CObject size
    	ASSERT(AfxIsValidAddress(this, sizeof(CObject)));
    
    	// simple SI case
    	CRuntimeClass* pClassThis = GetRuntimeClass();
    	return pClassThis->IsDerivedFrom(pClass); // POINTS TO HERE
    }
    A lot of the code is adapted from zMan's demo, just so he doesnt think I'm taking credit, the functions in his demo are used inside a CFormView class, instead of CPropertyPage and he uses OnInitUpdate where I have used OnSetActive.
    Last edited by Robert602; 03-01-2002 at 10:15 AM.

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    First obvious iregularity: IsKindOf returns a BOOL. You cast that into a pointer to an object. This will always yield a null pointer or an invalid pointer as result.

    Assuming this is for debugging and you used GetDocument normally, make sure your own TykeDoc class implements all those macros neccessary for the RUNTIME_CLASS macros used. Look in your help for DECLARE_ and IMPLEMENT_ macros, there are three types.

    If this is a Debug Assertion, find the line where it asserts. It will tell you what happened. If it is a crash, find the line where it crashes, it will help as well. Trace the stackwalk to your last own line of code and see what might be wrong with that.


    Sidenote:

    I never used Doc/View with a CDialog derived class. I'm not sure you can do it this way.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  4. Mesh Release() Problem
    By Morgul in forum Game Programming
    Replies: 6
    Last Post: 03-07-2006, 01:50 PM
  5. Replies: 5
    Last Post: 11-07-2005, 10:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21