DirectX SDK |
A C++ application begins device enumeration by calling the IDirect3D7::EnumDevices method, which enumerates all the Direct3D devices that the hardware supports. Direct3D invokes the D3DEnumDevicesCallback7 function to select the device to be used. You supply the D3DEnumDevicesCallback7 function in your application. Because this callback function is supplied by your application, you can call it anything that you want.
The following code fragment illustrates the process of enumerating Direct3D devices. In this example, the device enumeration callback function is named EnumDeviceCallback. The code passes a pointer to EnumDeviceCallback to the IDirect3D7::EnumDevices method, which in turn calls EnumDeviceCallback for each device being enumerated, then returns. The callback can stop the enumeration before all devices have been enumerated by returning D3DENUMRET_CANCEL.
// In this code fragment, the variable lpd3d contains a valid // pointer to the IDirect3D7 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. }
A Visual Basic application begins device enumeration by retrieving a reference to the Direct3DEnumDevices class by calling the Direct3D7.GetDevicesEnum method. The Direct3DEnumDevices class defines methods that retrieve the number of enumerated devices and information about each device.
The following code fragment illustrates the process of retrieving the Direct3DEnumDevices class:
' In this example, the d3d variable is a valid reference to a ' Direct3D7 class. Dim d3dEnum As Direct3DEnumDevices ' Retrieve the enumerator class. Set d3dEnum = d3d.GetDevicesEnum