| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include <WinAPICOM.au3>
- Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
- Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
- Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(int;int;ptr*);" & _
- "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
- "GetDevice hresult(wstr;ptr*);" & _
- "RegisterEndpointNotificationCallback hresult(ptr);" & _
- "UnregisterEndpointNotificationCallback hresult(ptr);"
- Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
- Global Const $tagIMMDevice = "Activate hresult(ptr;dword;variant*;ptr*);" & _
- "OpenPropertyStore hresult(dword;ptr*);" & _
- "GetId hresult(ptr*);" & _
- "GetState hresult(dword*);"
- Global Const $IID_IPropertyStore = "{886d8eeb-8cf2-4446-8d02-cdba1dbdcf99}"
- Global Const $tagIPropertyStore = "GetCount hresult(dword*);" & _
- "GetAt hresult(dword;ptr*);" & _
- "GetValue hresult(struct*;variant*);" & _
- "SetValue hresult(struct*;variant);" & _
- "Commit hresult();"
- Global Const $sPKEY_Device_FriendlyName = "{a45c254e-df1c-4efd-8020-67d146a850e0} 14"
- Global Const $STGM_READ = 0
- Global Const $DEVICE_STATE_ACTIVE = 0x00000001
- Global Const $eRender = 0
- Global Const $eCapture = 1
- Global Const $eAll = 2
- Global Const $EDataFlow_enum_count = 3
- Global Const $eConsole = 0
- Global Const $eMultimedia = 1
- Global Const $eCommunications = 2
- Global Const $ERole_enum_count = 3
- Func _WinAPI_PKEYFromString($sPKEY, $pID = Default)
- Local $tPKEY = DllStructCreate("byte GUID[16]; dword PID;")
- DllCall("propsys.dll", "long", "PSPropertyKeyFromString", "wstr", $sPKEY, "struct*", $tPKEY)
- If $pID <> Default Then DllStructSetData($tPKEY, "PID", $pID)
- Return $tPKEY
- EndFunc
- ;==========================================================
- Local $oEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
- Local $pDefaultEndpoint
- $oEnumerator.GetDefaultAudioEndpoint($eRender, $DEVICE_STATE_ACTIVE, $pDefaultEndpoint)
- Local $oEndpoint = ObjCreateInterface($pDefaultEndpoint, $IID_IMMDevice, $tagIMMDevice)
- ; PropertyStore stores properties
- Local $pProps
- $oEndpoint.OpenPropertyStore($STGM_READ, $pProps)
- $oProps = ObjCreateInterface($pProps, $IID_IPropertyStore, $tagIPropertyStore)
- ; Collect FriendlyName property
- Local $tPKEY_Device_FriendlyName = _WinAPI_PKEYFromString($sPKEY_Device_FriendlyName)
- Local $sName
- $oProps.GetValue($tPKEY_Device_FriendlyName, $sName)
- ConsoleWrite($sName & @CRLF)
|