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

The component's display name and/or index. For example, 1, "Line in" or "Line in:2".

If omitted or blank, an interface implemented by the device itself is retrieved.

For further details, see Component (Sound Functions).

Device

Type: String or Integer

The device's display name and/or index. For example, 1, "Speakers", "Speakers:2" or "Speakers (Example HD Audio)".

If this parameter is omitted, it defaults to the system's default device for playback (which is not necessarily device 1).

For further details, see Device (Sound Functions).

Return Value

Type: Integer or String (empty)

On success, the return value is an interface pointer.

On failure, the return value is an empty string.

Error Handling

An exception is thrown on failure. The exception's Message property may contain one of the following:

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 ComObject. The wrapped value (an object) can be passed directly to ComCall.

Interface := ComObject(13, InterfacePtr)

Related

Sound Functions, DeviceTopology API

Examples

#1: 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"