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.

314 lines
7.8 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dxvt.cpp
  6. * Content: Full Duplex Test main program.
  7. * History:
  8. * Date By Reason
  9. * ============
  10. * 08/19/99 pnewson created
  11. * 09/02/99 pnewson renamed to dxvt.cpp from fdtest.cpp
  12. * 11/01/99 rodtoll Bug #113726 - Voxware integration now uses COM
  13. * and this module uses LoadLibrary so we require
  14. * a CoInitialize() call.
  15. * 01/21/2000 pnewson Running this program with no command line options
  16. * now does nothing, since the cpanel is the correct
  17. * launch point now.
  18. * 03/03/2000 rodtoll Updated to handle alternative gamevoice build.
  19. * 04/19/2000 pnewson Error handling cleanup
  20. * removed obsolete retrocfg.h dependency
  21. * 06/28/2000 rodtoll Prefix Bug #38026
  22. * 07/12/2000 rodtoll Bug #31468 - Add diagnostic spew to logfile to show what is failing the HW Wizard
  23. * 08/28/2000 masonb Voice Merge: Removed OSAL_* and dvosal.h, added STR_* and strutils.h
  24. * 04/02/2001 simonpow Bug #354859 Fixes for PREfast (BOOL casts on DVGUIDFromString calls)
  25. * 02/28/2002 rodtoll WINBUG #550105 - SECURITY: DPVOICE: Dead code
  26. * - Removed /RENDER and /CAPTURE command-line processing. (Broken and not needed)
  27. *
  28. ***************************************************************************/
  29. #include <windows.h>
  30. #include <tchar.h>
  31. #include <initguid.h>
  32. #include <dplobby.h>
  33. #include <commctrl.h>
  34. #include <mmsystem.h>
  35. #include <dsoundp.h>
  36. #include <dsprv.h>
  37. #include "dvoice.h"
  38. #include "creg.h"
  39. #include "osind.h"
  40. #include "priority.h"
  41. #include "fulldup.h"
  42. #include "fdtcfg.h"
  43. #include "dndbg.h"
  44. #include "dsound.h"
  45. #include "supervis.h"
  46. #include "strutils.h"
  47. #include "comutil.h"
  48. #include "diagnos.h"
  49. #undef DPF_SUBCOMP
  50. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  51. #define DPVOICE_REGISTRY_DUMPDIAGNOSTICS L"InitDiagnostics"
  52. struct DPVSETUP_PARAMETERS
  53. {
  54. BOOL fPriority;
  55. BOOL fFullDuplex;
  56. BOOL fTest;
  57. GUID guidRender;
  58. GUID guidCapture;
  59. };
  60. #undef DPF_MODNAME
  61. #define DPF_MODNAME "ProcessCommandLine"
  62. BOOL ProcessCommandLine( TCHAR *pstrCommandLine, DPVSETUP_PARAMETERS* pParameters )
  63. {
  64. TCHAR *pNextToken = NULL;
  65. WCHAR wszGuidString[GUID_STRING_LEN];
  66. BOOL fRet;
  67. HRESULT hr=S_OK;
  68. DPF_ENTER();
  69. ZeroMemory(pParameters, sizeof(DPVSETUP_PARAMETERS));
  70. // default to the default voice devices
  71. pParameters->guidRender = DSDEVID_DefaultVoicePlayback;
  72. pParameters->guidCapture = DSDEVID_DefaultVoiceCapture;
  73. pNextToken = _tcstok(pstrCommandLine, _T(" "));
  74. // skip dpvsetup portion of command-line.
  75. pNextToken = _tcstok( NULL, _T(" ") );
  76. while( pNextToken != NULL )
  77. {
  78. if( _tcsicmp(pNextToken, _T("/T")) == 0
  79. || _tcsicmp(pNextToken, _T("/TEST")) == 0
  80. || _tcsicmp(pNextToken, _T("-T")) == 0
  81. || _tcsicmp(pNextToken, _T("-TEST")) == 0
  82. || _tcsicmp(pNextToken, _T("TEST")) == 0)
  83. {
  84. pParameters->fTest = TRUE;
  85. }
  86. else if(_tcsicmp(pNextToken, _T("/F")) == 0
  87. || _tcsicmp(pNextToken, _T("/FULLDUPLEX")) == 0
  88. || _tcsicmp(pNextToken, _T("-F")) == 0
  89. || _tcsicmp(pNextToken, _T("-FULLDUPLEX")) == 0
  90. || _tcsicmp(pNextToken, _T("FULLDUPLEX")) == 0)
  91. {
  92. pParameters->fFullDuplex = TRUE;
  93. }
  94. else if(_tcsicmp(pNextToken, _T("/P")) == 0
  95. || _tcsicmp(pNextToken, _T("/PRIORITY")) == 0
  96. || _tcsicmp(pNextToken, _T("-P")) == 0
  97. || _tcsicmp(pNextToken, _T("-PRIORITY")) == 0
  98. || _tcsicmp(pNextToken, _T("PRIORITY")) == 0)
  99. {
  100. pParameters->fPriority = TRUE;
  101. }
  102. else
  103. {
  104. DPF_EXIT();
  105. return FALSE;
  106. }
  107. pNextToken = _tcstok( NULL, _T(" ") );
  108. }
  109. // check to make sure only one of test, fullduplex, or priority was specified.
  110. int i = 0;
  111. if (pParameters->fTest)
  112. {
  113. ++i;
  114. }
  115. if (pParameters->fFullDuplex)
  116. {
  117. ++i;
  118. }
  119. if (pParameters->fPriority)
  120. {
  121. ++i;
  122. }
  123. if (i > 1)
  124. {
  125. DPF_EXIT();
  126. return FALSE;
  127. }
  128. DPF_EXIT();
  129. return TRUE;
  130. }
  131. #undef DPF_MODNAME
  132. #define DPF_MODNAME "GetDiagnosticsSetting"
  133. BOOL GetDiagnosticsSetting()
  134. {
  135. CRegistry cregSettings;
  136. BOOL fResult = FALSE;
  137. if( !cregSettings.Open( HKEY_CURRENT_USER, DPVOICE_REGISTRY_BASE, FALSE, TRUE ) )
  138. {
  139. return FALSE;
  140. }
  141. cregSettings.ReadBOOL( DPVOICE_REGISTRY_DUMPDIAGNOSTICS, &fResult );
  142. return fResult;
  143. }
  144. #undef DPF_MODNAME
  145. #define DPF_MODNAME "WinMain"
  146. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, CHAR *szOriginalCmdLine, int iCmdShow)
  147. {
  148. HINSTANCE hResDLLInstance = NULL;
  149. HRESULT hr;
  150. DPVSETUP_PARAMETERS dpvsetupParam;
  151. BOOL fCoInitialized = FALSE;
  152. BOOL fDNOSInitialized = FALSE;
  153. BOOL fDiagnostics = FALSE;
  154. TCHAR *szCmdLine = GetCommandLine();
  155. DPF_ENTER();
  156. hr = COM_CoInitialize(NULL);
  157. if( FAILED( hr ) )
  158. {
  159. MessageBox( NULL, _T("Error initializing COM"), _T("Error"), MB_OK|MB_ICONERROR);
  160. hr = DVERR_GENERIC;
  161. goto error_cleanup;
  162. }
  163. fCoInitialized = TRUE;
  164. if (!DNOSIndirectionInit(0))
  165. {
  166. MessageBox( NULL, _T("Error initializing OS indirection layer"), _T("Error"), MB_OK|MB_ICONERROR);
  167. hr = DVERR_OUTOFMEMORY;
  168. goto error_cleanup;
  169. }
  170. fDNOSInitialized = TRUE;
  171. fDiagnostics = GetDiagnosticsSetting();
  172. if (!ProcessCommandLine(szCmdLine, &dpvsetupParam))
  173. {
  174. MessageBox(NULL, _T("Bad Command Line Parameters"), _T("Error"), MB_OK|MB_ICONERROR);
  175. hr = DVERR_INVALIDPARAM;
  176. goto error_cleanup;
  177. }
  178. hResDLLInstance = LoadLibraryA(gc_szResDLLName);
  179. if (hResDLLInstance == NULL)
  180. {
  181. MessageBox(NULL, _T("Unable to load resource DLL - exiting program"), _T("Error"), MB_OK|MB_ICONERROR);
  182. hr = DVERR_GENERIC;
  183. goto error_cleanup;
  184. }
  185. if (dpvsetupParam.fPriority)
  186. {
  187. // This process is the one that opens dsound in
  188. // priority mode and sets the primary buffer to various
  189. // formats.
  190. // use SEH to clean up any really nasty errors
  191. __try
  192. {
  193. Diagnostics_Begin( fDiagnostics, "dpv_pri.txt" );
  194. hr = PriorityProcess(hResDLLInstance, hPrevInstance, szCmdLine, iCmdShow);
  195. Diagnostics_End();
  196. }
  197. __except(1)
  198. {
  199. hr = DVERR_GENERIC;
  200. }
  201. if( FAILED( hr ) )
  202. {
  203. goto error_cleanup;
  204. }
  205. }
  206. else if (dpvsetupParam.fFullDuplex)
  207. {
  208. // This process is the one that performs the full duplex
  209. // testing, in conjunction with the other process that
  210. // sets the primary buffer format.
  211. // use SEH to clean up any really nasty errors
  212. __try
  213. {
  214. Diagnostics_Begin( fDiagnostics, "dpv_fd.txt" );
  215. hr = FullDuplexProcess(hResDLLInstance, hPrevInstance, szCmdLine, iCmdShow);
  216. Diagnostics_End();
  217. }
  218. __except(1)
  219. {
  220. hr = DVERR_GENERIC;
  221. }
  222. if( FAILED( hr ) )
  223. {
  224. goto error_cleanup;
  225. }
  226. }
  227. else if (dpvsetupParam.fTest)
  228. {
  229. Diagnostics_Begin( fDiagnostics, "dpv_sup.txt" );
  230. // The user wants this program to run the whole test on the default
  231. // voice devices.
  232. hr = SupervisorCheckAudioSetup(&dpvsetupParam.guidRender, &dpvsetupParam.guidCapture, NULL, 0);
  233. Diagnostics_End();
  234. if( FAILED( hr ) )
  235. {
  236. goto error_cleanup;
  237. }
  238. }
  239. // With no command line parameters, this process does nothing.
  240. // You must know the secret handshake to get it to do something.
  241. // no error checking, since we're on our way out anyway
  242. FreeLibrary(hResDLLInstance);
  243. hResDLLInstance = NULL;
  244. DNOSIndirectionDeinit();
  245. fDNOSInitialized = FALSE;
  246. COM_CoUninitialize();
  247. fCoInitialized = FALSE;
  248. DPF_EXIT();
  249. return DV_OK;
  250. error_cleanup:
  251. if (hResDLLInstance != NULL)
  252. {
  253. FreeLibrary(hResDLLInstance);
  254. hResDLLInstance = NULL;
  255. }
  256. if (fDNOSInitialized == TRUE)
  257. {
  258. DNOSIndirectionDeinit();
  259. fDNOSInitialized = FALSE;
  260. }
  261. if (fCoInitialized == TRUE)
  262. {
  263. COM_CoUninitialize();
  264. fCoInitialized = FALSE;
  265. }
  266. DPF_EXIT();
  267. return hr;
  268. }