Step 4: Close Down
To exit an audio application cleanly, you must perform five main steps:
- Stop any playing segments by calling IDirectMusicPerformance8::Stop.
- Unload any segments that were downloaded to the synthesizer.
- Close down the performance. The IDirectMusicPerformance8::CloseDown method performs miscellaneous cleanup tasks and releases internal references to objects.
- Release all interfaces.
- 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.