The ins and outs of the MFC Program-subdocument 2
Afxwininit (hinstance, hprevinstance, lpcmdline, ncmdshow)
View the afxwininit source code:
Bool afxapi afxwininit (_ in _ hinstance, _ in _ hinstance hprevinstance,
_ In_z _ lptstr lpcmdline, _ in _ int ncmdshow)
{
Assert (hprevinstance = NULL );
// Handle critical errors and avoid windows message boxes
Seterrormode (0) |
Sem_failcriticalerrors | sem_noopenfileerrorbox );
// Set resource handles
Afx_module_state * pmodulestate = afxgetmodulestate ();
Pmodulestate-> m_hcurrentinstancehandle = hinstance;
Pmodulestate-> m_hcurrentresourcehandle = hinstance;
Pmodulestate-> createactivationcontext ();
// Fill in the initial state for the Application
Cwinapp * PAPP = afxgetapp ();
If (PAPP! = NULL)
{
// Windows specific initialization (not done if no cwinapp)
PAPP-> m_hinstance = hinstance;
Hprevinstance; // obsolete.
PAPP-> m_lpcmdline = lpcmdline;
PAPP-> m_ncmdshow = ncmdshow;
PAPP-> setcurrenthandles ();
}
// Initialize thread specific data (for main thread)
If (! Afxcontextisdll)
Afxinitthread ();
// Initialize cwnd: m_pfnnotifywinevent
Hmodule =: getmodulehandle (_ T ("user32.dll "));
If (hmodule! = NULL)
{
Cwnd: m_pfnnotifywinevent = (cwnd: pfnnotifywinevent): getprocaddress (hmodule, "notifywinevent ");
}
Return true;
}
Conclusion: afxwininit completes theapp and some thread initialization operations.