Assertion in CWinApp::CWinApp - AfxGetThread() == NULL

Discussion in 'Microsoft VC .NET' started by bonk, Dec 7, 2005.

  1. bonk

    bonk Guest

    I have created an MFC project that links MFC MFC as shared dll and uses
    /MD[d] . This MFC application loads another dll B via Loadlibrary that
    has /MD[d] too and also links MFC as shared dll. Dll B again loads dll C
    that also uses MFC as a shared DLL dll and also has /MD[d].

    Also the MFC app statically links to a .lib that has MFC linked as
    shared dll and has /MD[d]

    Now for some odd reason when the constructor of my MFC app is called
    (CMyMFCApp:CMyMFCApp) I get an assertion in CWinApp::CWinApp in this
    line: ASSERT(AfxGetThread() == NULL); (appcore.cpp).

    Any Idea what I possibly might be doing wrong.
     
    bonk, Dec 7, 2005
    #1
    1. Advertisements

  2. bonk wrote:
    > I have created an MFC project that links MFC MFC as shared dll and uses
    > /MD[d] . This MFC application loads another dll B via Loadlibrary that
    > has /MD[d] too and also links MFC as shared dll. Dll B again loads dll C
    > that also uses MFC as a shared DLL dll and also has /MD[d].
    >
    > Also the MFC app statically links to a .lib that has MFC linked as
    > shared dll and has /MD[d]
    >
    > Now for some odd reason when the constructor of my MFC app is called
    > (CMyMFCApp:CMyMFCApp) I get an assertion in CWinApp::CWinApp in this
    > line: ASSERT(AfxGetThread() == NULL); (appcore.cpp).
    >
    > Any Idea what I possibly might be doing wrong.


    A guess: You might be assuming in other constructors that the CMyMFCApp
    object has already been constructed. The order of construction of
    static objects is indeterminate, so you can't do much inside such
    constructors.

    --
    Scott McPhillips [VC++ MVP]
     
    Scott McPhillips [MVP], Dec 7, 2005
    #2
    1. Advertisements

  3. bonk

    bonk Guest

    Scott McPhillips [MVP] schrieb:
    > bonk wrote:
    >
    >> I have created an MFC project that links MFC MFC as shared dll and
    >> uses /MD[d] . This MFC application loads another dll B via Loadlibrary
    >> that has /MD[d] too and also links MFC as shared dll. Dll B again
    >> loads dll C that also uses MFC as a shared DLL dll and also has /MD[d].
    >>
    >> Also the MFC app statically links to a .lib that has MFC linked as
    >> shared dll and has /MD[d]
    >>
    >> Now for some odd reason when the constructor of my MFC app is called
    >> (CMyMFCApp:CMyMFCApp) I get an assertion in CWinApp::CWinApp in this
    >> line: ASSERT(AfxGetThread() == NULL); (appcore.cpp).
    >>
    >> Any Idea what I possibly might be doing wrong.

    >
    >
    > A guess: You might be assuming in other constructors that the CMyMFCApp
    > object has already been constructed. The order of construction of
    > static objects is indeterminate, so you can't do much inside such
    > constructors.
    >

    I have found out that the Ctor of a CWinApp is called 2 times anly the
    3rd time I get this assertion. Only the second time AfxGetThread()
    return NOT NULL and therfore I get the assertion the 2nd time. The first
    time th CTor is called it comes from a dll. the snd time that ctor is
    called it comes from the exe.
     
    bonk, Dec 7, 2005
    #3
  4. On Wed, 07 Dec 2005 17:11:26 +0100, bonk <>
    wrote:

    > I have found out that the Ctor of a CWinApp is called 2 times anly the
    >3rd time I get this assertion. Only the second time AfxGetThread()
    >return NOT NULL and therfore I get the assertion the 2nd time. The first
    >time th CTor is called it comes from a dll. the snd time that ctor is
    >called it comes from the exe.


    Sounds like you have two or more CWinApp objects, and they're using the
    same AfxGetThread data. I suppose this could happen if your libraries are
    linking to different versions of MFC, including mixing of debug and release
    versions. You might use Dependency Walker (depends.exe) to determine the
    DLLs you link to implicitly, or the Sysinternals Process Explorer to
    determine the DLLs you're using at runtime.

    --
    Doug Harrison
    Visual C++ MVP
     
    Doug Harrison [MVP], Dec 7, 2005
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. marat

    Debug Assertion Failed dbgdel.cpp error

    marat, Sep 10, 2003, in forum: Microsoft VC .NET
    Replies:
    2
    Views:
    8,350
    marat
    Sep 15, 2003
  2. Craig Klementowski

    assertion problem in Mixed mode DLL

    Craig Klementowski, Oct 27, 2003, in forum: Microsoft VC .NET
    Replies:
    2
    Views:
    956
    Craig Klementowski
    Oct 29, 2003
  3. Rajko

    DDX_Control & assertion

    Rajko, Dec 4, 2003, in forum: Microsoft VC .NET
    Replies:
    0
    Views:
    395
    Rajko
    Dec 4, 2003
  4. ellieong

    debug assertion failed!

    ellieong, Dec 4, 2003, in forum: Microsoft VC .NET
    Replies:
    4
    Views:
    1,572
    ellieong
    Dec 9, 2003
  5. Dan Trowbridge

    'Enable3dControls' : is not a member of 'CWinApp'

    Dan Trowbridge, Dec 8, 2003, in forum: Microsoft VC .NET
    Replies:
    5
    Views:
    1,985
    Ken Ekberg
    Dec 10, 2003
  6. Guest

    Exception in CWinApp Destructor. Help me.

    Guest, Apr 29, 2004, in forum: Microsoft VC .NET
    Replies:
    0
    Views:
    436
    Guest
    Apr 29, 2004
  7. Milind Phadnis

    CWinApp::WinHelp replaced by CWinApp::WinHelpInternal?

    Milind Phadnis, Aug 3, 2004, in forum: Microsoft VC .NET
    Replies:
    0
    Views:
    1,883
    Milind Phadnis
    Aug 3, 2004
  8. Atul
    Replies:
    0
    Views:
    1,166
Loading...