title: QT Include Windows SDK Library
body: <p>I am new to Qt and I want to use the <code>AudioSessionManager2</code> from the Windows SDK. In Qt Creator using <a href="https://docs.microsoft.com/en-us/windows/win32/medfound/managing-the-audio-session" rel="nofollow noreferrer">this example</a> I've written appended code below.</p>
  
  <p>When compiling I get the messages </p>
  
  <blockquote>
    <p>undefined reference to `__imp_CoCreateInstance'<br>
    undefined reference to `IID_IAudioSessionManager2'</p>
  </blockquote>
  
  <p>In the <a href="https://docs.microsoft.com/en-us/windows/win32/coreaudio/programming-reference" rel="nofollow noreferrer">documentation for the core audio APIs</a>, Microsoft states the APIs are implemented in Mmdevapi.dll and Audioses.dll. While I hoped to find two matching .lib files the SDK I downloaded with Visual Studio, I only found mmdevapi.lib. After copying it to my project and adding it to the qt project file like below I still had no success with the same error message.</p>
  
  <p>How am I supposed to know which lib files to import for which functions?<br>
  How do I get these lib files?<br>
  Did I import the lib file correctly?</p>
  
  <hr>
  
  <p><strong>audiomanager.h:</strong></p>
  
  <pre><code>#ifndef AUDIOMANAGER_H
  #define AUDIOMANAGER_H
  
  #include &lt;mmdeviceapi.h&gt;
  #include &lt;audiopolicy.h&gt;
  #include "utils/SafeRelease.h"
  
  
  class AudioManager {
  
  public:
      AudioManager();
      ~AudioManager();
  
  private:
      IAudioSessionManager2 *pSessionManager = nullptr;
      HRESULT init();
  
  
  };
  
  #endif // AUDIOMANAGER_H
  </code></pre>
  
  <p><strong>audiomanager.cpp</strong></p>
  
  <pre><code>#include "audiomanager.h"
  
  
  AudioManager::AudioManager () {
      this-&gt;init();
  }
  
  
  AudioManager::~AudioManager () {
      SafeRelease(&amp;pSessionManager);
  }
  
  
  
  HRESULT AudioManager::init () {
      HRESULT hr = S_OK;
  
      // initialize needed vars
      IMMDeviceEnumerator *pDeviceEnumerator = nullptr;
      IMMDevice *pDevice = nullptr;
  
      // get device enumerator
      hr = CoCreateInstance(
                  __uuidof(MMDeviceEnumerator),
                  nullptr,
                  CLSCTX_ALL,
                  IID_PPV_ARGS(&amp;pDeviceEnumerator)
                  );
      if (FAILED(hr))
          goto done;
  
      // get the default audio output (for consoles)
      // !!! only for consoles? (games, system, etc.), no  music, video
      pDeviceEnumerator-&gt;GetDefaultAudioEndpoint(eRender, eConsole, &amp;pDevice);
      if (FAILED(hr))
          goto done;
  
      // get the session manager
      hr = pDevice-&gt;Activate(
                  IID_IAudioSessionManager2,
                  CLSCTX_ALL,
                  nullptr,
                  reinterpret_cast&lt;void**&gt;(&amp;pSessionManager)
                  );
  
  done:
      SafeRelease(&amp;pDeviceEnumerator);
      SafeRelease(&amp;pDevice);
      return hr;
  }
  </code></pre>
  
  <p><strong>Line from Qt Project file</strong></p>
  
  <pre><code>LIBS += "$$PWD\..\libs\mmdevapi.lib"
  </code></pre>