home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / DLLNET.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  3.6 KB  |  132 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. #else
  37. #define MFC42_DLL "MFC42UD.DLL"
  38. #endif
  39. #else
  40. #ifndef _UNICODE
  41. #define MFC42_DLL "MFC42.DLL"
  42. #else
  43. #define MFC42_DLL "MFC42U.DLL"
  44. #endif
  45. #endif
  46.  
  47. extern "C"
  48. BOOL WINAPI RawDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
  49. {
  50.     UNUSED_ALWAYS(hInstance);
  51.     if (dwReason == DLL_PROCESS_ATTACH)
  52.     {
  53. #ifndef _MAC
  54.         // Prevent the MFC DLL from being unloaded prematurely
  55.         LoadLibraryA(MFC42_DLL);
  56. #endif
  57.  
  58.         // make sure we have enough memory to attempt to start (8kb)
  59.         void* pMinHeap = LocalAlloc(NONZEROLPTR, 0x2000);
  60.         if (pMinHeap == NULL)
  61.             return FALSE;   // fail if memory alloc fails
  62.         LocalFree(pMinHeap);
  63.  
  64.         // save critical data pointers before running the constructors
  65.         AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  66.         pModuleState->m_pClassInit = pModuleState->m_classList;
  67.         pModuleState->m_pFactoryInit = pModuleState->m_factoryList;
  68.         pModuleState->m_classList.m_pHead = NULL;
  69.         pModuleState->m_factoryList.m_pHead = NULL;
  70.     }
  71.     else if (dwReason == DLL_PROCESS_DETACH)
  72.     {
  73. #ifndef _MAC
  74.         // Now it's OK for the MFC  DLL to be unloaded (see LoadLibrary above)
  75.         FreeLibrary(GetModuleHandleA(MFC42_DLL));
  76. #endif
  77.     }
  78.     return TRUE;    // ok
  79. }
  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.  
  89.         // wire up this DLL into the resource chain
  90.         CDynLinkLibrary* pDLL = new CDynLinkLibrary(extensionDLL, TRUE);
  91.         ASSERT(pDLL != NULL);
  92.     }
  93.     else if (dwReason == DLL_PROCESS_DETACH)
  94.     {
  95.         AfxTermExtensionModule(extensionDLL);
  96.     }
  97.     else if (dwReason == DLL_THREAD_DETACH)
  98.     {
  99.         AfxTermThread(hInstance);
  100.     }
  101.  
  102.     return TRUE;    // ok
  103. }
  104.  
  105. ////////////////////////////////////////////////////////////////////////////
  106. // Special initialization entry point for controls
  107.  
  108. void AFXAPI AfxNetInitModule()
  109. {
  110.     ASSERT(AfxGetModuleState() != AfxGetAppModuleState());
  111.  
  112.     CDynLinkLibrary* pDLL = new CDynLinkLibrary(extensionDLL, TRUE);
  113.     ASSERT(pDLL != NULL);
  114. }
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117. // Special code to wire up vector deleting destructors
  118.  
  119. #ifdef AFX_VDEL_SEG
  120. #pragma code_seg(AFX_VDEL_SEG)
  121. #endif
  122. static void _AfxForceVectorDelete()
  123. {
  124.     ASSERT(FALSE);  // never called
  125.  
  126.     new CAsyncSocket[2];
  127.     new CSocket[2];
  128. }
  129. void (*_afxForceVectorDelete_mfcn)() = &_AfxForceVectorDelete;
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132.