Windows API method “IAudioSessionControl::GetDisplayName” returning empty pointer

I have all of my headphone’s audio sessions in a list of IAudioSessionControls and, through a loop, am trying to get the names, GUIDs, and states of each of them. The problem is that when I run the GetDisplayName method, I get only blank spaces, except for the session at index 0 which I believe is System Sounds. The GetState method also sometimes returns null pointers if that is any help. Here is the code of said loop:

ArrayList<IAudioSessionControl> Sessionz = new ArrayList<>();
// loop through all sessions and add to array
for (int sesh = 0; sesh < SessionCount.getValue(); sesh++) {
    PointerByReference tempSession = new PointerByReference();
    IEnum.GetSession(tempSession, sesh);
    Sessionz.add(new IAudioSessionControl(tempSession.getValue()));
}
System.out.println();
String lotsOfDashes = "--------------------------------------";
System.out.println("Session Loop Starts Here !");
System.out.println(lotsOfDashes);
for (IAudioSessionControl sess : Sessionz) {
    System.out.println("Session " + Sessionz.indexOf(sess));
    sess.GetDisplayName(sess.sName);
    sess.GetGroupingParam(sess.sGuid);
    sess.GetState(sess.sState);
    System.out.println(
            "Name: " + sess.sName.getValue().getWideString(0) + " | Pointer: " + sess.sName.getValue());

    System.out.println("GUID: " + sess.sGuid.toGuidString());
    System.out.println("State: " + sess.sState.getValue());
    System.out.println(lotsOfDashes);
}

And here is the output of the loop:

Session Loop Starts Here !
--------------------------------------
Session 0
Name: @%SystemRoot%\System32\AudioSrv.Dll,-202 | Pointer: native@0x20bfab57240
GUID: {55EAF804-0C7F-46EF-85A3-7F75F087EBEF}
State: null
--------------------------------------
Session 1
Name:  | Pointer: native@0x20bfab6a740
GUID: {9572A46A-71C8-4CB4-B5F5-D74264A319C8}
State: native@0x1
--------------------------------------
Session 2
Name:  | Pointer: native@0x20bfab6a970
GUID: {97EFF8AD-BFCC-45E2-A95E-B40C83C23F02}
State: null
--------------------------------------
Session 3
Name:  | Pointer: native@0x20bfab6a830
GUID: {BFFF6080-5CC4-4134-AB0E-7B571C889C3D}
State: native@0x1
--------------------------------------
Session 4
Name:  | Pointer: native@0x20bfab6a820
GUID: {FE89E3EF-83B9-40BE-B3B9-1AA952C89EC3}
State: null
--------------------------------------

If necessary, here is my IAudioSessionControl class:

class IAudioSessionControl extends Unknown {
    PointerByReference sName = new PointerByReference();
    PointerByReference sState = new PointerByReference();
    GUID.ByReference sGuid = new GUID.ByReference();

    public IAudioSessionControl(Pointer p) {
        super(p);
    }

    public HRESULT GetGroupingParam(GUID pRetVal) {
        HRESULT res = (HRESULT) _invokeNativeObject(8, new Object[] { getPointer(), pRetVal }, HRESULT.class);
        COMUtils.checkRC(res);
        return res;
    }

    public HRESULT GetDisplayName(PointerByReference pRetVal) {
        HRESULT res = (HRESULT) _invokeNativeObject(4, new Object[] { getPointer(), pRetVal }, HRESULT.class);
        COMUtils.checkRC(res);
        return res;
    }

    public HRESULT GetState(PointerByReference pRetVal) {
        HRESULT res = (HRESULT) _invokeNativeObject(3, new Object[] { getPointer(), pRetVal }, HRESULT.class);
        COMUtils.checkRC(res);
        return res;
    }
}

Also my IAudioSessionEnumerator class:

class IAudioSessionEnumerator extends Unknown {
    public IAudioSessionEnumerator(Pointer p) {
        super(p);
    }

    public HRESULT GetCount(IntByReference SessionCount) {
        HRESULT res = (HRESULT) _invokeNativeObject(3, new Object[] { getPointer(), SessionCount }, HRESULT.class);
        COMUtils.checkRC(res);
        return res;
    }

    public HRESULT GetSession(PointerByReference Session, int SessionCount) {
        HRESULT res = (HRESULT) _invokeNativeObject(4, new Object[] { getPointer(), SessionCount, Session },
                HRESULT.class);
        COMUtils.checkRC(res);
        return res;
    }
}

Leave a Comment