AfxGetThread() returns NULL pointer to pThread in winmain.cpp

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,

I am converting my code from VS2005 to VS2008 on XP and everything was going okay until I tried to run it.  Almost as soon as I try to run it, it crashes... "Unhandled exception as 0x78656641a (mfc90d.dll)...".  I am not completely sure what the problem is.  I have read in other forums that this could be caused from failure to link dlls.  I ran Dependecny Walker and the only dll I was missing was dwmapi.dll.  So I got it from another person and added it to the folder. Now the only message DW gives is
<b><font color="#ff0000" size=1>    "Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module."</b></font>
Outside of DW (which I cant fix), I dont know what else could be wrong or if this is even the cause of my problems.  Could someone please help?
<font color="#0000ff
int</font> AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance...)
{
    ASSERT(hPrevInstance == NULL);

<font color="#0000ff     int</font> nReturnCode = -1;
    CWinThread* pThread = AfxGetThread();
    CWinApp* pApp = AfxGetApp();
<font color="#008000     // AFX internal initialization
</font><font color="#0000ff     if</font> (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
        <font color="#0000ff goto</font> InitFailure;
<font color="#008000     // App global initializations (rare)
</font><font color="#0000ff     if</font> (pApp != NULL && !pApp->InitApplication())
<font color="#0000ff         goto</font> InitFailure;
<font color="#008000     // Perform specific initializations
</font><font color="#0000ff     if</font> (!pThread->InitInstance())                     <-- pThread is NULL
    {

View the full article
 
Back
Top