A regular DLL built with _AFXDLL and _USRDLL now gets its DllMain from
libmfcs.a (dllmodul.cpp), which gives it a module state of its own:
its CWinApp, instance and resource handles, window classes, handle
maps, OLE factories and object count. AfxGetModuleState returns the
current thread's module state, which AFX_MANAGE_STATE (AFX_MAINTAIN_STATE)
switches; AfxGetStaticModuleState gives the DLL's.
The DLL's set-up runs before its own constructors, so theApp and its
factories are made in its state. Its windows get a window procedure of
the DLL's, which switches to the DLL's state, and every CCmdTarget
remembers the module it was made in (m_pModuleState), which
METHOD_PROLOGUE switches to for COM calls. Threads a DLL starts run in
its state. Each module has its own handle maps on each thread, so the
container's CWnd for a control and the control's own object do not
collide.
dlltest runs against mfc.dll too (SHARED_TESTS), with a check that the
DLL's dialog handles its messages in the DLL's state.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRUqfQ3sTcDCMdNCGGs
The library gives a DLL its DllMain (afx.h makes each module's DllMain
call _AfxDllMain, since the C runtime's empty one would otherwise win),
which starts the DLL's CWinApp with the DLL's instance and resources
and ends it on unload. A DLL's AfxOleUnlockApp no longer closes the
program, the window classes a DLL registers go when it unloads, and
the socket window class uses the module's own instance.
dlltest registers a control in a real DLL through DllRegisterServer,
hosts it through COM, shows a dialog from the DLL's resources and
checks the unload through DllCanUnloadNow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRUqfQ3sTcDCMdNCGGs