That ton is more work than you need.
You just need to write a class that derives from IAudioSessionNotifications - you do not need to write the entire COM object and register it.
You should also use the eConsole role instead of the eMultimedia role. It doesn't really matter (if you only have one audio device), but it is more correct.
The destructor of the CustomAudioNotification class must be closed - this way you will prevent accidental destruction. Therefore, I would write:
CustomAudioNotification *customNotification = new CustomAudioNotification(); SESSION->RegisterSessionNotification(customNotification);
I also assume that you initialized COM before your code snippet.
UPDATED: Kevin sent me his application, and there are several other problems related to its application that are more fundamental (I am working on improving the documentation for the API to prevent confusion in the future)
First, his application did not retrieve the current list of sessions. This is one of the very subtle features of the session APIs. To prevent a race condition that may occur when a session notification arrives when an application using the session APIs is started, the session listing API discards new session notifications until the application receives a list of existing sessions.
Expected usage pattern:
The application activates the session manager 2. Application registers for session notifications. The application retrieves the current session list for the endpoint and stores the session management objects in the list (do not forget to add a session to the session).
When a new session is created, the application accepts the link to the newly created session management object and inserts it into the list if it is not already present. Note that the session control object passed to the notification will be destroyed when the session notification returns - if you call GetSessionEnumerator at that moment, it will probably NOT have a newly created session (it may all depend on the time).
The application manages the session lifetime based on its own criteria - as long as the application has a link to the session management, the session management object will be valid. There is no expiration mechanism for audio connection objects.
In addition, the session APIs require the MTA to be initialized - this is unfortunate, but since we create COM objects (which implement the IAudioSessionControl) in the workflow, the API requires the MTA to be created before the notification is received.