Commit Graph
2 Commits
Author SHA1 Message Date
Claude b92a664a45 Let a regular DLL share mfc.dll with its own module state
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
2026-11-11 13:24:33 +00:00
Claude e106adb66e Support MFC regular DLLs, such as control .ocx files
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
2026-11-07 11:35:58 +00:00