Microsoft DirectX 9.0 SDK Update (October 2004)

Step 4: Close Down

To exit an audio application cleanly, you must perform five main steps:

  1. Stop any playing segments by calling IDirectMusicPerformance8::Stop.
  2. Unload any segments that were downloaded to the synthesizer.
  3. Close down the performance. The IDirectMusicPerformance8::CloseDown method performs miscellaneous cleanup tasks and releases internal references to objects.
  4. Release all interfaces.
  5. Close COM.

The following code from the WinMain function in the tutorial sample is called when the dialog box is closed.

  g_pPerformance->Stop(
      NULL, // Stop all segments.
      NULL, // Stop all segment states.
      0,    // Do it immediately.
      0     // Flags.
  );
 
  g_pSegment->Unload(g_pPerformance);
  g_pPerformance->CloseDown();
 
  g_pLoader->Release(); 
  g_pPerformance->Release();
  g_pSegment->Release();
 
  CoUninitialize();
    
  return 0;  // Return value for WinMain.
}      // End of WinMain.

© 2004 Microsoft Corporation. All rights reserved.