based on it, I want to write a function get device list, what's more need some friendly name, icon path and description.
Code: Select all
GetAllDevices() {
deviceEnumerator := IMMDeviceEnumerator()
deviceCollection := deviceEnumerator.EnumAudioEndpoints(2, 0xf) ; EDataFlow_enum_count and DEVICE_STATEMASK_ALL
deviceCount := deviceCollection.GetCount()
;@Debug-Output => {deviceCount}
devices := Array()
loop deviceCount {
;@Debug-Output => {A_Index}
device := deviceCollection.Item(A_Index - 1)
deviceId := device.GetId()
deviceState := device.GetState()
friendlyName:=""
description:=""
iconPath:=""
; Open the property store of the device
propertyStorePtr := device.OpenPropertyStore(0) ; STGM_READ
;@Debug-Output => {propertyStorePtr}
if (propertyStorePtr != 0) {
propertyStore := IPropertyStore(propertyStorePtr)
; Get the device's friendly name
friendlyNameKey := "{A45C254E-DF1C-4EFD-8020-67D146A850E0},14"
friendlyName := propertyStore.GetValue(friendlyNameKey)
; Get the device's description
descriptionKey := "{A45C254E-DF1C-4EFD-8020-67D146A850E0},2"
description := propertyStore.GetValue(descriptionKey)
; Get the device's icon path
iconPathKey := "{A45C254E-DF1C-4EFD-8020-67D146A850E0},15"
iconPath := propertyStore.GetValue(iconPathKey)
}
devObj := Object()
devObj.device := device
devObj.deviceId := deviceId
devObj.deviceState := deviceState
devObj.friendlyName:=friendlyName
devObj.description:=description
devObj.iconPath:=iconPath
devices.push(devObj)
}
;@Debug-Output => {devices.Length}
return devices
}
1. how to convert the "{A45C254E-DF1C-4EFD-8020-67D146A850E0},14" to a right numberError: Expected a Number but got a String.
▶ 240: Return (ComCall(5, this, "Ptr", key, "Ptr", pv := Buffer(A_PtrSize = 8 ? 24 : 16)), pv)
2. Does it have more PROPERTYKEY could use to GetValue()
2. Is there another right method to get some details of devices?
[Mod edit: Fixed URL tag. The actual URL goes after the equal sign inside the first tag and the description goes between the tags, not the other way around..]