Platform SDK: DirectX |
The information in this section pertains only to applications written in C and C++. See DirectDraw Visual Basic Tutorials.
When you press the F12 key, the DDEx1 application processes the WM_DESTROY message before exiting the application. This message calls the ReleaseAllObjects sample function, which contains all of the IUnknown::Release calls, as shown in the following example.
static void ReleaseAllObjects(void) { if (g_pDD != NULL) { if (g_pDDSPrimary != NULL) { g_pDDSPrimary->Release(); g_pDDSPrimary = NULL; } g_pDD->Release(); g_pDD = NULL; } }
The application checks if the pointers to the DirectDraw object (g_pDD) and the DirectDrawSurface object (g_pDDSPrimary) are not equal to NULL. Then DDEx1 calls the IDirectDrawSurface7::Release method to decrease the reference count of the DirectDrawSurface object by 1. Because this brings the reference count to 0, the DirectDrawSurface object is deallocated. The DirectDrawSurface pointer is then destroyed by setting its value to NULL. Next, the application calls IDirectDraw7::Release to decrease the reference count of the DirectDraw object to 0, deallocating the DirectDraw object. This pointer is then also destroyed by setting its value to NULL.