sandbox.au3 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <WinAPICOM.au3>
  2. Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
  3. Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
  4. Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(int;int;ptr*);" & _
  5. "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
  6. "GetDevice hresult(wstr;ptr*);" & _
  7. "RegisterEndpointNotificationCallback hresult(ptr);" & _
  8. "UnregisterEndpointNotificationCallback hresult(ptr);"
  9. Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
  10. Global Const $tagIMMDevice = "Activate hresult(ptr;dword;variant*;ptr*);" & _
  11. "OpenPropertyStore hresult(dword;ptr*);" & _
  12. "GetId hresult(ptr*);" & _
  13. "GetState hresult(dword*);"
  14. Global Const $IID_IPropertyStore = "{886d8eeb-8cf2-4446-8d02-cdba1dbdcf99}"
  15. Global Const $tagIPropertyStore = "GetCount hresult(dword*);" & _
  16. "GetAt hresult(dword;ptr*);" & _
  17. "GetValue hresult(struct*;variant*);" & _
  18. "SetValue hresult(struct*;variant);" & _
  19. "Commit hresult();"
  20. Global Const $sPKEY_Device_FriendlyName = "{a45c254e-df1c-4efd-8020-67d146a850e0} 14"
  21. Global Const $STGM_READ = 0
  22. Global Const $DEVICE_STATE_ACTIVE = 0x00000001
  23. Global Const $eRender = 0
  24. Global Const $eCapture = 1
  25. Global Const $eAll = 2
  26. Global Const $EDataFlow_enum_count = 3
  27. Global Const $eConsole = 0
  28. Global Const $eMultimedia = 1
  29. Global Const $eCommunications = 2
  30. Global Const $ERole_enum_count = 3
  31. Func _WinAPI_PKEYFromString($sPKEY, $pID = Default)
  32. Local $tPKEY = DllStructCreate("byte GUID[16]; dword PID;")
  33. DllCall("propsys.dll", "long", "PSPropertyKeyFromString", "wstr", $sPKEY, "struct*", $tPKEY)
  34. If $pID <> Default Then DllStructSetData($tPKEY, "PID", $pID)
  35. Return $tPKEY
  36. EndFunc
  37. ;==========================================================
  38. Local $oEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
  39. Local $pDefaultEndpoint
  40. $oEnumerator.GetDefaultAudioEndpoint($eRender, $DEVICE_STATE_ACTIVE, $pDefaultEndpoint)
  41. Local $oEndpoint = ObjCreateInterface($pDefaultEndpoint, $IID_IMMDevice, $tagIMMDevice)
  42. ; PropertyStore stores properties
  43. Local $pProps
  44. $oEndpoint.OpenPropertyStore($STGM_READ, $pProps)
  45. $oProps = ObjCreateInterface($pProps, $IID_IPropertyStore, $tagIPropertyStore)
  46. ; Collect FriendlyName property
  47. Local $tPKEY_Device_FriendlyName = _WinAPI_PKEYFromString($sPKEY_Device_FriendlyName)
  48. Local $sName
  49. $oProps.GetValue($tPKEY_Device_FriendlyName, $sName)
  50. ConsoleWrite($sName & @CRLF)