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.

284 lines
7.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000-2001 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. * 02/21/2000 mjn Created
  12. * 06/07/2000 rmt Bug #34383 Must provide CLSID for each IID to fix issues with Whistler
  13. * 06/15/2000 rmt Bug #33617 - Must provide method for providing automatic launch of DirectPlay instances
  14. * 07/21/2000 RichGr IA64: Use %p format specifier for 32/64-bit pointers.
  15. * 08/18/2000 rmt Bug #42751 - DPLOBBY8: Prohibit more than one lobby client or lobby app per process
  16. * 08/30/2000 rmt Whistler Bug #171824 - PREFIX Bug
  17. * 04/12/2001 VanceO Moved granting registry permissions into common.
  18. * 06/16/2001 rodtoll WINBUG #416983 - RC1: World has full control to HKLM\Software\Microsoft\DirectPlay\Applications on Personal
  19. * Implementing mirror of keys into HKCU. Algorithm is now:
  20. * - Read of entries tries HKCU first, then HKLM
  21. * - Enum of entires is combination of HKCU and HKLM entries with duplicates removed. HKCU takes priority.
  22. * - Write of entries is HKLM and HKCU. (HKLM may fail, but is ignored).
  23. * - Removed permission modifications from lobby self-registration -- no longer needed.
  24. * 06/19/2001 RichGr DX8.0 added special security rights for "everyone" - remove them if they exist.
  25. *@@END_MSINTERNAL
  26. *
  27. ***************************************************************************/
  28. #include "dnlobbyi.h"
  29. extern BOOL g_fAppStarted;
  30. extern BOOL g_fClientStarted;
  31. extern DNCRITICAL_SECTION g_csSingleTon;
  32. // Globals
  33. extern DWORD GdwHLocks;
  34. extern DWORD GdwHObjects;
  35. extern IDirectPlayLobbyClassFactVtbl DPLCF_Vtbl;
  36. #undef DPF_MODNAME
  37. #define DPF_MODNAME "RegisterDefaultSettings"
  38. //
  39. // RegisterDefaultSettings
  40. //
  41. // This function registers the default settings for this module.
  42. //
  43. // For DPVOICE.DLL this is making sure the compression provider sub-key is created.
  44. //
  45. HRESULT RegisterDefaultSettings()
  46. {
  47. CRegistry creg;
  48. if( !creg.Open( HKEY_LOCAL_MACHINE, DPL_REG_LOCAL_APPL_ROOT DPL_REG_LOCAL_APPL_SUB, FALSE, TRUE ) )
  49. {
  50. DPFERR( "Cannot create app subkey" );
  51. return DPNERR_GENERIC;
  52. }
  53. // Adjust security permissions of the given key
  54. else
  55. {
  56. // 6/19/01: DX8.0 added special security rights for "everyone" - remove them.
  57. if( DNGetOSType() == VER_PLATFORM_WIN32_NT )
  58. {
  59. if( !creg.RemoveAllAccessSecurityPermissions() )
  60. {
  61. DPFX(DPFPREP, 0, "Error removing security permissions for app key" );
  62. }
  63. }
  64. return DPN_OK;
  65. }
  66. }
  67. #undef DPF_MODNAME
  68. #define DPF_MODNAME "UnRegisterDefaultSettings"
  69. //
  70. // UnRegisterDefaultSettings
  71. //
  72. // This function registers the default settings for this module.
  73. //
  74. // For DPVOICE.DLL this is making sure the compression provider sub-key is created.
  75. //
  76. HRESULT UnRegisterDefaultSettings()
  77. {
  78. CRegistry creg;
  79. if( !creg.Open( HKEY_LOCAL_MACHINE, DPL_REG_LOCAL_APPL_ROOT, FALSE, TRUE ) )
  80. {
  81. DPFERR( "Cannot remove app, does not exist" );
  82. }
  83. else
  84. {
  85. if( !creg.DeleteSubKey( &(DPL_REG_LOCAL_APPL_SUB)[1] ) )
  86. {
  87. DPFERR( "Cannot remove cp sub-key, could have elements" );
  88. }
  89. }
  90. return DPN_OK;
  91. }
  92. #undef DPF_MODNAME
  93. #define DPF_MODNAME "DllRegisterServer"
  94. HRESULT WINAPI DllRegisterServer()
  95. {
  96. HRESULT hr = S_OK;
  97. BOOL fFailed = FALSE;
  98. if( !CRegistry::Register( L"DirectPlay8Lobby.LobbyClient.1", L"DirectPlay8LobbyClient Object",
  99. L"dpnlobby.dll", CLSID_DirectPlay8LobbyClient, L"DirectPlay8Lobby.LobbyClient") )
  100. {
  101. DPFERR( "Could not register lobby client object" );
  102. fFailed = TRUE;
  103. }
  104. if( !CRegistry::Register( L"DirectPlay8Lobby.LobbiedApplication.1", L"DirectPlay8LobbiedApplication Object",
  105. L"dpnlobby.dll", CLSID_DirectPlay8LobbiedApplication, L"DirectPlay8Lobby.LobbiedApplication") )
  106. {
  107. DPFERR( "Could not register lobby client object" );
  108. fFailed = TRUE;
  109. }
  110. if( FAILED( hr = RegisterDefaultSettings() ) )
  111. {
  112. DPFX(DPFPREP, 0, "Could not register default settings hr = 0x%x", hr );
  113. fFailed = TRUE;
  114. }
  115. if( fFailed )
  116. {
  117. return E_FAIL;
  118. }
  119. else
  120. {
  121. return S_OK;
  122. }
  123. }
  124. #undef DPF_MODNAME
  125. #define DPF_MODNAME "DllUnregisterServer"
  126. STDAPI DllUnregisterServer()
  127. {
  128. HRESULT hr = S_OK;
  129. BOOL fFailed = FALSE;
  130. if( !CRegistry::UnRegister(CLSID_DirectPlay8LobbyClient) )
  131. {
  132. DPFX(DPFPREP, 0, "Failed to unregister client object" );
  133. fFailed = TRUE;
  134. }
  135. if( !CRegistry::UnRegister(CLSID_DirectPlay8LobbiedApplication) )
  136. {
  137. DPFX(DPFPREP, 0, "Failed to unregister app object" );
  138. fFailed = TRUE;
  139. }
  140. if( FAILED( hr = UnRegisterDefaultSettings() ) )
  141. {
  142. DPFX(DPFPREP, 0, "Failed to remove default settings hr=0x%x", hr );
  143. }
  144. if( fFailed )
  145. {
  146. return E_FAIL;
  147. }
  148. else
  149. {
  150. return S_OK;
  151. }
  152. }
  153. #undef DPF_MODNAME
  154. #define DPF_MODNAME "DllMain"
  155. BOOL APIENTRY DllMain( HANDLE hModule,
  156. DWORD ul_reason_for_call,
  157. LPVOID lpReserved
  158. )
  159. {
  160. TRY
  161. {
  162. DPFX(DPFPREP, 3,"Parameters: hModule [%p], ul_reason_for_call [%lx], lpReserved [%p]",
  163. hModule,ul_reason_for_call,lpReserved);
  164. switch ( ul_reason_for_call )
  165. {
  166. case DLL_PROCESS_ATTACH:
  167. {
  168. if (DNOSIndirectionInit() == FALSE)
  169. {
  170. DPFX(DPFPREP, 0,"Failed to initialize OS indirection layer");
  171. return FALSE;
  172. }
  173. if (FAILED(COM_Init()))
  174. {
  175. DPFX(DPFPREP, 0,"Failed to initialize COM indirection layer");
  176. DNOSIndirectionDeinit();
  177. return FALSE;
  178. }
  179. if (DNInitializeCriticalSection( &g_csSingleTon ) == FALSE)
  180. {
  181. DPFX(DPFPREP, 0,"Failed to initialize singleton CS");
  182. COM_Free();
  183. DNOSIndirectionDeinit();
  184. return FALSE;
  185. }
  186. break;
  187. }
  188. case DLL_PROCESS_DETACH:
  189. {
  190. COM_Free();
  191. DNDeleteCriticalSection( &g_csSingleTon );
  192. DNOSIndirectionDeinit();
  193. break;
  194. }
  195. }
  196. return TRUE;
  197. }
  198. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  199. {
  200. DPFERR("THERE WAS AN ERROR IN DllMain()");
  201. return FALSE;
  202. }
  203. }
  204. #undef DPF_MODNAME
  205. #define DPF_MODNAME "DllGetClassObject"
  206. STDAPI DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID *ppv)
  207. {
  208. _PIDirectPlayLobbyClassFact lpcfObj;
  209. HRESULT hResultCode = S_OK;
  210. DPFX(DPFPREP, 3,"Parameters: rclsid [%p], riid [%p], ppv [%p]",rclsid,riid,ppv);
  211. // Allocate Class Factory object
  212. if ((lpcfObj = (_PIDirectPlayLobbyClassFact)DNMalloc(sizeof(_IDirectPlayLobbyClassFact))) == NULL)
  213. {
  214. *ppv = NULL;
  215. return(E_OUTOFMEMORY);
  216. }
  217. DPFX(DPFPREP, 5,"lpcfObj = [%p]",lpcfObj);
  218. lpcfObj->lpVtbl = &DPLCF_Vtbl;
  219. lpcfObj->lRefCount = 0;
  220. lpcfObj->clsid = rclsid;
  221. // Query to find the interface
  222. if ((hResultCode = lpcfObj->lpVtbl->QueryInterface(reinterpret_cast<IDirectPlayLobbyClassFact*>(lpcfObj),riid,ppv)) != S_OK)
  223. {
  224. DNFree(lpcfObj);
  225. }
  226. // One more thing to release !
  227. GdwHObjects++;
  228. DPFX(DPFPREP, 3,"Return: hResultCode = [%lx], *ppv = [%p]",hResultCode,*ppv);
  229. return(hResultCode);
  230. }
  231. #undef DPF_MODNAME
  232. #define DPF_MODNAME "DllCanUnloadNow"
  233. STDAPI DllCanUnloadNow(void)
  234. {
  235. DPFX(DPFPREP, 3,"Parameters: (none)");
  236. DPFX(DPFPREP, 5,"GdwHLocks = %ld\tGdwHObjects = %ld",GdwHLocks,GdwHObjects);
  237. if (GdwHLocks == 0 && GdwHObjects == 0)
  238. return(S_OK);
  239. else
  240. return(S_FALSE);
  241. }