Microsoft DirectX 8.1 (Visual Basic)

Step 4: Shutting Down

At some point during execution, your application must shut down. When shutting down a Microsoft® DirectX® application, you need to disassociate any DirectX objects your application used by setting them to Nothing. The CreateDevice sample project calls Cleanup, an application-defined function, to handle this cleanup. Cleanup is called from Form_Unload when the form is unloading.

Private Sub Form_Unload(Cancel As Integer)

    Set g_D3D = Nothing
    Set g_D3DDevice = Nothing

End Sub

The preceding function sets its Microsoft Direct3D® objects to Nothing, which in turn disassociates the variable from the actual object. In addition to shut down, 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 Direct3D objects in use. As a result, it's handy 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.