Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
4.7 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: DllMain.cpp
  6. * Content: Defines the entry point for the DLL application.
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/21/99 mjn Created
  12. * 07/13/2000 rmt Added critical sections to protect FPMs
  13. * 07/21/2000 RichGr IA64: Use %p format specifier for 32/64-bit pointers.
  14. * 01/04/2001 rodtoll WinBug #94200 - Remove stray comments
  15. *@@END_MSINTERNAL
  16. *
  17. ***************************************************************************/
  18. #include "dnaddri.h"
  19. // Globals
  20. #ifndef DPNBUILD_LIBINTERFACE
  21. extern LONG g_lAddrObjectCount;
  22. extern IClassFactoryVtbl DP8ACF_Vtbl;
  23. #endif // ! DPNBUILD_LIBINTERFACE
  24. DEBUG_ONLY(BOOL g_fAddrObjectInited = FALSE);
  25. #ifndef DPNBUILD_ONLYONESP
  26. #define WSA_INITED 0x00000001
  27. #endif // ! DPNBUILD_ONLYONESP
  28. #define ADDROBJ_INITED 0x00000002
  29. #define ADDRELEM_INITED 0x00000004
  30. #define STRCACHE_INITED 0x00000008
  31. DWORD g_dwAddrInitFlags = 0;
  32. void DNAddressDeInit();
  33. #undef DPF_MODNAME
  34. #define DPF_MODNAME "DNAddressInit"
  35. BOOL DNAddressInit(HANDLE hModule)
  36. {
  37. #ifndef DPNBUILD_ONLYONESP
  38. WSADATA wsaData;
  39. #endif // ! DPNBUILD_ONLYONESP
  40. #ifdef DPNBUILD_PREALLOCATEDMEMORYMODEL
  41. XDP8STARTUP_PARAMS * pStartupParams;
  42. //
  43. // The instance handle is actually a pointer to the initialization parameters.
  44. //
  45. pStartupParams = (XDP8STARTUP_PARAMS*) hModule;
  46. #endif // DPNBUILD_PREALLOCATEDMEMORYMODEL
  47. #ifdef DBG
  48. DNASSERT(!g_fAddrObjectInited);
  49. #endif // DBG
  50. #ifndef DPNBUILD_ONLYONESP
  51. if( WSAStartup( MAKEWORD(1,1), &wsaData ) )
  52. {
  53. DPFX(DPFPREP, 0, "Unable to load winsock. Error" );
  54. goto Failure;
  55. }
  56. g_dwAddrInitFlags |= WSA_INITED;
  57. #endif // ! DPNBUILD_ONLYONESP
  58. if (!fpmAddressObjects.Initialize( sizeof( DP8ADDRESSOBJECT ),
  59. DP8ADDRESSOBJECT::FPM_BlockCreate,
  60. DP8ADDRESSOBJECT::FPM_BlockInit,
  61. DP8ADDRESSOBJECT::FPM_BlockRelease,
  62. DP8ADDRESSOBJECT::FPM_BlockDestroy ))
  63. {
  64. DPFX(DPFPREP, 0,"Failed to initialize address object pool");
  65. goto Failure;
  66. }
  67. g_dwAddrInitFlags |= ADDROBJ_INITED;
  68. if (!fpmAddressElements.Initialize( sizeof( DP8ADDRESSELEMENT ), NULL,
  69. DP8ADDRESSOBJECT::FPM_Element_BlockInit,
  70. DP8ADDRESSOBJECT::FPM_Element_BlockRelease, NULL ))
  71. {
  72. DPFX(DPFPREP, 0,"Failed to allocate address element pool");
  73. goto Failure;
  74. }
  75. g_dwAddrInitFlags |= ADDRELEM_INITED;
  76. if (FAILED(DP8A_STRCACHE_Init()))
  77. {
  78. DPFX(DPFPREP, 0,"Failed to initialize string cache");
  79. goto Failure;
  80. }
  81. g_dwAddrInitFlags |= STRCACHE_INITED;
  82. #ifdef DPNBUILD_PREALLOCATEDMEMORYMODEL
  83. if (DNAddress_PreallocateInterfaces(pStartupParams->dwNumAddressInterfaces) != DPN_OK)
  84. {
  85. DPFX(DPFPREP, 0, "Couldn't pre-allocate %u address objects!",
  86. pStartupParams->dwNumAddressInterfaces);
  87. goto Failure;
  88. }
  89. #endif // DPNBUILD_PREALLOCATEDMEMORYMODEL
  90. DEBUG_ONLY(g_fAddrObjectInited = TRUE);
  91. return TRUE;
  92. Failure:
  93. DNAddressDeInit();
  94. return FALSE;
  95. }
  96. #undef DPF_MODNAME
  97. #define DPF_MODNAME "DNAddressDeInit"
  98. void DNAddressDeInit()
  99. {
  100. #ifdef DBG
  101. DNASSERT(g_fAddrObjectInited);
  102. #endif // DBG
  103. DPFX(DPFPREP, 5, "Deinitializing Addressing");
  104. if (g_dwAddrInitFlags & STRCACHE_INITED)
  105. {
  106. DP8A_STRCACHE_Free();
  107. }
  108. if (g_dwAddrInitFlags & ADDRELEM_INITED)
  109. {
  110. fpmAddressElements.DeInitialize();
  111. }
  112. if (g_dwAddrInitFlags & ADDROBJ_INITED)
  113. {
  114. fpmAddressObjects.DeInitialize();
  115. }
  116. #ifndef DPNBUILD_ONLYONESP
  117. if (g_dwAddrInitFlags & WSA_INITED)
  118. {
  119. WSACleanup();
  120. }
  121. #endif // ! DPNBUILD_ONLYONESP
  122. g_dwAddrInitFlags = 0;
  123. DEBUG_ONLY(g_fAddrObjectInited = FALSE);
  124. }
  125. #ifndef DPNBUILD_NOCOMREGISTER
  126. #undef DPF_MODNAME
  127. #define DPF_MODNAME "DNAddressRegister"
  128. BOOL DNAddressRegister(LPCWSTR wszDLLName)
  129. {
  130. if( !CRegistry::Register( L"DirectPlay8Address.Address.1", L"DirectPlay8Address Object",
  131. wszDLLName, &CLSID_DirectPlay8Address, L"DirectPlay8Address.Address") )
  132. {
  133. DPFERR( "Could not register address object" );
  134. return FALSE;
  135. }
  136. else
  137. {
  138. return TRUE;
  139. }
  140. }
  141. #undef DPF_MODNAME
  142. #define DPF_MODNAME "DNAddressUnRegister"
  143. BOOL DNAddressUnRegister()
  144. {
  145. if( !CRegistry::UnRegister(&CLSID_DirectPlay8Address) )
  146. {
  147. DPFX(DPFPREP, 0, "Failed to unregister server object" );
  148. return FALSE;
  149. }
  150. else
  151. {
  152. return TRUE;
  153. }
  154. }
  155. #endif // !DPNBUILD_NOCOMREGISTER
  156. #ifndef DPNBUILD_LIBINTERFACE
  157. #undef DPF_MODNAME
  158. #define DPF_MODNAME "DNAddressGetRemainingObjectCount"
  159. DWORD DNAddressGetRemainingObjectCount()
  160. {
  161. return g_lAddrObjectCount;
  162. }
  163. #endif // ! DPNBUILD_LIBINTERFACE