CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2001
    Location
    Pretoria, Gauteng
    Posts
    46

    m_dwRef assert in ~CCmdTarget

    Hi all, I'm fighting an exit error in an MFC app that is driving me nuts. On exit, MFC asserts in CCmdTarget::~CCmdTarget because m_dwRef is greater than 1 (in this case it is 2). I have determined at which point the dwref is actually created and picked up where it is incremented, and both lie deep in my AfxOleInit call in InitInstance. The assert happens on shutdown when AfxOleTerm is (implicitly) called. I have checked again and again that I am not hanging on to any dialogs or anything and I just seem to be going in circles. Has anyone hit this problem before?

    If it helps I can post the useful parts of the stack traces when the ref count is incremented and when the assert occurs.

    Thanks.

  2. #2
    Join Date
    Jul 2005
    Posts
    767

    Re: m_dwRef assert in ~CCmdTarget

    Of course stack trace would be great. Anyway my guess would be some OLE object is not being released.

  3. #3
    Join Date
    Jun 2001
    Location
    Pretoria, Gauteng
    Posts
    46

    Re: m_dwRef assert in ~CCmdTarget

    Thanks, I thought as much, but after commenting out most of my app I can't imagine what. I have to work on something else at the moment, but as soon as I'm back on the bug I'll grab the stack trace and post it.

  4. #4
    Join Date
    Jul 2002
    Location
    Aachen, Germany
    Posts
    22

    Re: m_dwRef assert in ~CCmdTarget

    I had the same problem.

    Seemed to be a problem with different versions of MFC (actually, there were completely different includes in my files, one was standard win32, the other one AFX/MFC) in different stdafx.h files I was using in a project combined from 2 other projects.

    I reduced to one, the error disappeared. Maybe it helps you.

    In case someone else needs this info: the assertion occured here:

    Code:
    CCmdTarget::~CCmdTarget()
     {
    #ifndef _AFX_NO_OLE_SUPPORT
     	if (m_xDispatch.m_vtbl != 0)
      		((COleDispatchImpl*)&m_xDispatch)->Disconnect();
      	ASSERT(m_dwRef <= 1);
     #endif 
     	m_pModuleState = NULL;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured