Starting Device Enumeration

Applications can query the hardware they run on to detect which types of Direct3D devices it supports. The most important API element in this task is IDirect3D3::EnumDevices, which enumerates all of the Direct3D devices that the hardware is capable of supporting. It invokes the D3DEnumDevicesCallback function to select the device that will be used. The D3DEnumDevicesCallback function is supplied by you in your application. Note that because this callback function is supplied by your application, its name can be anything you want.

The following code fragment illustrates the process of enumerating and selecting a Direct3D device. In this example, the device enumeration callback function is named EnumDeviceCallback. A pointer to EnumDeviceCallback is passed to the IDirect3D3::EnumDevices method, which calls EnumDeviceCallback for each device being enumerated.

// In this code fragment, the variable lpd3d contains a valid 
// pointer to the IDirect3D3 interface that the application obtained
// prior to executing this code.
 
BOOL fDeviceFound = FALSE; 
hRes = lpd3d->EnumDevices(EnumDeviceCallback, &fDeviceFound); 
if (FAILED(hRes)) 
{
    // Code to handle the error goes here.
}
 
if (!fDeviceFound) 
{ 
    // Code to handle the error goes here.
}