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.

168 lines
4.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dvsetup.c
  6. * Content: Implements functions for the DirectXVoiceSetup interface
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 09/02/99 pnewson Created It
  12. * 10/25/99 rodtoll Bug #114098 - Calling AddRef/Release from seperate threads
  13. * on multiproc can cause improper results
  14. * 11/04/99 pnewson Bug #115297 - removed unused members of Setup interface
  15. * - added HWND to check audio setup
  16. * 11/17/99 rodtoll Bug #116153 - Setup QueryInterface crashes with NULL pointer
  17. * 11/30/99 pnewson Bug #117449 - Parameter validation
  18. * 05/03/2000 rodtoll Bug #33640 - CheckAudioSetup takes GUID * instead of const GUID *
  19. * 08/23/2000 rodtoll DllCanUnloadNow always returning TRUE!
  20. * 10/05/2000 rodtoll Bug #46541 - DPVOICE: A/V linking to dpvoice.lib could cause application to fail init and crash
  21. *
  22. ***************************************************************************/
  23. #include "dxvoicepch.h"
  24. #undef DPF_SUBCOMP
  25. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  26. // defined in unk.cpp
  27. extern LPVOID dvtInterface[];
  28. #undef DPF_MODNAME
  29. #define DPF_MODNAME "DVT_ValidDirectXVoiceSetupObject"
  30. // DV_ValidDirectXVoiceSetupObject
  31. //
  32. // Checks to ensure the specified pointer points to a valid directvoice setup
  33. // object.
  34. BOOL DVT_ValidDirectXVoiceSetupObject( LPDIRECTVOICESETUPOBJECT lpdvt )
  35. {
  36. if (lpdvt == NULL)
  37. {
  38. DPFX(DPFPREP, DVF_ERRORLEVEL, "Invalid Setup object pointer");
  39. return FALSE;
  40. }
  41. if (!DNVALID_READPTR(lpdvt, sizeof(LPDIRECTVOICESETUPOBJECT)))
  42. {
  43. DPFX(DPFPREP, DVF_ERRORLEVEL, "Invalid Setup object pointer");
  44. return FALSE;
  45. }
  46. if( lpdvt->lpVtbl != dvtInterface )
  47. {
  48. DPFX(DPFPREP, DVF_ERRORLEVEL, "Invalid setup vtable" );
  49. return FALSE;
  50. }
  51. if ( lpdvt->lpDVSetup == NULL )
  52. {
  53. DPFX(DPFPREP, DVF_ERRORLEVEL, "Inavlid CDirectVoiceSetup pointer");
  54. return FALSE;
  55. }
  56. if (!DNVALID_READPTR(lpdvt->lpDVSetup, sizeof(CDirectVoiceSetup)))
  57. {
  58. DPFX(DPFPREP, DVF_ERRORLEVEL, "Inavlid CDirectVoiceSetup pointer");
  59. return FALSE;
  60. }
  61. return TRUE;
  62. }
  63. #undef DPF_MODNAME
  64. #define DPF_MODNAME "DVT_AddRef"
  65. STDAPI DVT_AddRef(LPDIRECTVOICESETUPOBJECT lpDVT)
  66. {
  67. LONG rc;
  68. DNEnterCriticalSection( &lpDVT->csCountLock );
  69. rc = ++lpDVT->lIntRefCnt;
  70. DNLeaveCriticalSection( &lpDVT->csCountLock );
  71. return rc;
  72. }
  73. #undef DPF_MODNAME
  74. #define DPF_MODNAME "DVT_Release"
  75. STDAPI DVT_Release(LPDIRECTVOICESETUPOBJECT lpDV )
  76. {
  77. HRESULT hr=S_OK;
  78. LONG rc;
  79. DNEnterCriticalSection( &lpDV->csCountLock );
  80. if (lpDV->lIntRefCnt == 0)
  81. {
  82. DNLeaveCriticalSection( &lpDV->csCountLock );
  83. return 0;
  84. }
  85. // dec the interface count
  86. rc = --lpDV->lIntRefCnt;
  87. if (0 == rc)
  88. {
  89. DNLeaveCriticalSection( &lpDV->csCountLock );
  90. delete lpDV->lpDVSetup;
  91. DNDeleteCriticalSection( &lpDV->csCountLock );
  92. DNFree(lpDV);
  93. DecrementObjectCount();
  94. }
  95. else
  96. {
  97. DNLeaveCriticalSection( &lpDV->csCountLock );
  98. }
  99. return rc;
  100. }
  101. #undef DPF_MODNAME
  102. #define DPF_MODNAME "DVT_QueryInterface"
  103. STDMETHODIMP DVT_QueryInterface(LPDIRECTVOICESETUPOBJECT lpDVT, REFIID riid, LPVOID * ppvObj)
  104. {
  105. HRESULT hr = S_OK;
  106. if( ppvObj == NULL ||
  107. !DNVALID_WRITEPTR( ppvObj, sizeof( LPVOID ) ) )
  108. {
  109. return DVERR_INVALIDPOINTER;
  110. }
  111. *ppvObj=NULL;
  112. if( IsEqualIID(riid, IID_IUnknown) ||
  113. IsEqualIID(riid, IID_IDirectPlayVoiceTest ) )
  114. {
  115. *ppvObj = lpDVT;
  116. DVT_AddRef(lpDVT);
  117. }
  118. else
  119. {
  120. hr = E_NOINTERFACE;
  121. }
  122. return hr;
  123. }//DVT_QueryInterface
  124. #undef DPF_MODNAME
  125. #define DPF_MODNAME "DVT_CheckAudioSetup"
  126. STDMETHODIMP DVT_CheckAudioSetup(LPDIRECTVOICESETUPOBJECT This, const GUID * lpguidRenderDevice, const GUID * lpguidCaptureDevice, HWND hwndParent, DWORD dwFlags)
  127. {
  128. DPFX(DPFPREP, DVF_ENTRYLEVEL, "Enter");
  129. if( !DVT_ValidDirectXVoiceSetupObject( This ) )
  130. return DVERR_INVALIDOBJECT;
  131. HRESULT hr;
  132. hr = This->lpDVSetup->CheckAudioSetup( lpguidRenderDevice, lpguidCaptureDevice, hwndParent, dwFlags );
  133. DPFX(DPFPREP, DVF_ENTRYLEVEL, "Exit");
  134. return hr;
  135. }