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.

107 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. kmode.c
  5. Abstract:
  6. This module contains code to cause KMode NPx accesses
  7. Author:
  8. Environment:
  9. User mode only.
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. VOID
  14. KModeTouchNpx(
  15. VOID
  16. )
  17. {
  18. BOOLEAN bSuccess;
  19. bSuccess = KModeTouchNpxViaDSound();
  20. if (bSuccess == FALSE) {
  21. exit(1);
  22. }
  23. }
  24. BOOLEAN
  25. KModeTouchNpxViaDSound(
  26. VOID
  27. )
  28. {
  29. LPDIRECTSOUND ds;
  30. LPDIRECTSOUNDBUFFER dsc;
  31. DSBUFFERDESC dsbc;
  32. WAVEFORMATEX wfx;
  33. HRESULT hr;
  34. BYTE x[1024];
  35. PBYTE y;
  36. int i;
  37. ZeroMemory(&wfx, sizeof(wfx));
  38. wfx.wFormatTag = WAVE_FORMAT_PCM;
  39. wfx.nBlockAlign = 4;
  40. wfx.wBitsPerSample = 4;
  41. wfx.nSamplesPerSec = 44100;
  42. wfx.nAvgBytesPerSec = 44100 * 4;
  43. wfx.nChannels = 2;
  44. wfx.cbSize = 0;
  45. ds = NULL;
  46. dsc = NULL;
  47. memcpy(x, &wfx, sizeof(wfx));
  48. y = x + sizeof(wfx);
  49. for(i=0; i<200; i++) {
  50. *y = (BYTE) i;
  51. y++;
  52. }
  53. hr = DirectSoundCreate(NULL, &ds, NULL);
  54. if (ds == NULL) {
  55. fprintf(stderr, "DirectSoundCreate failed?!\n");
  56. return FALSE;
  57. }
  58. hr = ds->lpVtbl->SetCooperativeLevel(ds, GetDesktopWindow(), DSSCL_NORMAL);
  59. ZeroMemory(&dsbc, sizeof(dsbc));
  60. dsbc.dwBufferBytes = 10000;
  61. dsbc.dwFlags = 0;
  62. dsbc.dwSize = sizeof(dsbc);
  63. dsbc.lpwfxFormat = (LPWAVEFORMATEX) x;
  64. hr = ds->lpVtbl->CreateSoundBuffer(ds, &dsbc, &dsc, NULL);
  65. if (dsc) {
  66. hr = dsc->lpVtbl->Play(dsc, 0, 0, 0);
  67. dsc->lpVtbl->Release(dsc);
  68. }
  69. if (ds) {
  70. ds->lpVtbl->Release(ds);
  71. }
  72. return TRUE;
  73. }