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

  • Thread starter Thread starter bonk
  • Start date Start date
B

bonk

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 said:
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 said:
bonk said:
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.
 
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.
 
Back
Top