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.

133 lines
4.6 KiB

  1. #include <windows.h>
  2. #include <devioctl.h>
  3. #include <ks.h>
  4. #include <ksmediap.h>
  5. #include "debug.h"
  6. #include "sad.h"
  7. extern "C" HANDLE hHeap;
  8. LONG SadAddGfxToZoneGraph(HANDLE hSad, HANDLE hGfx, PCTSTR GfxFriendlyName, PCTSTR ZoneFactoryDi, ULONG Type, ULONG Order)
  9. {
  10. KSPROPERTY Property;
  11. PSYSAUDIO_GFX pSadGfx;
  12. ULONG cbSadGfx;
  13. PTSTR pZoneFactoryDi;
  14. ULONG cbZoneFactoryDi;
  15. PTSTR pGfxFriendlyName;
  16. ULONG cbGfxFriendlyName;
  17. DWORD cbBytesReturned;
  18. LONG lresult;
  19. ASSERT(!IsBadStringPtr(GfxFriendlyName, 5000));
  20. ASSERT(!IsBadStringPtr(ZoneFactoryDi, 5000));
  21. Property.Set = KSPROPSETID_Sysaudio;
  22. Property.Id = KSPROPERTY_SYSAUDIO_ADDREMOVE_GFX;
  23. Property.Flags = KSPROPERTY_TYPE_SET;
  24. cbGfxFriendlyName = (lstrlen(GfxFriendlyName)+1) * sizeof(GfxFriendlyName[0]);
  25. cbZoneFactoryDi = (lstrlen(ZoneFactoryDi)+1) * sizeof(ZoneFactoryDi[0]);
  26. cbSadGfx = sizeof(*pSadGfx) + cbGfxFriendlyName + cbZoneFactoryDi;
  27. pSadGfx = (PSYSAUDIO_GFX)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, cbSadGfx);
  28. if (pSadGfx) {
  29. pSadGfx->Enable = TRUE;
  30. pSadGfx->hGfx = hGfx;
  31. pSadGfx->ulOrder = Order;
  32. pSadGfx->ulType = Type;
  33. pSadGfx->ulFlags = 0;
  34. pZoneFactoryDi = (PTSTR)(pSadGfx+1);
  35. lstrcpy(pZoneFactoryDi, ZoneFactoryDi);
  36. pSadGfx->ulDeviceNameOffset = (ULONG)((PBYTE)pZoneFactoryDi - (PBYTE)pSadGfx);
  37. pGfxFriendlyName = pZoneFactoryDi + lstrlen(pZoneFactoryDi) + 1;
  38. lstrcpy(pGfxFriendlyName, GfxFriendlyName);
  39. pSadGfx->ulFriendlyNameOffset = (ULONG)((PBYTE)pGfxFriendlyName - (PBYTE)pSadGfx);
  40. ASSERT((PBYTE)(pGfxFriendlyName + lstrlen(pGfxFriendlyName) + 1) == ((PBYTE)pSadGfx) + cbSadGfx);
  41. if (DeviceIoControl(hSad, IOCTL_KS_PROPERTY,
  42. &Property, sizeof(Property),
  43. pSadGfx, cbSadGfx,
  44. &cbBytesReturned, NULL))
  45. {
  46. lresult = ERROR_SUCCESS;
  47. } else {
  48. // ISSUE-200/09/21-FrankYe Shoule we get other data regarding failure?
  49. lresult = GetLastError();
  50. }
  51. HeapFree(hHeap, 0, pSadGfx);
  52. } else {
  53. lresult = ERROR_OUTOFMEMORY;
  54. }
  55. return lresult;
  56. }
  57. LONG SadRemoveGfxFromZoneGraph(HANDLE hSad, HANDLE hGfx, PCTSTR GfxFriendlyName, PCTSTR ZoneFactoryDi, ULONG Type, ULONG Order)
  58. {
  59. KSPROPERTY Property;
  60. PSYSAUDIO_GFX pSadGfx;
  61. ULONG cbSadGfx;
  62. PTSTR pZoneFactoryDi;
  63. ULONG cbZoneFactoryDi;
  64. PTSTR pGfxFriendlyName;
  65. ULONG cbGfxFriendlyName;
  66. ULONG cbBytesReturned;
  67. LONG lresult;
  68. ASSERT(!IsBadStringPtr(GfxFriendlyName, 5000));
  69. ASSERT(!IsBadStringPtr(ZoneFactoryDi, 5000));
  70. Property.Set = KSPROPSETID_Sysaudio;
  71. Property.Id = KSPROPERTY_SYSAUDIO_ADDREMOVE_GFX;
  72. Property.Flags = KSPROPERTY_TYPE_SET;
  73. cbGfxFriendlyName = (lstrlen(GfxFriendlyName)+1) * sizeof(GfxFriendlyName[0]);
  74. cbZoneFactoryDi = (lstrlen(ZoneFactoryDi)+1) * sizeof(ZoneFactoryDi[0]);
  75. cbSadGfx = sizeof(*pSadGfx) + cbGfxFriendlyName + cbZoneFactoryDi;
  76. pSadGfx = (PSYSAUDIO_GFX)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, cbSadGfx);
  77. if (pSadGfx) {
  78. pSadGfx->Enable = FALSE;
  79. pSadGfx->hGfx = hGfx;
  80. pSadGfx->ulOrder = Order;
  81. pSadGfx->ulType = Type;
  82. pSadGfx->ulFlags = 0;
  83. pZoneFactoryDi = (PTSTR)(pSadGfx+1);
  84. lstrcpy(pZoneFactoryDi, ZoneFactoryDi);
  85. pSadGfx->ulDeviceNameOffset = (ULONG)((PBYTE)pZoneFactoryDi - (PBYTE)pSadGfx);
  86. pGfxFriendlyName = pZoneFactoryDi + lstrlen(pZoneFactoryDi) + 1;
  87. lstrcpy(pGfxFriendlyName, GfxFriendlyName);
  88. pSadGfx->ulFriendlyNameOffset = (ULONG)((PBYTE)pGfxFriendlyName - (PBYTE)pSadGfx);
  89. ASSERT((PBYTE)(pGfxFriendlyName + lstrlen(pGfxFriendlyName) + 1) == ((PBYTE)pSadGfx) + cbSadGfx);
  90. if (DeviceIoControl(hSad, IOCTL_KS_PROPERTY,
  91. &Property, sizeof(Property),
  92. pSadGfx, cbSadGfx,
  93. &cbBytesReturned, NULL))
  94. {
  95. lresult = ERROR_SUCCESS;
  96. } else {
  97. // ISSUE-200/09/21-FrankYe Shoule we get other data regarding failure?
  98. lresult = GetLastError();
  99. }
  100. HeapFree(hHeap, 0, pSadGfx);
  101. } else {
  102. lresult = ERROR_OUTOFMEMORY;
  103. }
  104. return lresult;
  105. }