home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / dllnet.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  4KB  |  128 lines

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