'Win32 C++ get Audio Subunits

I've been trying to Automate my Setup by having Keyboard Shortcuts for enabling Microphone monitoring Unmute the Rear Blue In Subunit. I first tried using Nirsofts SoundVolumeViewer, which allows command-line access to these Settings. And lists all Audio devices and Subunits

But there is always a startup delay when using the Software to mute/Unmute the device. So I figured the solution would be to write my own tool using the Windows Core Audio APIs. Which seemed promising until I tried to get the Subunit count for my IMMDevice which always returned 0. Sadly the documentation doesn't really mention how to enumerate the Subunits in any other way. Now I don't know if I'm approaching this the wrong way or missing something. So far I've used the mmdevice API to get my Realtek Speaker and tried to Activate the IDeviceTopology Output of my Programm

the function returning the Subunit Count

UINT getSubunits(IMMDevice* device) {
        IDeviceTopology* Topo;
        HRESULT res = device->Activate(__uuidof(IDeviceTopology), CLSCTX_ALL, NULL, (void**)&Topo);
        if (res != S_OK)
            return -1;
        UINT count;
        Topo->GetSubunitCount(&count);
        return count;
    }

I've also tried compiling with GCC and the Visual Studio Compiler but that wasn't the solution.

Does anybody know how you could achieve what I'm trying to do, or knows what I'm doing wrong?

I'm grateful for all input :)

Whole Code



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source