dllnet.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #else
  30. #define MFC42_DLL "MFC42D.DLL"
  31. #endif // __BORLANDC__
  32. #else
  33. #define MFC42_DLL "MFC42UD.DLL"
  34. #endif
  35. #else
  36. #ifndef _UNICODE
  37. #ifdef __BORLANDC__
  38. #define MFC42_DLL "BFC42.DLL"
  39. #else
  40. #define MFC42_DLL "MFC42.DLL"
  41. #endif // __BORLANDC__
  42. #else
  43. #define MFC42_DLL "MFC42U.DLL"
  44. #endif
  45. #endif
  46. extern "C"
  47. BOOL WINAPI RawDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
  48. {
  49. UNUSED_ALWAYS(hInstance);
  50. if (dwReason == DLL_PROCESS_ATTACH)
  51. {
  52. // Prevent the MFC DLL from being unloaded prematurely
  53. LoadLibraryA(MFC42_DLL);
  54. // make sure we have enough memory to attempt to start (8kb)
  55. void* pMinHeap = LocalAlloc(NONZEROLPTR, 0x2000);
  56. if (pMinHeap == NULL)
  57. return FALSE; // fail if memory alloc fails
  58. LocalFree(pMinHeap);
  59. // save critical data pointers before running the constructors
  60. AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  61. pModuleState->m_pClassInit = pModuleState->m_classList;
  62. pModuleState->m_pFactoryInit = pModuleState->m_factoryList;
  63. pModuleState->m_classList.m_pHead = NULL;
  64. pModuleState->m_factoryList.m_pHead = NULL;
  65. }
  66. else if (dwReason == DLL_PROCESS_DETACH)
  67. {
  68. // Now it's OK for the MFC DLL to be unloaded (see LoadLibrary above)
  69. FreeLibrary(GetModuleHandleA(MFC42_DLL));
  70. }
  71. return TRUE; // ok
  72. }
  73. extern "C"
  74. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  75. {
  76. if (dwReason == DLL_PROCESS_ATTACH)
  77. {
  78. // shared initialization
  79. VERIFY(AfxInitExtensionModule(extensionDLL, hInstance));
  80. // wire up this DLL into the resource chain
  81. CDynLinkLibrary* pDLL = new CDynLinkLibrary(extensionDLL, TRUE);
  82. ASSERT(pDLL != NULL);
  83. }
  84. else if (dwReason == DLL_PROCESS_DETACH)
  85. {
  86. AfxTermExtensionModule(extensionDLL);
  87. }
  88. else if (dwReason == DLL_THREAD_DETACH)
  89. {
  90. AfxTermThread(hInstance);
  91. }
  92. return TRUE; // ok
  93. }
  94. ////////////////////////////////////////////////////////////////////////////
  95. // Special initialization entry point for controls
  96. void AFXAPI AfxNetInitModule()
  97. {
  98. ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
  99. CDynLinkLibrary* pDLL = new CDynLinkLibrary(extensionDLL, TRUE);
  100. ASSERT(pDLL != NULL);
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. // Special code to wire up vector deleting destructors
  104. #ifdef AFX_VDEL_SEG
  105. #pragma code_seg(AFX_VDEL_SEG)
  106. #endif
  107. static void _AfxForceVectorDelete()
  108. {
  109. ASSERT(FALSE); // never called
  110. new CAsyncSocket[2];
  111. new CSocket[2];
  112. }
  113. void (*_afxForceVectorDelete_mfcn)() = &_AfxForceVectorDelete;
  114. /////////////////////////////////////////////////////////////////////////////