Platform SDK: DirectX

Step 1.3: Enumerate Device Information

[Visual Basic]

The information in this section pertains only to applications written in C and C++. See Direct3D Immediate Mode Visual Basic Tutorials.

[C++]

The IDirect3D7::EnumDevices method enumerates all of the Direct3D device drivers installed on the system. The Enumeration application calls the EnumDevices function with the following parameters:

    pD3D->EnumDevices( DeviceEnumCallback, &d3dDeviceInfo );

The first argument, DeviceEnumCallback, is the address of a D3DEnumDevicesCallback7 callback function that will be called every time a Direct3D device is submitted for enumeration. The second parameter is a reference to a D3DDEVICEINFO structure, describing the device under enumeration.

For every device that is enumerated, the following function is called:

static HRESULT WINAPI DeviceEnumCallback(LPSTR strDesc,
                                  LPSTR strName, D3DDEVICEDESC7* pDesc,
                                  VOID* pParentInfo )
{

The first two parameters are the string description and name of the device. The third parameter, pDesc, is the address of a D3DDEVICEDESC7 structure the describes the hardware capabilities of the Direct3D device. For more information on this function, see the D3DEnumDevicesCallback7 topic in the SDK reference.

You can set up the device information for the device under enumeration with the following code:

    D3DDEVICEINFO* pDriverInfo = (D3DDEVICEINFO*)pParentInfo;
    D3DDEVICEINFO* pDeviceInfo = &g_d3dDevices[g_dwNumDevices];
    memcpy( &pDeviceInfo->ddDeviceDesc, pDesc, sizeof(D3DDEVICEDESC7) );
    pDeviceInfo->guidDevice   = pDesc->deviceGUID;
    pDeviceInfo->pDeviceGUID  = &pDeviceInfo->guidDevice;
    pDeviceInfo->bHardware    = pDesc->dwDevCaps & D3DDEVCAPS_HWRASTERIZATION;
    pDeviceInfo->dwNumModes   = 0;
    pDeviceInfo->ddDriverCaps = pDriverInfo->ddDriverCaps;
    pDeviceInfo->ddHELCaps    = pDriverInfo->ddHELCaps;

In the preceding code, the D3DDEVICEINFO structure, pDeviceInfo, is filled with the capabilities of the device. Note that pParentInfo is cast to a D3DDEVICEINFO type, so that the driver GUID and description can be extracted from it.

Now that you have the device information, copy the driver GUID and description for the device into the D3DDEVICEINFO structure holding the device information:

        pDeviceInfo->guidDriver  = pDriverInfo->guidDriver;
        pDeviceInfo->pDriverGUID = &pDeviceInfo->guidDriver;
        strncpy( pDeviceInfo->strDesc, pDriverInfo->strDesc, 39 );

After you have enumerated your display driver, display modes, and devices you can select an enumerated device to be used by your application, which is the topic of Step 2: Select an Enumerated Device.