'I get an error while trying to call IAudioClient::GetService()

I get these errors when I'm trying to compile the program:

image

I can get rid of error LNK2001 by using __uuidof(IChannelAudioVolume), but in the documentation it says I should be able to use IID_IChannelAudioVolume.

This is my code:

#include <iostream>
#include <Windows.h>
#include <Audioclient.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>

using namespace std;

int main() {
    //defining valiables
    HRESULT hr;
    UINT32 Channel_count = 0;
    IAudioClient* aClient = nullptr;
    IChannelAudioVolume* pAudioControls = nullptr;

    aClient->IAudioClient::GetService(IID_IChannelAudioVolume, (void**)pAudioControls);

    //hr = pAudioControls->GetChannelCount(&Channel_count);

    delete aClient;
    delete pAudioControls;
    return 0;
}

edit:

So i found, that i need to call Initialize() func, but it doesn't change anything. I also tried looking it up, but i don't know what should my aClient be (what other functions should i call to change it). Also here is Output picture with error.

*The same error with aClient beeing nullptr occurs

Code:

#include <Windows.h>
#include <Audioclient.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>

using namespace std;

int main() {
    //defining valiables
    HRESULT hr;
    UINT32 Channel_count = 0;
    IAudioClient* aClient = nullptr;
    IChannelAudioVolume* pAudioControls = nullptr;
    WAVEFORMATEX *wf = nullptr;


    hr = aClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, 10000, 0, wf, NULL);
    
    if (!SUCCEEDED(hr)) {
        cout << "Error while initializing\n";
        return -1;
    }
    cout << "Initialization successfull\n";
    



    aClient->IAudioClient::GetService(__uuidof(IChannelAudioVolume), (void**)pAudioControls);

    pAudioControls->GetChannelCount(&Channel_count);


    aClient->Release();
    pAudioControls->Release();
    return 0;
}


Sources

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

Source: Stack Overflow

Solution Source