Platform SDK: DirectX

Sample Function 2: DI_Term

[Visual Basic]

The information in this topic pertains only to applications written in C++. See DirectInput Visual Basic Tutorials.

[C++]

This application-defined sample function deallocates existing DirectInput interface pointers in preparation for program shutdown or in the event of a failure to properly initialize a device.

/* The following variables are presumed initialized:
LPDIRECTINPUT7        g_lpDI; 
LPDIRECTINPUTDEVICE7  g_lpDIDevice; 
*/
 
void WINAPI DI_Term() 
{ 
    if (g_lpDI) 
    { 
        if (g_lpDIDevice) 
        { 
            /* 
Always unacquire device before calling Release().              */
             g_lpDIDevice->Unacquire(); 
             g_lpDIDevice->Release();
             g_lpDIDevice = NULL; 
        } 
        g_lpDI->Release();
        g_lpDI = NULL; 
    } 
}