SoundGetInterface

Retrieves a native COM interface of a sound device or component.

InterfacePtr := SoundGetInterface(IID, Component, Device)

Parameters

IID

Type: String

An interface identifier (GUID) in the form "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}".

Component

Type: String or Integer

If blank or omitted, an interface implemented by the device itself will be retrieved. Otherwise, specify the component's display name and/or index, e.g. 1, "Line in" or "Line in:2".

For further details, see Component (Sound Functions).

Device

Type: String or Integer

If blank or omitted, it defaults to the system's default device for playback (which is not necessarily device 1). Otherwise, specify the device's display name and/or index, e.g. 1, "Speakers", "Speakers:2" or "Speakers (Example HD Audio)".

For further details, see Device (Sound Functions).

Return Value

Type: Integer

On success, the return value is an interface pointer.

If the interface is not supported, the return value is zero.

Error Handling

A TargetError is thrown if the device or component could not be found. Otherwise, an OSError is thrown on failure.

Remarks

The interface is retrieved from one of the following sources:

Once the interface pointer is retrieved, ComCall can be used to call its methods. Refer to the Windows SDK header files to identify the correct method index.

The interface pointer must be released by passing it to ObjRelease when it is no longer needed. This can be done by "wrapping" it with ComValue. The wrapped value (an object) can be passed directly to ComCall.

Interface := ComValue(13, InterfacePtr)

Sound Functions, DeviceTopology API

Examples

Peak meter. A tooltip is displayed with the current peak value, except when the peak value is zero (no sounds are playing).

; IAudioMeterInformation
audioMeter := SoundGetInterface("{C02216F6-8C67-4B5B-9D00-D008E73E0064}")
if audioMeter
{
    try loop  ; Until the script exits or an error occurs.
    {
        ; audioMeter->GetPeakValue(&peak)
        ComCall 3, audioMeter, "float*", &peak:=0
        ToolTip peak > 0 ? peak : ""
        Sleep 15
    }
    ObjRelease audioMeter
}
else
    MsgBox "Unable to get audio meter"