title: Problems using Windows Core Audio APIs
body: <p>I've been trying to get a program working which uses the Windows audio APIs.
  The end result will be a programs that checks for volume changes in other audio process. 
  I've looked at some of the examples on the Microsoft site and have an undersatanding of what I should be doing.
  However when I attempt to implement this I get some errors. I'm starting by trying to get a list, well actually just a count at the minute, of all the audio process running.
  The code I'm using is based on the code on the Windows site however I get errors when I try to build it. The two main ones are:</p>
  
  <ol>
  <li>'IAudioSessionManager2' : no GUID has been associated with this object</li>
  <li>use of undefined type 'IAudioSessionManager2'</li>
  </ol>
  
  <p>There is also a similar one for the 2nd one but relating to IAudioSessionEnumerator.</p>
  
  <p>I'm quite new to C++ programming, more used to Java, so I'm thinking that it's just some silly little mistake to do with header files or something, I've included the .h code and .cpp code below.
  If anyone would be able to help me it would be much appreciated.</p>
  
  <p>GetProcess.h</p>
  
  <pre><code>#ifndef GETPROCESS_H
  #define GETPROCESS_H
  #define SAFE_RELEASE(p) { if ( (p) ) { (p)-&gt;Release(); (p) = 0; } }
  
  #include&lt;Audiopolicy.h&gt;
  #include&lt;Mmdeviceapi.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  
  using namespace std; 
  struct IAudioSessionManager2;
  struct IAudioSessionEnumerator;
  struct IAudioSessionControl;
  struct IMMDevice;
  struct IMMDeviceEnumerator;
  
  ref class GetProcess
  {
  public:
      GetProcess();
  };
  #endif
  </code></pre>
  
  <p>GetProcess.cpp</p>
  
  <pre><code>#include "StdAfx.h"
  #include "GetProcess.h"
  #include&lt;Audiopolicy.h&gt;
  #include&lt;Mmdeviceapi.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  
  GetProcess::GetProcess()
  {
      IMMDeviceEnumerator* deviceEnumerator = NULL;
      IMMDevice* device = NULL;
      IAudioSessionManager2* sessionManager = NULL;
      IAudioSessionEnumerator* sessionEnumerator = NULL;
      IAudioSessionControl* session = NULL;
  
  
      int numberOfProcesses = 0;
      int numberOfActiveProcesses = 0;
  
      AudioSessionState state;
  
      //create device enumerator
      CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&amp;deviceEnumerator);
      // get default device
      deviceEnumerator-&gt;GetDefaultAudioEndpoint(eRender, eConsole, &amp;device);
  
      // activate session manager
      device-&gt;Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&amp;sessionManager);
      //// make enum
      sessionManager-&gt;GetSessionEnumerator(&amp;sessionEnumerator);
      sessionEnumerator -&gt;GetCount(&amp;numberOfProcesses);
      for (int i = 0; i &lt; numberOfProcesses; i++)
      {
          sessionEnumerator-&gt;GetSession(i, &amp;session);
          session-&gt;GetState(&amp;state);
          if (state == 1)
          {
              numberOfActiveProcesses++;
          }
          SAFE_RELEASE(session);
      }
  
      //CLEANUP
  
      SAFE_RELEASE(deviceEnumerator);
      SAFE_RELEASE(device);
      SAFE_RELEASE(sessionEnumerator);
      SAFE_RELEASE(sessionManager);
  }
  </code></pre>