Microsoft DirectX 9.0

Step 5: Shutting Down

At some point during execution, your application must shut down. Shutting down a Microsoft?DirectX?application not only means that you destroy the application window, but you also deallocate any DirectX objects your application uses, and you invalidate the pointers to them. The CreateDevice sample project calls Cleanup, an application-defined function to handle this when it receives a WM_DESTROY message.

VOID Cleanup()
    if( g_pd3dDevice != NULL)
    if( g_pD3D != NULL)

The preceding function deallocates the DirectX objects it uses by calling the IUnknown::Release methods for each object. Because this tutorial follows COM rules, the reference count for most objects should become zero and should be automatically removed from memory.

In addition to shutdown, there are times during normal execution—such as when the user changes the desktop resolution or color depth—when you might need to destroy and re-create the Microsoft Microsoft Direct3D?objects in use. Therefore it is a good idea to keep your application's cleanup code in one place, which can be called when the need arises.

This tutorial has shown you how to create a device. Tutorial 2: Rendering Vertices shows you how to use vertices to draw geometric shapes.

© 2002 Microsoft Corporation. All rights reserved.