Our application mixes native and managed code, with a bit of MFC thrown in.
After switching to VS2015, we started getting an ASSERT being hit in _AfxActivationWndProc:
LRESULT CALLBACK
_AfxActivationWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
WNDPROC oldWndProc = (WNDPROC)::GetProp(hWnd, _afxOldWndProc);
ASSERT(oldWndProc != NULL);
We tracked the problem down to AFX_MODULE_STATE's m_bDLL being false, which resulting in AfxUnhookWindowCreate() not unhooking _AfxCbtFilterHook, which resulted in the AfxWndProc being registered on windows it should not have been. Due to some poor
coding on our side, this resulted in the AfxWndProc being called on non-CWnd windows.
We then finally tracked down the cause of AFX_MODULE_STATE's m_bDLL being false. When mfcm140ud.dll is loaded, the following is run (from src\mfc\appmodul.cpp):
char _afxInitAppState = (char)(AfxInitialize(FALSE, _MFC_VER));
Pruned down, the call stack is:
mfcm140ud.dll!`dynamic initializer for '_afxInitAppState''() Line 67 C++
ucrtbased.dll!000007fede848efd()
mfcm140ud.dll!dllmain_crt_process_attach(HINSTANCE__ * const instance=0x000007fee0e10000, void * const reserved=0x0000000000000000)
mfcm140ud.dll!dllmain_crt_dispatch(HINSTANCE__ * const instance=0x000007fee0e10000, const unsigned long reason=0x00000001, void * const reserved=0x0000000000000000)
mfcm140ud.dll!dllmain_dispatch(HINSTANCE__ * const instance=0x000007fee0e10000, const unsigned long reason=0x00000001, void * const reserved=0x0000000000000000)
mfcm140ud.dll!_DllMainCRTStartup(HINSTANCE__ * const instance=0x000007fee0e10000, const unsigned long reason=0x00000001, void * const reserved=0x0000000000000000)
mscoreei.dll!_CorDllMain()
mscoree.dll!ShellShim__CorDllMain()
..
clr.dll!CLRLoadLibraryExWorker()
...
clr.dll!AppDomain::LoadDomainAssemblyInternal()
..
clr.dll!AssemblyNative::Load()
...
clr.dll!UMThunkStub()
AfxInitialize ended up working on _afxBaseModuleState's AFX_MODULE_STATE instance.
All of the above was not happening in vc11. Looking at the code it seems it should have, but 'char _afxInitAppState =' isn't hit when mfcm140ud.dll is loaded.
I had seen another post about a similar problem with the ASSERT (which I can no longer find), which had talked about using a hack fix of saying:
AfxGetModuleState()->m_bDLL = true;
What is also needed in some cases is:
AfxGetAppModuleState()->m_bDLL = true;
So, anyhow, this is sort of inbetween a 'why is this now happening in vc14) and a 'lesson's learned'....
Larry