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.

211 lines
5.0 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999, 2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dllmain.cpp
  6. * Content: This file contains all of the DLL exports except for DllGetClass / DllCanUnload
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 07/05/00 rodtoll Created
  11. * 08/23/2000 rodtoll DllCanUnloadNow always returning TRUE!
  12. * 08/28/2000 masonb Voice Merge: Removed OSAL_* and dvosal.h
  13. * 06/27/2001 rodtoll RC2: DPVOICE: DPVACM's DllMain calls into acm -- potential hang
  14. * Move global initialization to first object creation
  15. *
  16. ***************************************************************************/
  17. #include "dpvacmpch.h"
  18. LONG lInitCount = 0;
  19. #undef DPF_MODNAME
  20. #define DPF_MODNAME "RegisterDefaultSettings"
  21. //
  22. // RegisterDefaultSettings
  23. //
  24. // This function registers the default settings for this module.
  25. //
  26. // For DPVOICE.DLL this is making sure the compression provider sub-key is created.
  27. //
  28. HRESULT RegisterDefaultSettings()
  29. {
  30. CRegistry creg;
  31. if( !creg.Open( HKEY_LOCAL_MACHINE, DPVOICE_REGISTRY_BASE DPVOICE_REGISTRY_CP DPVOICE_REGISTRY_DPVACM, FALSE, TRUE ) )
  32. {
  33. DPFERR( "Could not create dpvacm config key" );
  34. return DVERR_GENERIC;
  35. }
  36. else
  37. {
  38. if( !creg.WriteGUID( L"", CLSID_DPVCPACM ) )
  39. {
  40. DPFERR( "Could not write dpvacm GUID" );
  41. return DVERR_GENERIC;
  42. }
  43. return DV_OK;
  44. }
  45. }
  46. #undef DPF_MODNAME
  47. #define DPF_MODNAME "UnRegisterDefaultSettings"
  48. //
  49. // UnRegisterDefaultSettings
  50. //
  51. // This function unregisters the default settings for this module.
  52. //
  53. // For DPVOICE.DLL this is making sure the compression provider sub-key is created.
  54. //
  55. HRESULT UnRegisterDefaultSettings()
  56. {
  57. CRegistry creg;
  58. if( !creg.Open( HKEY_LOCAL_MACHINE, DPVOICE_REGISTRY_BASE DPVOICE_REGISTRY_CP, FALSE, FALSE ) )
  59. {
  60. DPFERR( "Cannot remove DPVACM key, does not exist" );
  61. }
  62. else
  63. {
  64. if( !creg.DeleteSubKey( &(DPVOICE_REGISTRY_DPVACM)[1] ) )
  65. {
  66. DPFERR( "Could not remove DPVACM sub-key" );
  67. }
  68. }
  69. return DV_OK;
  70. }
  71. #undef DPF_MODNAME
  72. #define DPF_MODNAME "DllRegisterServer"
  73. HRESULT WINAPI DllRegisterServer()
  74. {
  75. HRESULT hr = S_OK;
  76. BOOL fFailed = FALSE;
  77. #if !defined(DBG) || !defined( DIRECTX_REDIST )
  78. #define DPVOICE_FILENAME_DPVACM L"dpvacm.dll"
  79. #else
  80. // For redist debug builds we append a 'd' to the name to allow both debug and retail to be installed on the system
  81. #define DPVOICE_FILENAME_DPVACM L"dpvacmd.dll"
  82. #endif // !defined(DBG) || !defined( DIRECTX_REDIST )
  83. if( !CRegistry::Register( L"DirectPlayVoiceACM.Converter.1", L"DirectPlayVoice ACM Converter Object",
  84. DPVOICE_FILENAME_DPVACM, &CLSID_DPVCPACM_CONVERTER, L"DirectPlayVoiceACM.Converter") )
  85. {
  86. DPFERR( "Could not register converter object" );
  87. fFailed = TRUE;
  88. }
  89. if( !CRegistry::Register( L"DirectPlayVoiceACM.Provider.1", L"DirectPlayVoice ACM Provider Object",
  90. DPVOICE_FILENAME_DPVACM, &CLSID_DPVCPACM , L"DirectPlayVoiceACM.Provider") )
  91. {
  92. DPFERR( "Could not register provider object" );
  93. fFailed = TRUE;
  94. }
  95. if( FAILED( hr = RegisterDefaultSettings() ) )
  96. {
  97. DPFX(DPFPREP, 0, "Could not register default settings hr = 0x%x", hr );
  98. fFailed = TRUE;
  99. }
  100. if( fFailed )
  101. {
  102. return E_FAIL;
  103. }
  104. else
  105. {
  106. return S_OK;
  107. }
  108. }
  109. #undef DPF_MODNAME
  110. #define DPF_MODNAME "DllUnregisterServer"
  111. STDAPI DllUnregisterServer()
  112. {
  113. HRESULT hr = S_OK;
  114. BOOL fFailed = FALSE;
  115. if( !CRegistry::UnRegister(&CLSID_DPVCPACM_CONVERTER) )
  116. {
  117. DPFX(DPFPREP, DVF_ERRORLEVEL, "Failed to unregister server object" );
  118. fFailed = TRUE;
  119. }
  120. if( !CRegistry::UnRegister(&CLSID_DPVCPACM) )
  121. {
  122. DPFX(DPFPREP, DVF_ERRORLEVEL, "Failed to unregister compat object" );
  123. fFailed = TRUE;
  124. }
  125. if( FAILED( hr = UnRegisterDefaultSettings() ) )
  126. {
  127. DPFX(DPFPREP, 0, "Could not remove default settings hr=0x%x", hr );
  128. fFailed = TRUE;
  129. }
  130. if( fFailed )
  131. {
  132. return E_FAIL;
  133. }
  134. else
  135. {
  136. return S_OK;
  137. }
  138. }
  139. #undef DPF_MODNAME
  140. #define DPF_MODNAME "DllMain"
  141. BOOL WINAPI DllMain(
  142. HINSTANCE hDllInst,
  143. DWORD fdwReason,
  144. LPVOID lpvReserved)
  145. {
  146. if( fdwReason == DLL_PROCESS_ATTACH )
  147. {
  148. if( !lInitCount )
  149. {
  150. g_hDllInst = hDllInst;
  151. if (!DNOSIndirectionInit(0))
  152. {
  153. return FALSE;
  154. }
  155. if( !DNInitializeCriticalSection( &g_csObjectCountLock ) )
  156. {
  157. DNOSIndirectionDeinit();
  158. return FALSE;
  159. }
  160. DPFX(DPFPREP, DVF_INFOLEVEL, ">>>>>>>>>>>>>>>> DPF INIT CALLED <<<<<<<<<<<<<<<" );
  161. }
  162. InterlockedIncrement( &lInitCount );
  163. }
  164. else if( fdwReason == DLL_PROCESS_DETACH )
  165. {
  166. InterlockedDecrement( &lInitCount );
  167. if( lInitCount == 0 )
  168. {
  169. DPFX(DPFPREP, DVF_INFOLEVEL, ">>>>>>>>>>>>>>>> DPF UNINITED <<<<<<<<<<<<<<<" );
  170. DNDeleteCriticalSection(&g_csObjectCountLock);
  171. DNOSIndirectionDeinit();
  172. // Check to ensure we're not being unloaded with objects active
  173. DNASSERT( g_lNumObjects == 0 && g_lNumLocks == 0 );
  174. }
  175. }
  176. return TRUE;
  177. }