Download the source code

The APIs FindFirstDevice and FindNextDevice can be used to search for a device currently loaded in Windows CE 5.0 or above. These APIs are not available in versions prior to Windows CE 5.0. The following are the syntax:

HANDLE FindFirstDevice(DeviceSearchType searchType,LPCVOID pvSearchParam,PDEVMGR_DEVICE_INFORMATION pdi);
BOOL FindNextDevice(HANDLE h,PDEVMGR_DEVICE_INFORMATION pdi);

If successful the FindFirstDevice returns a device handle which can be used for subsequent FineNextDevice. The first parameter is the device type which can be one of the following:

DeviceSearchByLegacyName
DeviceSearchByDeviceName
DeviceSearchByBusName
DeviceSearchByGuid
DeviceSearchByParent

The second parameter is the additional search parameter which depends of the device type specified. To search all devices we can use “*” as the search parameter. The third parameter is a pointer to DEVMGR_DEVICE_INFORMATION structure which will be filled with the details of the devices found.

The FindNextDevice returns TRUE if there are more devices to find otherwise returns FALSE. The first parameter is the HANDLE returned by the FindFirstDevice and second parameter is a pointer to the DEVMGR_DEVICE_INFORMATION structure.

The following code enumerate all devices and add the details to a ListCtrl.

HANDLE hDevice = NULL;
DeviceSearchType eSearchType = DeviceSearchByLegacyName;
DEVMGR_DEVICE_INFORMATION sInfo = {0};

sInfo.dwSize = sizeof(DEVMGR_DEVICE_INFORMATION);
hDevice = FindFirstDevice(eSearchType,TEXT(“*”),&sInfo);

int nItem = 0;
int nListItem = 0;

if(INVALID_HANDLE_VALUE == hDevice)
return;

BOOL bContinue = TRUE;

while(bContinue)
{
nListItem = pList->InsertItem(nItem,sInfo.szLegacyName);

pList->SetItemText(nItem,1,sInfo.szDeviceName);
pList->SetItemText(nItem,2,sInfo.szDeviceKey);
pList->SetItemText(nItem,3,sInfo.szBusName);

++nItem;

bContinue = FindNextDevice(hDevice,&sInfo);
}

FindClose(hDevice);