Source code of Windows XP (NT5)
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.

281 lines
7.0 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000 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. extern DWORD GdwHLocks;
  21. extern DWORD GdwHObjects;
  22. #undef DPF_MODNAME
  23. #define DPF_MODNAME "DllRegisterServer"
  24. HRESULT WINAPI DllRegisterServer()
  25. {
  26. HRESULT hr = S_OK;
  27. BOOL fFailed = FALSE;
  28. if( !CRegistry::Register( L"DirectPlay8Address.Address.1", L"DirectPlay8Address Object",
  29. L"dpnaddr.dll", CLSID_DirectPlay8Address, L"DirectPlay8Address.Address") )
  30. {
  31. DPFERR( "Could not register address object" );
  32. fFailed = TRUE;
  33. }
  34. if( fFailed )
  35. {
  36. return E_FAIL;
  37. }
  38. else
  39. {
  40. return S_OK;
  41. }
  42. }
  43. #undef DPF_MODNAME
  44. #define DPF_MODNAME "DllUnregisterServer"
  45. STDAPI DllUnregisterServer()
  46. {
  47. HRESULT hr = S_OK;
  48. BOOL fFailed = FALSE;
  49. if( !CRegistry::UnRegister(CLSID_DirectPlay8Address) )
  50. {
  51. DPFX(DPFPREP, 0, "Failed to unregister server object" );
  52. fFailed = TRUE;
  53. }
  54. if( fFailed )
  55. {
  56. return E_FAIL;
  57. }
  58. else
  59. {
  60. return S_OK;
  61. }
  62. }
  63. #undef DPF_MODNAME
  64. #define DPF_MODNAME "DllMain"
  65. BOOL APIENTRY DllMain( HANDLE hModule,
  66. DWORD ul_reason_for_call,
  67. LPVOID lpReserved
  68. )
  69. {
  70. _try
  71. {
  72. DPFX(DPFPREP, 3,"Parameters: hModule [%p], ul_reason_for_call [%lx], lpReserved [%p]",
  73. hModule,ul_reason_for_call,lpReserved);
  74. if (ul_reason_for_call == DLL_PROCESS_ATTACH)
  75. {
  76. WORD wVersionRequested = MAKEWORD(1,1);
  77. WSADATA wsaData;
  78. int nResult;
  79. nResult = WSAStartup( wVersionRequested, &wsaData );
  80. if( nResult )
  81. {
  82. DPFX(DPFPREP, 0, "Unable to load winsock. Error" );
  83. return FALSE;
  84. }
  85. if (DNOSIndirectionInit() == FALSE)
  86. {
  87. DPFX(DPFPREP, 0,"Failed to initialize OS indirection layer");
  88. WSACleanup();
  89. return FALSE;
  90. }
  91. if (FAILED(COM_Init()))
  92. {
  93. DPFX(DPFPREP, 0,"Failed to initialize COM indirection layer");
  94. DNOSIndirectionDeinit();
  95. WSACleanup();
  96. return FALSE;
  97. }
  98. fpmAddressClassFacs = FPM_Create( sizeof( _IDirectPlay8AddressClassFact ),
  99. NULL,
  100. NULL,
  101. NULL,
  102. NULL );
  103. if (fpmAddressClassFacs == NULL)
  104. {
  105. DPFX(DPFPREP, 0,"Failed to allocate address class factory pool");
  106. COM_Free();
  107. DNOSIndirectionDeinit();
  108. WSACleanup();
  109. return FALSE;
  110. }
  111. fpmAddressObjects = FPM_Create( sizeof( DP8ADDRESSOBJECT ),
  112. DP8ADDRESSOBJECT::FPM_BlockCreate,
  113. DP8ADDRESSOBJECT::FPM_BlockInit,
  114. DP8ADDRESSOBJECT::FPM_BlockRelease,
  115. DP8ADDRESSOBJECT::FPM_BlockDestroy );
  116. if (fpmAddressObjects == NULL)
  117. {
  118. DPFX(DPFPREP, 0,"Failed to allocate address object pool");
  119. fpmAddressClassFacs->Fini(fpmAddressClassFacs);
  120. fpmAddressClassFacs = NULL;
  121. COM_Free();
  122. DNOSIndirectionDeinit();
  123. WSACleanup();
  124. return FALSE;
  125. }
  126. fpmAddressElements = FPM_Create( sizeof( DP8ADDRESSELEMENT ), NULL,
  127. DP8ADDRESSOBJECT::FPM_Element_BlockInit,
  128. DP8ADDRESSOBJECT::FPM_Element_BlockRelease, NULL );
  129. if (fpmAddressElements == NULL)
  130. {
  131. DPFX(DPFPREP, 0,"Failed to allocate address element pool");
  132. fpmAddressObjects->Fini(fpmAddressObjects);
  133. fpmAddressObjects = NULL;
  134. fpmAddressClassFacs->Fini(fpmAddressClassFacs);
  135. fpmAddressClassFacs = NULL;
  136. COM_Free();
  137. DNOSIndirectionDeinit();
  138. WSACleanup();
  139. return FALSE;
  140. }
  141. fpmAddressInterfaceLists = FPM_Create( sizeof( INTERFACE_LIST ),
  142. NULL,
  143. NULL,
  144. NULL,
  145. NULL );
  146. if (fpmAddressInterfaceLists == NULL)
  147. {
  148. DPFX(DPFPREP, 0,"Failed to allocate address interface list pool");
  149. fpmAddressElements->Fini(fpmAddressElements);
  150. fpmAddressElements = NULL;
  151. fpmAddressObjects->Fini(fpmAddressObjects);
  152. fpmAddressObjects = NULL;
  153. fpmAddressClassFacs->Fini(fpmAddressClassFacs);
  154. fpmAddressClassFacs = NULL;
  155. COM_Free();
  156. DNOSIndirectionDeinit();
  157. WSACleanup();
  158. return FALSE;
  159. }
  160. fpmAddressObjectDatas = FPM_Create( sizeof( OBJECT_DATA ),
  161. NULL,
  162. NULL,
  163. NULL,
  164. NULL );
  165. if (fpmAddressObjectDatas == NULL)
  166. {
  167. DPFX(DPFPREP, 0,"Failed to allocate address object data pool");
  168. fpmAddressInterfaceLists->Fini(fpmAddressInterfaceLists);
  169. fpmAddressInterfaceLists = NULL;
  170. fpmAddressElements->Fini(fpmAddressElements);
  171. fpmAddressElements = NULL;
  172. fpmAddressObjects->Fini(fpmAddressObjects);
  173. fpmAddressObjects = NULL;
  174. fpmAddressClassFacs->Fini(fpmAddressClassFacs);
  175. fpmAddressClassFacs = NULL;
  176. COM_Free();
  177. DNOSIndirectionDeinit();
  178. WSACleanup();
  179. return FALSE;
  180. }
  181. DP8A_STRCACHE_Init();
  182. }
  183. else if( ul_reason_for_call == DLL_PROCESS_DETACH )
  184. {
  185. fpmAddressClassFacs->Fini(fpmAddressClassFacs);
  186. fpmAddressClassFacs = NULL;
  187. fpmAddressObjects->Fini(fpmAddressObjects);
  188. fpmAddressObjects = NULL;
  189. fpmAddressElements->Fini(fpmAddressElements);
  190. fpmAddressElements = NULL;
  191. fpmAddressInterfaceLists->Fini(fpmAddressInterfaceLists);
  192. fpmAddressInterfaceLists = NULL;
  193. fpmAddressObjectDatas->Fini(fpmAddressObjectDatas);
  194. fpmAddressObjectDatas = NULL;
  195. DP8A_STRCACHE_Free();
  196. COM_Free();
  197. DNOSIndirectionDeinit();
  198. WSACleanup();
  199. }
  200. return TRUE;
  201. }
  202. _except( EXCEPTION_EXECUTE_HANDLER )
  203. {
  204. DPFERR("THERE WAS AN ERROR IN DllMain()");
  205. return FALSE;
  206. }
  207. }
  208. #undef DPF_MODNAME
  209. #define DPF_MODNAME "DllGetClassObject"
  210. STDAPI DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID *ppv)
  211. {
  212. _LPIDirectPlay8AddressClassFact lpcfObj;
  213. HRESULT hResultCode = S_OK;
  214. DPFX(DPFPREP, 3,"Parameters: rclsid [%p], riid [%p], ppv [%p]",rclsid,riid,ppv);
  215. // Allocate Class Factory object
  216. lpcfObj = (_LPIDirectPlay8AddressClassFact)fpmAddressClassFacs->Get(fpmAddressClassFacs);
  217. if (lpcfObj == NULL)
  218. {
  219. DPFERR("FPM_Get() failed");
  220. *ppv = NULL;
  221. return(E_OUTOFMEMORY);
  222. }
  223. DPFX(DPFPREP, 5,"lpcfObj = [%p]",lpcfObj);
  224. lpcfObj->lpVtbl = &DP8ACF_Vtbl;
  225. lpcfObj->lRefCount = 0;
  226. // Query to find the interface
  227. if ((hResultCode = lpcfObj->lpVtbl->QueryInterface(reinterpret_cast<IDirectPlay8AddressClassFact*>( lpcfObj ),riid,ppv)) != S_OK)
  228. {
  229. fpmAddressClassFacs->Release(fpmAddressClassFacs, lpcfObj);
  230. }
  231. // One more thing to release !
  232. GdwHObjects++;
  233. DPFX(DPFPREP, 3,"Return: hResultCode = [%lx], *ppv = [%p]",hResultCode,*ppv);
  234. return(hResultCode);
  235. }
  236. #undef DPF_MODNAME
  237. #define DPF_MODNAME "DllCanUnloadNow"
  238. STDAPI DllCanUnloadNow(void)
  239. {
  240. DPFX(DPFPREP, 3,"Parameters: (none)");
  241. DPFX(DPFPREP, 5,"GdwHLocks = %ld\tGdwHObjects = %ld",GdwHLocks,GdwHObjects);
  242. if (GdwHLocks == 0 && GdwHObjects == 0)
  243. return(S_OK);
  244. else
  245. return(S_FALSE);
  246. }