CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2002
    Location
    Monte Carlo
    Posts
    129

    [RESOLVED] Migrating VC++6.0 Application to VC++2015 - AfxClassInit assertion triggered.

    I've imported a legacy Visual C++ 6.0 application into Visual Studio 2015 and attempted to compile. The .exe compiles OK but when opening a file within the application, I get debug assertions when certain classes are initialized.

    The assertion takes place in ..\..\vctools\vc7libs\ship\atlmfc\src\mfc\afxtls.cpp (Line: 22) which is:
    Code:
    void CSimpleList::AddHead(void* p)
    {
    	ASSERT(p != NULL);
    	ASSERT(*GetNextPtr(p) == NULL);  /// <-- This assert is triggered.
    
    	*GetNextPtr(p) = m_pHead;
    	m_pHead = p;
    }

    The code is called from AfxInit() which is located in :C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\src\mfc\objcore.cpp (Line: 157)
    Code:
    void AFXAPI AfxClassInit(CRuntimeClass* pNewClass)
    {
    	AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
    	AfxLockGlobals(CRIT_RUNTIMECLASSLIST);
    	pModuleState->m_classList.AddHead(pNewClass);
    	AfxUnlockGlobals(CRIT_RUNTIMECLASSLIST);
    }
    I have a good 100+ classes/objects that initialize fine. I have 12 that trigger this assertion. If I ignore this assertion in debug and continue running the application, I get into trouble with CWnd::SendMessageToDescendants falling into infinite recursion. I suspect that this may be due to AfxClassInit's assertion failure.

    What should I be looking at to correct this assertion failure? I know that m_classList.AddHead() expects the GetNextPtr to be NULL, but it's not. What changes in VS2015 would cause this behavior?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Migrating VC++6.0 Application to VC++2015 - AfxClassInit assertion triggered.

    Could this discussion help?
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2002
    Location
    Monte Carlo
    Posts
    129

    Re: Migrating VC++6.0 Application to VC++2015 - AfxClassInit assertion triggered.

    Thank you, Victor. That discussion did indeed help. While my problem wasn't specifically related to characters sets, I was linked to a wrong library. (The legacy application has two modes of execution and I was linked to a library not compatible with a mode.) The discussion you linked pointed me in the direction of double checking the libraries to which I was linked. Marking this as resolved and maybe this will help someone in the future.

    Edit: To be clear: Visual Studio 2015 did NOT import the Visual Studio 6 (1998) project correctly. Some library links weren't imported (the cause of my error was manually linking a wrong library) and not all source files were imported. (The project still compiled, but I would get unresolved externals 3 levels up due to missing .cpp files in projects 3 levels down.)
    Last edited by mega Kluge; August 12th, 2015 at 11:00 PM.

Tags for this Thread

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