The ChooseDevice function invokes the EnumDeviceCallback function , which is described in Enumeration Callback Function.
static HRESULT
ChooseDevice(void)
{
DDSURFACEDESC ddsd;
HRESULT hRes;
ASSERT(NULL != lpd3d);
ASSERT(NULL != lpddPrimary);
// Since we are running in a window, we will not be changing the
// screen depth; therefore, the pixel format of the rendering
// target must match the pixel format of the current primary
// surface. This means that we need to determine the pixel
// format of the primary surface.
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
hRes = lpddPrimary->lpVtbl->GetSurfaceDesc(lpddPrimary, &ddsd);
if (FAILED(hRes))
return hRes;
dwDeviceBitDepth =
BitDepthToFlags(ddsd.ddpfPixelFormat.dwRGBBitCount);
// Enumerate the devices and pick one.
fDeviceFound = FALSE;
hRes = lpd3d->lpVtbl->EnumDevices(lpd3d, EnumDeviceCallback,
&fDeviceFound);
if (FAILED(hRes))
return hRes;
if (!fDeviceFound)
{
// No suitable device was found. We cannot allow
// device-creation to continue.
return DDERR_NOTFOUND;
}
return DD_OK;
}