dlldb.cpp 4.1 KB

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