home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / DLLINIT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-03  |  20.3 KB  |  777 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #include <stdarg.h>
  13.  
  14. #ifdef AFX_INIT_SEG
  15. #pragma code_seg(AFX_INIT_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. #ifndef _AFXDLL
  24.     #error file must be compiled with _AFXDLL
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // _AFXDLL support
  29.  
  30. static AFX_EXTENSION_MODULE coreDLL;
  31. #ifdef _AFX_OLE_IMPL
  32. AFX_MODULE_STATE* AFXAPI _AfxGetOleModuleState();
  33. #endif
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CDynLinkLibrary class
  37.  
  38. IMPLEMENT_DYNAMIC(CDynLinkLibrary, CCmdTarget)
  39.  
  40. // Constructor - will wire into the current application's list
  41. CDynLinkLibrary::CDynLinkLibrary(AFX_EXTENSION_MODULE& state, BOOL bSystem)
  42. {
  43. #ifndef _AFX_NO_OLE_SUPPORT
  44.     m_factoryList.Construct(offsetof(COleObjectFactory, m_pNextFactory));
  45. #endif
  46.     m_classList.Construct(offsetof(CRuntimeClass, m_pNextClass));
  47.  
  48.     // copy info from AFX_EXTENSION_MODULE struct
  49.     ASSERT(state.hModule != NULL);
  50.     m_hModule = state.hModule;
  51.     m_hResource = state.hResource;
  52.     m_classList.m_pHead = state.pFirstSharedClass;
  53. #ifndef _AFX_NO_OLE_SUPPORT
  54.     m_factoryList.m_pHead = state.pFirstSharedFactory;
  55. #endif
  56.     m_bSystem = bSystem;
  57.  
  58.     // insert at the head of the list (extensions will go in front of core DLL)
  59.     DEBUG_ONLY(m_pNextDLL = NULL);
  60.     AfxLockGlobals(CRIT_DYNLINKLIST);
  61.     m_pModuleState->m_libraryList.AddHead(this);
  62.     AfxUnlockGlobals(CRIT_DYNLINKLIST);
  63. }
  64.  
  65. #ifdef AFX_TERM_SEG
  66. #pragma code_seg(AFX_TERM_SEG)
  67. #endif
  68.  
  69. CDynLinkLibrary::~CDynLinkLibrary()
  70. {
  71.     // remove this frame window from the list of frame windows
  72.     AfxLockGlobals(CRIT_DYNLINKLIST);
  73.     m_pModuleState->m_libraryList.Remove(this);
  74.     AfxUnlockGlobals(CRIT_DYNLINKLIST);
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CDynLinkLibrary diagnostics
  79.  
  80. #ifdef _DEBUG
  81. void CDynLinkLibrary::AssertValid() const
  82. {
  83.     ASSERT(m_hModule != NULL);
  84. }
  85.  
  86. void CDynLinkLibrary::Dump(CDumpContext& dc) const
  87. {
  88.     CCmdTarget::Dump(dc);
  89.  
  90.     dc << "m_hModule = " << (UINT)m_hModule;
  91.     dc << "\nm_hResource = " << (UINT)m_hResource;
  92.  
  93.     if (m_hModule != NULL)
  94.     {
  95.         TCHAR szName[_MAX_PATH];
  96.         GetModuleFileName(m_hModule, szName, _countof(szName));
  97.         dc << "\nmodule name = " << szName;
  98.     }
  99.     else
  100.         dc << "\nmodule name is unknown";
  101.  
  102.     dc << "\n";
  103. }
  104. #endif //_DEBUG
  105.  
  106. #ifdef AFX_INIT_SEG
  107. #pragma code_seg(AFX_INIT_SEG)
  108. #endif
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // special initialization and helper functions
  112.  
  113. // This is called in an extension DLL's DllMain
  114. //  It makes a copy of the DLL's HMODULE, as well as a copy of the
  115. //  runtime class objects that have been initialized by this
  116. //  extension DLL as part of normal static object construction
  117. //  executed before DllMain is entered.
  118.  
  119. BOOL AFXAPI AfxInitExtensionModule(AFX_EXTENSION_MODULE& state, HMODULE hModule)
  120. {
  121.     // only initialize once
  122.     if (state.bInitialized)
  123.     {
  124.         AfxInitLocalData(hModule);
  125.         return TRUE;
  126.     }
  127.     state.bInitialized = TRUE;
  128.  
  129.     // save the current HMODULE information for resource loading
  130.     ASSERT(hModule != NULL);
  131.     state.hModule = hModule;
  132.     state.hResource = hModule;
  133.  
  134.     // save the start of the runtime class list
  135.     AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  136.     state.pFirstSharedClass = pModuleState->m_classList.GetHead();
  137.     pModuleState->m_classList.m_pHead = pModuleState->m_pClassInit;
  138.  
  139. #ifndef _AFX_NO_OLE_SUPPORT
  140.     // save the start of the class factory list
  141.     state.pFirstSharedFactory = pModuleState->m_factoryList.GetHead();
  142.     pModuleState->m_factoryList.m_pHead = pModuleState->m_pFactoryInit;
  143. #endif
  144.  
  145.     return TRUE;
  146. }
  147.  
  148. #ifdef AFX_TERM_SEG
  149. #pragma code_seg(AFX_TERM_SEG)
  150. #endif
  151.  
  152. void AFXAPI AfxTermExtensionModule(AFX_EXTENSION_MODULE& state, BOOL bAll)
  153. {
  154.     // make sure initialized
  155.     if (!state.bInitialized)
  156.         return;
  157.  
  158.     // search for CDynLinkLibrary matching state.hModule and delete it
  159.     ASSERT(state.hModule != NULL);
  160.     AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  161.     AfxLockGlobals(CRIT_DYNLINKLIST);
  162.     for (CDynLinkLibrary* pDLL = pModuleState->m_libraryList; pDLL != NULL; )
  163.     {
  164.         CDynLinkLibrary* pNextDLL = pDLL->m_pNextDLL;
  165.         if (bAll || pDLL->m_hModule == state.hModule)
  166.             delete pDLL;    // will unwire itself
  167.         pDLL = pNextDLL;
  168.     }
  169.     AfxUnlockGlobals(CRIT_DYNLINKLIST);
  170.  
  171.     // delete any local storage attached to this module
  172.     AfxTermLocalData(state.hModule, TRUE);
  173.  
  174.     // remove any entries from the CWnd message map cache
  175.     AfxResetMsgCache();
  176. }
  177.  
  178. /////////////////////////////////////////////////////////////////////////////
  179. // special LoadLibrary and FreeLibrary for loading MFC extension DLLs
  180.  
  181. HINSTANCE AFXAPI AfxLoadLibrary(LPCTSTR lpszModuleName)
  182. {
  183.     ASSERT(lpszModuleName != NULL);
  184.     AfxLockGlobals(CRIT_LOCKSHARED);
  185.     HINSTANCE hInstLib = LoadLibrary(lpszModuleName);
  186.     AfxUnlockGlobals(CRIT_LOCKSHARED);
  187.     return hInstLib;
  188. }
  189.  
  190. BOOL AFXAPI AfxFreeLibrary(HINSTANCE hInstLib)
  191. {
  192.     AfxLockGlobals(CRIT_LOCKSHARED);
  193.     BOOL bResult = FreeLibrary(hInstLib);
  194.     AfxUnlockGlobals(CRIT_LOCKSHARED);
  195.     return bResult;
  196. }
  197.  
  198. /////////////////////////////////////////////////////////////////////////////
  199. // Resource helpers
  200.  
  201. #ifdef AFX_CORE2_SEG
  202. #pragma code_seg(AFX_CORE2_SEG)
  203. #endif
  204.  
  205. HINSTANCE AFXAPI AfxFindResourceHandle(LPCTSTR lpszName, LPCTSTR lpszType)
  206. {
  207.     ASSERT(lpszName != NULL);
  208.     ASSERT(lpszType != NULL);
  209.  
  210.     HINSTANCE hInst;
  211.  
  212.     // first check the main module state
  213.     AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  214.     if (!pModuleState->m_bSystem)
  215.     {
  216.         hInst = AfxGetResourceHandle();
  217.         if (::FindResource(hInst, lpszName, lpszType) != NULL)
  218.             return hInst;
  219.     }
  220.  
  221.     // check for non-system DLLs in proper order
  222.     AfxLockGlobals(CRIT_DYNLINKLIST);
  223.     for (CDynLinkLibrary* pDLL = pModuleState->m_libraryList; pDLL != NULL;
  224.         pDLL = pDLL->m_pNextDLL)
  225.     {
  226.         if (!pDLL->m_bSystem && pDLL->m_hResource != NULL &&
  227.             ::FindResource(pDLL->m_hResource, lpszName, lpszType) != NULL)
  228.         {
  229.             // found it in a DLL
  230.             AfxUnlockGlobals(CRIT_DYNLINKLIST);
  231.             return pDLL->m_hResource;
  232.         }
  233.     }
  234.     AfxUnlockGlobals(CRIT_DYNLINKLIST);
  235.  
  236.     // check language specific resource next
  237.     hInst = pModuleState->m_appLangDLL;
  238.     if (hInst != NULL && ::FindResource(hInst, lpszName, lpszType) != NULL)
  239.         return hInst;
  240.  
  241.     // check the main system module state
  242.     if (pModuleState->m_bSystem)
  243.     {
  244.         hInst = AfxGetResourceHandle();
  245.         if (::FindResource(hInst, lpszName, lpszType) != NULL)
  246.             return hInst;
  247.     }
  248.  
  249.     // check for system DLLs in proper order
  250.     AfxLockGlobals(CRIT_DYNLINKLIST);
  251.     for (pDLL = pModuleState->m_libraryList; pDLL != NULL; pDLL = pDLL->m_pNextDLL)
  252.     {
  253.         if (pDLL->m_bSystem && pDLL->m_hResource != NULL &&
  254.             ::FindResource(pDLL->m_hResource, lpszName, lpszType) != NULL)
  255.         {
  256.             // found it in a DLL
  257.             AfxUnlockGlobals(CRIT_DYNLINKLIST);
  258.             return pDLL->m_hResource;
  259.         }
  260.     }
  261.     AfxUnlockGlobals(CRIT_DYNLINKLIST);
  262.  
  263.     // if failed to find resource, return application resource
  264.     return AfxGetResourceHandle();
  265. }
  266.  
  267. // AfxLoadString must not only check for the appropriate string segment
  268. //   in the resource file, but also that the string is non-zero
  269. int AFXAPI AfxLoadString(UINT nID, LPTSTR lpszBuf, UINT nMaxBuf)
  270. {
  271.     ASSERT(AfxIsValidAddress(lpszBuf, nMaxBuf*sizeof(TCHAR)));
  272.  
  273.     LPCTSTR lpszName = MAKEINTRESOURCE((nID>>4)+1);
  274.     HINSTANCE hInst;
  275.     int nLen;
  276.  
  277.     // first check the main module state
  278.     AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  279.     if (!pModuleState->m_bSystem)
  280.     {
  281.         hInst = AfxGetResourceHandle();
  282.         if (::FindResource(hInst, lpszName, RT_STRING) != NULL &&
  283.             (nLen = ::LoadString(hInst, nID, lpszBuf, nMaxBuf)) != 0)
  284.         {
  285.             // found a non-zero string in app
  286.             return nLen;
  287.         }
  288.     }
  289.  
  290.     // check non-system DLLs in proper order
  291.     AfxLockGlobals(CRIT_DYNLINKLIST);
  292.     for (CDynLinkLibrary* pDLL = pModuleState->m_libraryList; pDLL != NULL;
  293.         pDLL = pDLL->m_pNextDLL)
  294.     {
  295.         if (!pDLL->m_bSystem && (hInst = pDLL->m_hResource) != NULL &&
  296.           ::FindResource(hInst, lpszName, RT_STRING) != NULL &&
  297.           (nLen = ::LoadString(hInst, nID, lpszBuf, nMaxBuf)) != 0)
  298.         {
  299.             AfxUnlockGlobals(CRIT_DYNLINKLIST);
  300.             return nLen;
  301.         }
  302.     }
  303.     AfxUnlockGlobals(CRIT_DYNLINKLIST);
  304.  
  305.     // check language specific DLL next
  306.     hInst = pModuleState->m_appLangDLL;
  307.     if (hInst != NULL && ::FindResource(hInst, lpszName, RT_STRING) != NULL &&
  308.         (nLen = ::LoadString(hInst, nID, lpszBuf, nMaxBuf)) != 0)
  309.     {
  310.         // found a non-zero string in language DLL
  311.         return nLen;
  312.     }
  313.  
  314.     // check the system module state
  315.     if (pModuleState->m_bSystem)
  316.     {
  317.         hInst = AfxGetResourceHandle();
  318.         if (::FindResource(hInst, lpszName, RT_STRING) != NULL &&
  319.             (nLen = ::LoadString(hInst, nID, lpszBuf, nMaxBuf)) != 0)
  320.         {
  321.             // found a non-zero string in app
  322.             return nLen;
  323.         }
  324.     }
  325.  
  326.     // check system DLLs in proper order
  327.     AfxLockGlobals(CRIT_DYNLINKLIST);
  328.     for (pDLL = pModuleState->m_libraryList; pDLL != NULL; pDLL = pDLL->m_pNextDLL)
  329.     {
  330.         if (pDLL->m_bSystem && (hInst = pDLL->m_hResource) != NULL &&
  331.           ::FindResource(hInst, lpszName, RT_STRING) != NULL &&
  332.           (nLen = ::LoadString(hInst, nID, lpszBuf, nMaxBuf)) != 0)
  333.         {
  334.             AfxUnlockGlobals(CRIT_DYNLINKLIST);
  335.             return nLen;
  336.         }
  337.     }
  338.     AfxUnlockGlobals(CRIT_DYNLINKLIST);
  339.  
  340.     // did not find it
  341.     lpszBuf[0] = '\0';
  342.     return 0;
  343. }
  344.  
  345. /////////////////////////////////////////////////////////////////////////////
  346. // Library initialization and cleanup
  347.  
  348. #ifdef _DEBUG
  349. #define MSVCRT_DLL "MSVCRTD.DLL"
  350. #else
  351. #define MSVCRT_DLL "MSVCRT.DLL"
  352. #endif
  353.  
  354. #ifdef AFX_INIT_SEG
  355. #pragma code_seg(AFX_INIT_SEG)
  356. #endif
  357.  
  358. extern "C" BOOL WINAPI RawDllMain(HINSTANCE, DWORD dwReason, LPVOID);
  359. extern "C" BOOL (WINAPI* _pRawDllMain)(HINSTANCE, DWORD, LPVOID) = &RawDllMain;
  360.  
  361. extern "C"
  362. BOOL WINAPI RawDllMain(HINSTANCE /*hInstance*/, DWORD dwReason, LPVOID)
  363. {
  364.     if (dwReason == DLL_PROCESS_ATTACH)
  365.     {
  366. #ifndef _MAC
  367.         // Prevent the C runtime DLL from being unloaded prematurely
  368.         LoadLibraryA(MSVCRT_DLL);
  369. #endif
  370.  
  371. #ifdef _UNICODE
  372.         // give error message and exit if running Unicode on non-Unicode system
  373.         if (GetVersion() & 0x80000000)
  374.         {
  375.             // Note: this message is for programmers who can read english
  376.             ::MessageBoxA(NULL,
  377.                 "This application or DLL can not be loaded "
  378.                 "on Windows 95 or on Windows 3.1.  It takes advantage "
  379.                 "of Unicode features only available on Windows NT.",
  380.                 "MFC Runtime Module", MB_ICONSTOP|MB_OK);
  381.             return FALSE; // and fail
  382.         }
  383. #endif
  384.  
  385.         SetErrorMode(SetErrorMode(0) |
  386.             SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
  387.  
  388.         // add a reference to thread local storage data
  389.         AfxTlsAddRef();
  390.  
  391.         // make sure we have enough memory to attempt to start (8kb)
  392.         void* pMinHeap = LocalAlloc(NONZEROLPTR, 0x2000);
  393.         if (pMinHeap == NULL)
  394.             return FALSE;   // fail if memory alloc fails
  395.         LocalFree(pMinHeap);
  396.  
  397.         // cause early initialization of _afxCriticalSection
  398.         if (!AfxCriticalInit())
  399.             return FALSE;
  400.  
  401. #ifdef _AFX_OLE_IMPL
  402.         // set module state before initialization
  403.         AFX_MODULE_STATE* pModuleState = _AfxGetOleModuleState();
  404.         _AFX_THREAD_STATE* pState = AfxGetThreadState();
  405.         pState->m_pPrevModuleState = AfxSetModuleState(pModuleState);
  406. #endif
  407.     }
  408.     else if (dwReason == DLL_PROCESS_DETACH)
  409.     {
  410. #ifdef _AFX_OLE_IMPL
  411.         _AFX_THREAD_STATE* pThreadState = _afxThreadState.GetDataNA();
  412.         if (pThreadState != NULL)
  413.         {
  414.             // restore previously-saved module state
  415.             VERIFY(AfxSetModuleState(pThreadState->m_pPrevModuleState) ==
  416.                 _AfxGetOleModuleState());
  417.             DEBUG_ONLY(pThreadState->m_pPrevModuleState = NULL);
  418.         }
  419. #endif
  420.  
  421.         // free up the _afxCriticalSection
  422.         AfxCriticalTerm();
  423.  
  424. #ifndef _MAC
  425.         // Now it's OK for C runtime DLL to be unloaded (see LoadLibrary above)
  426.         FreeLibrary(GetModuleHandleA(MSVCRT_DLL));
  427. #endif
  428.  
  429.         // remove reference from thread local data
  430.         AfxTlsRelease();
  431.     }
  432.  
  433.     return TRUE;    // ok
  434. }
  435.  
  436. extern "C"
  437. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
  438. {
  439.     if (dwReason == DLL_PROCESS_ATTACH)
  440.     {
  441. #ifdef _AFX_OLE_IMPL
  442.         BOOL bRegister = !coreDLL.bInitialized;
  443.  
  444.         // shared initialization
  445.         AFX_MODULE_STATE* pModuleState = _AfxGetOleModuleState();
  446.         pModuleState->m_hCurrentInstanceHandle = hInstance;
  447.         pModuleState->m_hCurrentResourceHandle = hInstance;
  448.         pModuleState->m_pClassInit = pModuleState->m_classList.GetHead();
  449.         pModuleState->m_pFactoryInit = pModuleState->m_factoryList.GetHead();
  450. #endif
  451.  
  452.         // initialize this DLL's extension module
  453.         VERIFY(AfxInitExtensionModule(coreDLL, hInstance));
  454.  
  455. #ifdef _AFX_OLE_IMPL
  456.         AfxWinInit(hInstance, NULL, &afxChNil, 0);
  457.  
  458.         // Register class factories in context of private module state
  459.         if (bRegister)
  460.             COleObjectFactory::RegisterAll();
  461. #endif
  462.  
  463. #ifdef _AFX_OLE_IMPL
  464.         // restore previously-saved module state
  465.         VERIFY(AfxSetModuleState(AfxGetThreadState()->m_pPrevModuleState) ==
  466.             _AfxGetOleModuleState());
  467.         DEBUG_ONLY(AfxGetThreadState()->m_pPrevModuleState = NULL);
  468. #endif
  469.  
  470.         // wire up this DLL into the resource chain
  471.         CDynLinkLibrary* pDLL = new CDynLinkLibrary(coreDLL, TRUE);
  472.         ASSERT(pDLL != NULL);
  473.         pDLL->m_factoryList.m_pHead = NULL;
  474.  
  475.         // load language specific DLL
  476.         // the DLL must be in the "system directory"
  477.         static const char szPrefix[] = "\\MFC42";
  478.         static const char szLOC[] = "LOC";
  479.         static const char szDLL[] = ".DLL";
  480.         char szLangDLL[_MAX_PATH+14]; // Note: 8.3 name
  481.         GetSystemDirectoryA(szLangDLL, _countof(szLangDLL));
  482.         lstrcatA(szLangDLL, szPrefix);
  483.  
  484.         // try MFC42LOC.DLL
  485.         lstrcatA(szLangDLL, szLOC);
  486.         lstrcatA(szLangDLL, szDLL);
  487.         HINSTANCE hLangDLL = LoadLibraryA(szLangDLL);
  488.         AFX_MODULE_STATE* pState = AfxGetModuleState();
  489.         pState->m_appLangDLL = hLangDLL;
  490.  
  491. #ifdef _AFX_OLE_IMPL
  492.         // copy it to the private OLE state too
  493.         pModuleState->m_appLangDLL = hLangDLL;
  494. #endif
  495.     }
  496.     else if (dwReason == DLL_PROCESS_DETACH)
  497.     {
  498.         // free language specific DLL
  499.         AFX_MODULE_STATE* pState = AfxGetModuleState();
  500.         if (pState->m_appLangDLL != NULL)
  501.         {
  502.             ::FreeLibrary(pState->m_appLangDLL);
  503.             pState->m_appLangDLL = NULL;
  504.         }
  505.  
  506.         // free the DLL info blocks
  507.         CDynLinkLibrary* pDLL;
  508.         while ((pDLL = pState->m_libraryList) != NULL)
  509.             delete pDLL;
  510.         ASSERT(pState->m_libraryList.IsEmpty());
  511.  
  512.         // cleanup module state for this process
  513.         AfxTermExtensionModule(coreDLL);
  514.  
  515. #ifdef _AFX_OLE_IMPL
  516.         // set module state for cleanup
  517.         ASSERT(AfxGetThreadState()->m_pPrevModuleState == NULL);
  518.         AfxGetThreadState()->m_pPrevModuleState =
  519.             AfxSetModuleState(_AfxGetOleModuleState());
  520. #endif
  521.  
  522.         // cleanup module state in OLE private module state
  523.         AfxTermExtensionModule(coreDLL, TRUE);
  524.  
  525.         // free any local data for this process/thread
  526.         AfxTermLocalData(NULL, TRUE);
  527.     }
  528.     else if (dwReason == DLL_THREAD_DETACH)
  529.     {
  530.         AfxTermThread();
  531.     }
  532.  
  533.     return TRUE;    // ok
  534. }
  535.  
  536. ////////////////////////////////////////////////////////////////////////////
  537. // Special initialization entry point for controls
  538.  
  539. void AFXAPI AfxCoreInitModule()
  540. {
  541.     ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
  542.  
  543.     // construct new dynlink library in this context for core resources
  544.     CDynLinkLibrary* pDLL = new CDynLinkLibrary(coreDLL, TRUE);
  545.     ASSERT(pDLL != NULL);
  546.     pDLL->m_factoryList.m_pHead = NULL;
  547.  
  548.     // borrow resources from language specific DLL if loaded
  549.     AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  550.     AFX_MODULE_STATE* pAppState = AfxGetAppModuleState();
  551.     if (pModuleState->m_appLangDLL == NULL)
  552.         pModuleState->m_appLangDLL = pAppState->m_appLangDLL;
  553. }
  554.  
  555. ////////////////////////////////////////////////////////////////////////////
  556. // COM entry points
  557.  
  558. #ifdef _AFX_OLE_IMPL
  559. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  560. {
  561.     AFX_MANAGE_STATE(_AfxGetOleModuleState());
  562.     return AfxDllGetClassObject(rclsid, riid, ppv);
  563. }
  564.  
  565. STDAPI DllCanUnloadNow(void)
  566. {
  567.     AFX_MANAGE_STATE(_AfxGetOleModuleState());
  568.     return AfxDllCanUnloadNow();
  569. }
  570.  
  571. ////////////////////////////////////////////////////////////////////////////
  572. // Server registration
  573.  
  574. STDAPI DllRegisterServer(void)
  575. {
  576.     AFX_MANAGE_STATE(_AfxGetOleModuleState());
  577.  
  578.     if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
  579.         return SELFREG_E_CLASS;
  580.  
  581.     return S_OK;
  582. }
  583.  
  584. STDAPI DllUnregisterServer(void)
  585. {
  586.     AFX_MANAGE_STATE(_AfxGetOleModuleState());
  587.  
  588.     if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
  589.         return SELFREG_E_CLASS;
  590.  
  591.     return S_OK;
  592. }
  593.  
  594. // This CWinApp is required so this module state has a CWinApp object!
  595. CWinApp _afxOleWinApp;
  596.  
  597. /////////////////////////////////////////////////////////////////////////////
  598. // static-linked version of AfxWndProc for use by this module
  599.  
  600. #undef AfxWndProc
  601.  
  602. LRESULT CALLBACK
  603. AfxWndProcDllOle(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
  604. {
  605.     AFX_MANAGE_STATE(_AfxGetOleModuleState());
  606.     return AfxWndProc(hWnd, nMsg, wParam, lParam);
  607. }
  608.  
  609. /////////////////////////////////////////////////////////////////////////////
  610.  
  611. // force initialization early
  612. #pragma warning(disable: 4074)
  613. #pragma init_seg(lib)
  614.  
  615. static AFX_MODULE_STATE _afxOleModuleState(TRUE, &AfxWndProcDllOle,
  616.     _MFC_VER, TRUE);
  617.  
  618. AFX_MODULE_STATE* AFXAPI _AfxGetOleModuleState()
  619. {
  620.     return &_afxOleModuleState;
  621. }
  622. #endif
  623.  
  624. /////////////////////////////////////////////////////////////////////////////
  625. // Special code to wire up vector deleting destructors
  626.  
  627. #ifdef AFX_VDEL_SEG
  628. #pragma code_seg(AFX_VDEL_SEG)
  629. #endif
  630. static void _AfxForceVectorDelete()
  631. {
  632.     ASSERT(FALSE);  // never called
  633.  
  634.     new CBitmap[2];
  635.     new CBitmapButton[2];
  636.     new CBrush[2];
  637.     new CButton[2];
  638.     new CByteArray[2];
  639.     new CCmdTarget[2];
  640.     new CComboBox[2];
  641.     new CDC[2];
  642.     new CDWordArray[2];
  643.     new CDialog[2];
  644.     new CDialogBar[2];
  645.     new CEdit[2];
  646.     new CFile[2];
  647.     new CFont[2];
  648.     new CFrameWnd[2];
  649.     new CGdiObject[2];
  650.     new CListBox[2];
  651.     new CCheckListBox[2];
  652.     new CMapPtrToPtr[2];
  653.     new CMapPtrToWord[2];
  654.     new CMapStringToOb[2];
  655.     new CMapStringToPtr[2];
  656.     new CMapStringToString[2];
  657.     new CMapWordToOb[2];
  658.     new CMapWordToPtr[2];
  659.     new CMemFile[2];
  660.     new CMenu[2];
  661.     new CMetaFileDC[2];
  662.     new CObArray[2];
  663.     new CObList[2];
  664.     new CPalette[2];
  665.     new CPen[2];
  666.     new CPtrArray[2];
  667.     new CPtrList[2];
  668.     new CRectTracker[2];
  669.     new CRgn[2];
  670.     new CScrollBar[2];
  671.     new CSharedFile[2];
  672.     new CSplitterWnd[2];
  673.     new CStatic[2];
  674.     new CStatusBar[2];
  675.     new CStdioFile[2];
  676.     new CString[2];
  677.     new CStringArray[2];
  678.     new CStringList[2];
  679.     new CThreadSlotData[2];
  680.     new CTime[2];
  681.     new CTimeSpan[2];
  682.     new CToolBar[2];
  683.     new CUIntArray[2];
  684.     new CWnd[2];
  685.     new CWordArray[2];
  686.  
  687. #ifndef _MAC
  688.     new CFileFind[2];
  689.     new CInternetSession[2];
  690. #endif
  691.  
  692.     new CDragListBox[2];
  693.     new CStatusBarCtrl[2];
  694.     new CListCtrl[2];
  695.     new CTreeCtrl[2];
  696.     new CSpinButtonCtrl[2];
  697.     new CSliderCtrl[2];
  698.     new CProgressCtrl[2];
  699.     new CHeaderCtrl[2];
  700.     new CHotKeyCtrl[2];
  701.     new CToolTipCtrl[2];
  702.     new CTabCtrl[2];
  703.     new CAnimateCtrl[2];
  704.     new CImageList[2];
  705.     new CToolBarCtrl[2];
  706.     new CRichEditCtrl[2];
  707.  
  708.     new CMirrorFile[2];
  709.     new CDockState[2];
  710.  
  711.     new CListView[2];
  712.     new CTreeView[2];
  713.     new CCommandLineInfo[2];
  714.     new CDocManager[2];
  715.  
  716. #ifndef _MAC
  717.     new CPageSetupDialog[2];
  718.  
  719.     new CSemaphore[2];
  720.     new CMutex[2];
  721.     new CEvent[2];
  722.     new CCriticalSection[2];
  723. #endif
  724.  
  725. #ifdef _AFX_OLE_IMPL
  726.     new COleDataSource[2];
  727.     new COleDispatchDriver[2];
  728.     new COleDropSource[2];
  729.     new CMonikerFile[2];
  730. #ifndef _MAC
  731.     new COleResizeBar[2];
  732.     new CAsyncMonikerFile[2];
  733.     new CCachedDataPathProperty[2];
  734.     new CDataPathProperty[2];
  735. #endif
  736.     new COleStreamFile[2];
  737.     new COleTemplateServer[2];
  738.     new COleDataObject[2];
  739.     new COleDropTarget[2];
  740.     new COleIPFrameWnd[2];
  741.  
  742. #ifndef _MAC
  743.     new COleDocIPFrameWnd[2];
  744. #endif
  745.  
  746.     new COleVariant[2];
  747.     new CRichEditView[2];
  748.     new CRichEditCntrItem[2];
  749. #endif
  750.  
  751. #ifdef _AFX_DB_IMPL
  752.     new CDatabase[2];
  753.     new CLongBinary[2];
  754.  
  755.     new CDaoWorkspace[2];
  756.     new CDaoException[2];
  757.     new CDaoDatabase[2];
  758.     new CDaoRecordset[2];
  759. #endif
  760.  
  761. // Net
  762. #ifdef _AFX_NET_IMPL
  763. #ifndef _MAC
  764.     new CAsyncSocket[2];
  765.     new CSocket[2];
  766. #endif
  767. #endif
  768.  
  769. }
  770. void (*_afxForceVectorDelete_mfc)() = &_AfxForceVectorDelete;
  771.  
  772. void _AfxBinaryCompatibleStubFunction()
  773. {
  774. }
  775.  
  776. /////////////////////////////////////////////////////////////////////////////
  777.