title: IAudioSessionManager2 notifications not sent
body: <p>I'm trying to monitor new audio sessions via Windows 7's IAudioSessionManager2 COM interface (coupled with IAudioSessionNotification).  Currently, IAudioSessionNotification::OnSessionCreated() is never called and I've run out of ideas as to why.</p>
  
  <p>Code registering custom IAudioSessionNotification:</p>
  
  <pre><code>#define SAFE_RELEASE(comObj) \
  if(comObj != NULL) \
      { (comObj)-&gt;Release(); comObj = NULL; }
  
  BOOL success = false;
  
  HRESULT res;
  IClassFactory* pFactory;
  IMMDevice* pDevice;
  IMMDeviceEnumerator* pEnumerator;
  
  SESSION_LISTENER = NULL;
  SESSION = NULL;
  
  res = CoInitialize(NULL);
  
  if(res != S_OK &amp;&amp; res != S_FALSE)
      return false;
  
  res = CoGetClassObject(CLSID_CustomAudioFactory, CLSCTX_ALL, NULL, __uuidof(IClassFactory), (void**)&amp;pFactory);
  if(res != S_OK)  goto Exit;
  
  res = pFactory-&gt;CreateInstance(NULL, CLSID_CustomAudioNotifications, (void**)&amp;SESSION_LISTENER);
  if(res != S_OK)  goto Exit;
  
  res = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&amp;pEnumerator);
  if(res != S_OK)  goto Exit;
  
  res = pEnumerator-&gt;GetDefaultAudioEndpoint(eRender, eMultimedia, &amp;pDevice);
  if(res != S_OK)  goto Exit;
  
  res = pDevice-&gt;Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&amp;SESSION);
  if(res != S_OK)  goto Exit;
  
  res = SESSION-&gt;RegisterSessionNotification(SESSION_LISTENER);
  if(res != S_OK)  goto Exit;
  
  success = true;
  
  Exit:
  SAFE_RELEASE(pFactory);
  SAFE_RELEASE(pEnumerator);
  SAFE_RELEASE(pDevice);
  if(!success)
  {
      SAFE_RELEASE(SESSION_LISTENER);
      SAFE_RELEASE(SESSION);
  }
  </code></pre>
  
  <p>CustomAudioNotifications declaration:</p>
  
  <pre><code>class CustomAudioNotifications : public IAudioSessionNotification
  {
  public:
  //Constructors
  CustomAudioNotifications()  { InterlockedIncrement(&amp;g_notifyCount); m_listener = NULL; }
  ~CustomAudioNotifications() { InterlockedDecrement(&amp;g_notifyCount); SAFE_RELEASE(m_listener); }
  
  //IUnknown interface
  HRESULT __stdcall QueryInterface(
                              REFIID riid ,
                              void **ppObj);
  ULONG   __stdcall AddRef();
  ULONG   __stdcall Release();
  
  //Notification
  HRESULT __stdcall OnSessionCreated(IAudioSessionControl *NewSession);
  
  private:
  LONG m_nRefCount;
  };
  </code></pre>
  
  <p>OnSessionCreated just posts a message to a window whenever a session is created for the time being; which never happens.  Just in case my assumptions are totally off base, I'm expecting a notification whenever an application that has yet to play audio starts to do so; so launching VLC with a video file should immediately result in a notice, while visiting Pandora via a web browser would also trigger such a notice.</p>
  
  <p>Debugging shows all returned values are S_OK.</p>
  
  <p>My COM experience is pretty limitted, so pointing out general "WTFs?" would also be appreciated.</p>