Problem to get information of audio device with Audio.ahk by thpby

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Jacquesyip
Posts: 5
Joined: 18 May 2023, 22:16
Contact:

Problem to get information of audio device with Audio.ahk by thpby

09 May 2024, 04:19

I use the library @thpby Audio.ahk

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
}
I got an error when I GetValue() through propertyStore() , because GetValue() need a number
Error: Expected a Number but got a String.
▶ 240: Return (ComCall(5, this, "Ptr", key, "Ptr", pv := Buffer(A_PtrSize = 8 ? 24 : 16)), pv)
1. how to convert the "{A45C254E-DF1C-4EFD-8020-67D146A850E0},14" to a right number
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..]

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: emp00, songdg and 35 guests