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.

159 lines
3.4 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dpvxmisc.cpp
  6. * Content: Useful misc utility functions lib for sample apps
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 10/07/99 rodtoll Created It
  12. * 10/15/99 rodtoll Plugged memory leaks
  13. * 01/24/2000 pnewson Prefix detected bug fix
  14. * 01/28/2000 rodtoll Prefix detected bug fix
  15. * 03/03/2000 rodtoll Updated to handle alternative gamevoice build.
  16. * 06/28/2000 rodtoll Prefix Bug #38033
  17. * 08/31/2000 rodtoll Prefix Bug #171842
  18. *
  19. ***************************************************************************/
  20. #include "dpvxlibpch.h"
  21. HRESULT DPVDX_GetCompressionName( GUID guidCT, LPTSTR lpstrName, LPDWORD lpdwNameLength )
  22. {
  23. BOOL fCoCalled = FALSE;
  24. LPDIRECTPLAYVOICECLIENT lpdpvClient = NULL;
  25. LPBYTE lpBuffer = NULL;
  26. DWORD dwSize = 0;
  27. DWORD dwNumElements = 0;
  28. LPDVCOMPRESSIONINFO lpdvCompressionInfo;
  29. LPSTR lpszName;
  30. HRESULT hr;
  31. DWORD dwIndex;
  32. if( lpdwNameLength == NULL )
  33. return DVERR_INVALIDPARAM;
  34. hr = CoCreateInstance( DPVOICE_CLSID_DPVOICE, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlayVoiceClient, (void **) &lpdpvClient );
  35. if( hr == 0x800401f0 )
  36. {
  37. fCoCalled = TRUE;
  38. hr = CoInitialize(NULL);
  39. if( FAILED( hr ) )
  40. {
  41. goto ERROR_CLEANUP;
  42. }
  43. hr = CoCreateInstance( DPVOICE_CLSID_DPVOICE, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlayVoiceClient, (void **) &lpdpvClient );
  44. }
  45. if( FAILED( hr ) )
  46. {
  47. goto ERROR_CLEANUP;
  48. }
  49. hr = lpdpvClient->GetCompressionTypes( lpBuffer, &dwSize, &dwNumElements, 0 );
  50. if( hr != DVERR_BUFFERTOOSMALL )
  51. {
  52. goto ERROR_CLEANUP;
  53. }
  54. lpBuffer = new BYTE[dwSize];
  55. if( lpBuffer == NULL )
  56. {
  57. hr = DVERR_OUTOFMEMORY;
  58. goto ERROR_CLEANUP;
  59. }
  60. hr = lpdpvClient->GetCompressionTypes( lpBuffer, &dwSize, &dwNumElements, 0 );
  61. if( FAILED( hr ) )
  62. {
  63. goto ERROR_CLEANUP;
  64. }
  65. lpdvCompressionInfo = (LPDVCOMPRESSIONINFO) lpBuffer;
  66. for( dwIndex = 0; dwIndex < dwNumElements; dwIndex++ )
  67. {
  68. if( lpdvCompressionInfo[dwIndex].guidType == guidCT )
  69. {
  70. if (lpdvCompressionInfo[dwIndex].lpszName == NULL)
  71. {
  72. hr = DVERR_GENERIC;
  73. goto ERROR_CLEANUP;
  74. }
  75. #ifdef _UNICODE
  76. if( wcslen( lpdvCompressionInfo[dwIndex].lpszName )+1 > *lpdwNameLength )
  77. {
  78. *lpdwNameLength = wcslen( lpdvCompressionInfo[dwIndex].lpszName )+1;
  79. goto ERROR_CLEANUP;
  80. }
  81. else
  82. {
  83. wcscpy( lpstrName, lpdvCompressionInfo[dwIndex].lpszName );
  84. goto ERROR_CLEANUP;
  85. }
  86. #else
  87. hr = DPVDX_AllocAndConvertToANSI( &lpszName, lpdvCompressionInfo[dwIndex].lpszName );
  88. if( FAILED( hr ) )
  89. return hr;
  90. if( lpszName == NULL )
  91. {
  92. if( lpdwNameLength > 0 )
  93. {
  94. _tcscpy( lpszName, _T("") );
  95. hr = DV_OK;
  96. }
  97. else
  98. {
  99. hr = DVERR_BUFFERTOOSMALL;
  100. }
  101. *lpdwNameLength = 1;
  102. }
  103. else if( *lpdwNameLength < (_tcsclen( lpszName )+1) || lpstrName == NULL )
  104. {
  105. *lpdwNameLength = _tcsclen( lpszName ) + 1;
  106. hr = DVERR_BUFFERTOOSMALL;
  107. delete [] lpszName;
  108. goto ERROR_CLEANUP;
  109. }
  110. else
  111. {
  112. _tcscpy( lpstrName, lpszName );
  113. delete [] lpszName;
  114. goto ERROR_CLEANUP;
  115. }
  116. #endif
  117. }
  118. }
  119. delete [] lpBuffer;
  120. hr = DVERR_COMPRESSIONNOTSUPPORTED;
  121. ERROR_CLEANUP:
  122. if( lpBuffer != NULL )
  123. delete [] lpBuffer;
  124. if( lpdpvClient != NULL )
  125. lpdpvClient->Release();
  126. if( fCoCalled )
  127. CoUninitialize();
  128. return hr;
  129. }