home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / DLLDB.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  3.9 KB  |  144 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.  
  13. #ifdef AFX_INIT_SEG
  14. #pragma code_seg(AFX_INIT_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Initialization of MFC extension DLL
  24.  
  25. static AFX_EXTENSION_MODULE extensionDLL;
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Library initialization and cleanup
  29.  
  30. extern "C" BOOL WINAPI RawDllMain(HINSTANCE, DWORD dwReason, LPVOID);
  31. extern "C" BOOL (WINAPI* _pRawDllMain)(HINSTANCE, DWORD, LPVOID) = &RawDllMain;
  32.  
  33. #ifdef _DEBUG
  34. #ifndef _UNICODE
  35. #define MFC42_DLL   "MFC42D.DLL"
  36. #define MFCO42_DLL  "MFCO42D.DLL"
  37. #else
  38. #define MFC42_DLL   "MFC42UD.DLL"
  39. #define MFCO42_DLL  "MFCO42UD.DLL"
  40. #endif
  41. #else
  42. #ifndef _UNICODE
  43. #define MFC42_DLL   "MFC42.DLL"
  44. #define MFCO42_DLL  "MFCO42.DLL"
  45. #else
  46. #define MFC42_DLL   "MFC42U.DLL"
  47. #define MFCO42_DLL  "MFCO42U.DLL"
  48. #endif
  49. #endif
  50.  
  51. extern "C"
  52. BOOL WINAPI RawDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
  53. {
  54.     UNUSED_ALWAYS(hInstance);
  55.     if (dwReason == DLL_PROCESS_ATTACH)
  56.     {
  57. #ifndef _MAC
  58.         // Prevent the MFC DLLs from being unloaded prematurely
  59.         LoadLibraryA(MFC42_DLL);
  60.         LoadLibraryA(MFCO42_DLL);
  61. #endif
  62.  
  63.         // make sure we have enough memory to attempt to start (8kb)
  64.         void* pMinHeap = LocalAlloc(NONZEROLPTR, 0x2000);
  65.         if (pMinHeap == NULL)
  66.             return FALSE;   // fail if memory alloc fails
  67.         LocalFree(pMinHeap);
  68.  
  69.         // save critical data pointers before running the constructors
  70.         AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  71.         pModuleState->m_pClassInit = pModuleState->m_classList;
  72.         pModuleState->m_pFactoryInit = pModuleState->m_factoryList;
  73.         pModuleState->m_classList.m_pHead = NULL;
  74.         pModuleState->m_factoryList.m_pHead = NULL;
  75.     }
  76.     else if (dwReason == DLL_PROCESS_DETACH)
  77.     {
  78. #ifndef _MAC
  79.         // Now it's OK for the MFC DLLs to be unloaded (see LoadLibrary above)
  80.         FreeLibrary(GetModuleHandleA(MFCO42_DLL));
  81.         FreeLibrary(GetModuleHandleA(MFC42_DLL));
  82. #endif
  83.     }
  84.     return TRUE;    // ok
  85. }
  86.  
  87. extern "C"
  88. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  89. {
  90.     if (dwReason == DLL_PROCESS_ATTACH)
  91.     {
  92.         // shared initialization
  93.         VERIFY(AfxInitExtensionModule(extensionDLL, hInstance));
  94.  
  95.         // wire up this DLL into the resource chain
  96.         CDynLinkLibrary* pDLL = new CDynLinkLibrary(extensionDLL, TRUE);
  97.         ASSERT(pDLL != NULL);
  98.     }
  99.     else if (dwReason == DLL_PROCESS_DETACH)
  100.     {
  101.         AfxTermExtensionModule(extensionDLL);
  102.     }
  103.     else if (dwReason == DLL_THREAD_DETACH)
  104.     {
  105.         AfxTermThread(hInstance);
  106.     }
  107.     return TRUE;    // ok
  108. }
  109.  
  110. ////////////////////////////////////////////////////////////////////////////
  111. // Special initialization entry point for controls
  112.  
  113. void AFXAPI AfxDbInitModule()
  114. {
  115.     ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
  116.  
  117.     CDynLinkLibrary* pDLL = new CDynLinkLibrary(extensionDLL, TRUE);
  118.     ASSERT(pDLL != NULL);
  119. }
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // Special code to wire up vector deleting destructors
  123.  
  124. #ifdef AFX_VDEL_SEG
  125. #pragma code_seg(AFX_VDEL_SEG)
  126. #endif
  127. static void _AfxForceVectorDelete()
  128. {
  129.     ASSERT(FALSE);  // never called
  130.  
  131.     new CDatabase[2];
  132.     new CLongBinary[2];
  133.  
  134. #ifndef _AFX_NO_DAO_SUPPORT
  135.     new CDaoWorkspace[2];
  136.     new CDaoException[2];
  137.     new CDaoDatabase[2];
  138.     new CDaoRecordset[2];
  139. #endif
  140. }
  141. void (*_afxForceVectorDelete_mfcd)() = &_AfxForceVectorDelete;
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144.