title: How do I use get access to audio devices through the MMDevice API?
body: <p>I am trying to manage the audio streams with a program, but I am having trouble even getting access to an audio device. As a side note I am new to C++ and I learned coding in Java so I'm new to the idea of pointers as well as the ideas of the HRESULT and other windows stuff. On <a href="https://docs.microsoft.com/en-us/windows/desktop/coreaudio/stream-management" rel="nofollow noreferrer">this</a> page it says that I must first enumerate an audio endpoint device. I then did some more searching to find out how to do so and was lead to the <a href="https://docs.microsoft.com/en-us/windows/desktop/CoreAudio/enumerating-audio-devices" rel="nofollow noreferrer">Enumerating Audio Devices</a> page. That page told me to use the <a href="https://docs.microsoft.com/en-us/windows/desktop/CoreAudio/mmdevice-api" rel="nofollow noreferrer">MMDevice API</a>. This page shows this code:</p>
  
  <pre><code>const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
  const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
  hr = CoCreateInstance(
       CLSID_MMDeviceEnumerator, NULL,
       CLSCTX_ALL, IID_IMMDeviceEnumerator,
       (void**)&amp;amp;pEnumerator);
  </code></pre>
  
  <p>I tried to use this and the </p>
  
  <pre><code>(void**)&amp;amp;pEnumerator
  </code></pre>
  
  <p>did not work, so I found some other code that used a </p>
  
  <pre><code>reinterpret_cast&lt;&gt;();
  </code></pre>
  
  <p>in order to deal with this error. But the problem that I am running into is that I am not getting a pointer. My code is below.</p>
  
  <pre><code>CoInitializeEx(NULL, COINIT_MULTITHREADED);
  
  IMMDeviceEnumerator *pEnumerator;
  
  const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
  const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
  
  //print CLSID to see if I get any ids
  std::cout &lt;&lt; CLSID_MMDeviceEnumerator.Data1 &lt;&lt; "\n";
  std::cout &lt;&lt; CLSID_MMDeviceEnumerator.Data2 &lt;&lt; "\n";
  std::cout &lt;&lt; CLSID_MMDeviceEnumerator.Data3 &lt;&lt; "\n";
  std::cout &lt;&lt; CLSID_MMDeviceEnumerator.Data4 &lt;&lt; "\n";
  
  //temp variable to hold the result of the CoCreateInstance call
  LPVOID *ppv = NULL;
  
  HRESULT retrivedDeviceEnumerator = CoCreateInstance(
      CLSID_MMDeviceEnumerator,
      NULL,
      CLSCTX_ALL,
      IID_IMMDeviceEnumerator,
      ppv
  );
  //I'm sure there is a better way to print and end the line
  //print mem location to see if I am getting a result
  std::cout &lt;&lt; ppv &lt;&lt; "\n";
  //cast the result to correct type
  pEnumerator = (reinterpret_cast&lt;IMMDeviceEnumerator*&gt;(ppv));
  </code></pre>
  
  <p>This code prints some numbers for the CLSID lines so I think that those are getting the correct values, but I am getting 00000000 when I print the ppv pointer.</p>