I am writing this library that implements some of the basic functions of an audio player in C ++ / CLI through the Media Foundation environment, which will be consumed by managed code. I can play sound, pause, pause, etc. For those new to the Media Foundation, a media session publishes events that you can process for notifications. This is done by calling BeginGetEvent on a session object with an IMFAsyncCallback object. IMFAsyncCallback defines the Invoke method (IMFAsyncResult) that should be implemented to handle events. When an event occurs, the call method is called by the session object in the workflow with the IMFAsyncResult object, which you can request for information about the event. This result object is created and belongs to the flow of events.
In my Invoke implementation, when I try to do something (including just calling QueryInterface or something else) with the IMFAsyncResult object that I passed, I get a System.AccessViolationException. The object that I am implementing IMFAsyncCallback is the C ++ base class (unmanaged) allocated on the CRT heap, and events are placed on the thread belonging to the session object also allocated on the CRT heap.
Steve whitfield
source share