// initialize CWinThread state
AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE();
AFX_MODULE_THREAD_STATE* pThreadState = pModuleState->m_thread;
ASSERT(AfxGetThread() == NULL);
pThreadState->m_pCurrentWinThread = this;
ASSERT(AfxGetThread() == this);
m_hThread = ::GetCurrentThread();
m_nThreadID = ::GetCurrentThreadId();
// initialize CWinApp state
ASSERT(afxCurrentWinApp == NULL); // only one CWinApp object please
pModuleState->m_pCurrentWinApp = this;
ASSERT(AfxGetApp() == this);
It looks as though somehow p_mModuleState is pointing to a globally
accessible object, which is then read by AfxGetApp().
AfxGetApp() returns afxCurrentWinApp, which is just an alias for
AfxGetModuleState()->m_pCurrentWinApp. CWinApp() assigns to
pModuleState->m_pCurrentWinApp. pModuleState is the result of
_AFX_CMDTARGET_GETSTATE(), which is defined like this:
#ifdef _AFXDLL
#define _AFX_CMDTARGET_GETSTATE() (m_pModuleState)
#else
#define _AFX_CMDTARGET_GETSTATE() (AfxGetModuleState())
#endif
Why does it depend on _AFXDLL, which I assume is set if you're building with
MFC as a DLL? Anyway, it looks like AfxGetModuleState() sets a global or
two, but it's a little confusing.
Can anyone make this more clear?
Thanks,
McGee
See :- http://www.codeproject.com/cpp/mfcprogflow.asp
Regards,
Nish [VC++ MVP]
"McGee" <cla...@NO-SPAM-TILL-BROOKLYN-trefs.com> wrote in message
news:48A4F4A896C377D4.F37495F6...@lp.airnews.net...
pModuleState->m_pCurrentWinApp = this;
but all that's said about it is "Thus when we create our global CNWinApp
object, it's constructor gets called and the AFX_MODULE_STATE structure is
setup properly." What I wonder is "How?" pModuleState =
_AFX_CMDTARGET_GETSTATE(), which as I said is just a macro:
#ifdef _AFXDLL
#define _AFX_CMDTARGET_GETSTATE() (m_pModuleState)
#else
#define _AFX_CMDTARGET_GETSTATE() (AfxGetModuleState())
#endif
So its value depends on whether or not you're using MFC as a DLL. HERE'S
where I get lost -- how does this all work?
Thanks,
McGee
"Nishant Sivakumar" <ni...@nospam.asianetindia.com> wrote in message
news:uQ9#8ed7CH...@TK2MSFTNGP11.phx.gbl...