Microsoft DirectX 9.0

Step 4: Close Down

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

  1. Stop any playing segments by calling IDirectMusicPerformance8::Stop.
  2. Close down the performance. The IDirectMusicPerformance8::CloseDown method performs miscellaneous cleanup tasks and releases internal references to objects.
  3. Release all interfaces.
  4. 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_pPerformance->CloseDown();
 
  g_pLoader->Release(); 
  g_pPerformance->Release();
  g_pSegment->Release();
 
  CoUninitialize();
    
  return 0;  // Return value for WinMain.
}      // End of WinMain.