本文整理汇总了C++中SetupDiEnumDeviceInfo函数的典型用法代码示例。如果您正苦于以下问题:C++ SetupDiEnumDeviceInfo函数的具体用法?C++ SetupDiEnumDeviceInfo怎么用?C++ SetupDiEnumDeviceInfo使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetupDiEnumDeviceInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Mobot_dongleGetTTY
/* Find an attached dongle device and return the COM port name via the output
* parameter tty. tty is a user-supplied buffer of size len. Return the COM
* port number, if anyone cares. On error, return -1. */
int Mobot_dongleGetTTY (char *tty, size_t len) {
/* Get all USB devices that provide a serial or parallel port interface. */
HDEVINFO devices = SetupDiGetClassDevs(
&GUID_DEVCLASS_PORTS,
"USB",
NULL,
DIGCF_PRESENT);
if (INVALID_HANDLE_VALUE == devices) {
win32_error(_T("SetupDiGetClassDevs"), GetLastError());
exit(1);
}
/* Now iterate over each device in the COM port interface class. */
SP_DEVINFO_DATA dev;
dev.cbSize = sizeof(SP_DEVINFO_DATA);
DWORD i = 0;
BOOL b = SetupDiEnumDeviceInfo(devices, i, &dev);
int ret = -1;
while (b) {
if (isDongle(devices, &dev)) {
ret = getCOMPort(devices, &dev, tty, len);
if (-1 == ret) {
fprintf(stderr, "Found dongle, but could not get COM port\n");
exit(1);
}
/* Found the dongle. */
break;
}
/* And get the next device. */
dev.cbSize = sizeof(SP_DEVINFO_DATA);
b = SetupDiEnumDeviceInfo(devices, ++i, &dev);
}
DWORD err = GetLastError();
if (ERROR_SUCCESS != err && ERROR_NO_MORE_ITEMS != err) {
win32_error(_T("SetupDiEnumDeviceInfo"), GetLastError());
exit(1);
}
/* Done with our COM port devices. */
if (!SetupDiDestroyDeviceInfoList(devices)) {
win32_error(_T("SetupDiDestroyDeviceInfoList"), GetLastError());
exit(1);
}
return ret;
}
示例2: StateChange
// ////////////////////////////////////////////////////////////////////////////////
// @private StateChange
//
static BOOL StateChange(DWORD NewState, DWORD SelectedItem,HDEVINFO hDevInfo)
{
SP_PROPCHANGE_PARAMS PropChangeParams = {sizeof(SP_CLASSINSTALL_HEADER)};
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
if ( !SetupDiEnumDeviceInfo(hDevInfo,SelectedItem,&DeviceInfoData) )
{
return FALSE;
}
PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PropChangeParams.Scope = DICS_FLAG_GLOBAL;
PropChangeParams.StateChange = NewState;
if ( !SetupDiSetClassInstallParams(
hDevInfo,
&DeviceInfoData,
(SP_CLASSINSTALL_HEADER *)&PropChangeParams,
sizeof(PropChangeParams)) )
{
return FALSE;
}
if ( !SetupDiCallClassInstaller(
DIF_PROPERTYCHANGE,
hDevInfo,
&DeviceInfoData) )
{
return TRUE;
}
return TRUE;
}
示例3: getDeviceInfo
BOOL getDeviceInfo(const GUID* category, CMIDEV* pDev)
{
TCHAR szServiceName[128];
int nIndex = 0;
pDev->Info = SetupDiGetClassDevs(category, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (pDev->Info == INVALID_HANDLE_VALUE) {
PrintLastError("SetupDiGetClassDevs()");
return FALSE;
}
pDev->InfoData.cbSize = sizeof(SP_DEVINFO_DATA);
while (SetupDiEnumDeviceInfo(pDev->Info, nIndex, &(pDev->InfoData))) {
if (!SetupDiGetDeviceRegistryProperty(pDev->Info, &(pDev->InfoData), SPDRP_SERVICE, NULL, (PBYTE)szServiceName, sizeof(szServiceName), NULL)) {
PrintLastError("SetupDiGetDeviceRegistryProperty()");
SetupDiDestroyDeviceInfoList(pDev->Info);
pDev->Info = NULL;
return FALSE;
}
if (CompareString(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT), NORM_IGNORECASE, szServiceName, -1, TEXT("cmipci"), -1) == CSTR_EQUAL) {
return TRUE;
}
nIndex++;
}
SetupDiDestroyDeviceInfoList(pDev->Info);
pDev->Info = NULL;
return FALSE;
}
示例4: getDeviceList
Status getDeviceList(const device_infoset_t& infoset,
std::vector<SP_DEVINFO_DATA>& rDevices) {
SP_DEVINSTALL_PARAMS installParams;
ZeroMemory(&installParams, sizeof(SP_DEVINSTALL_PARAMS));
installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
installParams.FlagsEx |=
DI_FLAGSEX_ALLOWEXCLUDEDDRVS | DI_FLAGSEX_INSTALLEDDRIVER;
DWORD i = 0;
BOOL devicesLeft = TRUE;
do {
SP_DEVINFO_DATA devInfo;
devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
devicesLeft = SetupDiEnumDeviceInfo(infoset.get(), i, &devInfo);
if (devicesLeft == TRUE) {
// Set install params to make any subsequent driver enumerations on this
// device more efficient
SetupDiSetDeviceInstallParams(infoset.get(), &devInfo, &installParams);
rDevices.push_back(devInfo);
}
i++;
} while (devicesLeft == TRUE);
auto err = GetLastError();
if (err != ERROR_NO_MORE_ITEMS) {
rDevices.clear();
return Status(GetLastError(), "Error enumerating installed devices");
}
return Status();
}
示例5: sizeof
bool QextSerialEnumerator::matchAndDispatchChangedDevice(const QString & deviceID, const GUID & guid, WPARAM wParam)
{
bool rv = false;
DWORD dwFlag = (DBT_DEVICEARRIVAL == wParam) ? DIGCF_PRESENT : DIGCF_ALLCLASSES;
HDEVINFO devInfo;
if( (devInfo = SetupDiGetClassDevs(&guid,NULL,NULL,dwFlag)) != INVALID_HANDLE_VALUE )
{
SP_DEVINFO_DATA spDevInfoData;
spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for(int i=0; SetupDiEnumDeviceInfo(devInfo, i, &spDevInfoData); i++)
{
DWORD nSize=0 ;
TCHAR buf[MAX_PATH];
if ( SetupDiGetDeviceInstanceId(devInfo, &spDevInfoData, buf, MAX_PATH, &nSize) &&
deviceID.contains(TCHARToQString(buf))) // we found a match
{
rv = true;
QextPortInfo info;
info.productID = info.vendorID = 0;
getDeviceDetailsWin( &info, devInfo, &spDevInfoData, wParam );
if( wParam == DBT_DEVICEARRIVAL )
emit deviceDiscovered(info);
else if( wParam == DBT_DEVICEREMOVECOMPLETE )
emit deviceRemoved(info);
break;
}
}
SetupDiDestroyDeviceInfoList(devInfo);
}
return rv;
}
示例6: sbWinGetDeviceInstanceIDFromDeviceInterfaceName
nsresult
sbWinGetDeviceInstanceIDFromDeviceInterfaceName(nsAString& aDeviceInterfaceName,
nsAString& aDeviceInstanceID)
{
BOOL success;
nsresult rv;
// Create a device info set and set it up for auto-disposal.
HDEVINFO devInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);
NS_ENSURE_TRUE(devInfoSet != INVALID_HANDLE_VALUE, NS_ERROR_FAILURE);
sbAutoHDEVINFO autoDevInfoSet(devInfoSet);
// Add the device interface data, including the device info data, to the
// device info set.
SP_DEVICE_INTERFACE_DATA devIfData;
ZeroMemory(&devIfData, sizeof(SP_DEVICE_INTERFACE_DATA));
devIfData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
success = SetupDiOpenDeviceInterfaceW(devInfoSet,
aDeviceInterfaceName.BeginReading(),
0,
&devIfData);
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
// Get the device info data.
SP_DEVINFO_DATA devInfoData;
devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
success = SetupDiEnumDeviceInfo(devInfoSet, 0, &devInfoData);
NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
// Get the device instance ID.
rv = sbWinGetDeviceInstanceID(devInfoData.DevInst, aDeviceInstanceID);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
示例7: FillDeviceInstanceId
void FillDeviceInstanceId(HDEVINFO hDevHandle, SP_DEVINFO_DATA deviceInfoData, WCHAR *wAdapter)
{
DWORD i;
for (i = 0; SetupDiEnumDeviceInfo(hDevHandle, i, &deviceInfoData); i++)
{
BYTE buffer[BUFFER_SIZE];
WCHAR deviceInfo[BUFFER_SIZE];
DWORD dwProperty = 0;
memset(buffer, 0, BUFFER_SIZE);
if (SetupDiGetDeviceRegistryProperty(hDevHandle, &deviceInfoData,
SPDRP_DEVICEDESC , &dwProperty, buffer, BUFFER_SIZE, NULL) == TRUE)
{
wcscpy_s(deviceInfo, BUFFER_SIZE, (LPWSTR)buffer);
if (wcscmp(wAdapter, deviceInfo) == 0)
{
RtlZeroMemory(wDeviceInstanceId, MAX_PATH);
SetupDiGetDeviceInstanceId(hDevHandle, &deviceInfoData, wDeviceInstanceId, MAX_PATH, 0);
}
}
}
}
示例8: sbWinGetDevInfoData
nsresult
sbWinGetDevInfoData(DEVINST aDevInst,
HDEVINFO aDevInfo,
PSP_DEVINFO_DATA aDevInfoData)
{
// Validate arguments.
NS_ENSURE_ARG_POINTER(aDevInfoData);
// Function variables.
BOOL success;
// Find the device info data for the device instance.
DWORD devIndex = 0;
while (1) {
// Get the next device info data.
aDevInfoData->cbSize = sizeof(SP_DEVINFO_DATA);
success = SetupDiEnumDeviceInfo(aDevInfo, devIndex, aDevInfoData);
if (!success)
return NS_ERROR_NOT_AVAILABLE;
// The search is done if the device info data is for the device instance.
if (aDevInfoData->DevInst == aDevInst)
break;
// Check the next device info data.
devIndex++;
}
return NS_OK;
}
示例9: ti_reset
static int ti_reset(struct tip_cygwin *priv)
{
HDEVINFO hdi;
SP_DEVINFO_DATA did;
int i;
int rc = -1;
hdi = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL,
DIGCF_PRESENT);
if (hdi == INVALID_HANDLE_VALUE)
return -1;
/* find device */
for (i = 0;; i++) {
did.cbSize = sizeof(did);
if (!SetupDiEnumDeviceInfo(hdi, i, &did))
break;
if (!ti_is_us(priv, &hdi, &did))
continue;
rc = ti_do_reset(&hdi, &did);
if (rc)
break;
rc = ti_restart(priv);
break;
}
SetupDiDestroyDeviceInfoList(hdi);
return rc;
}
示例10: SetupDiGetClassDevs
void Serial::enumerateWin32Ports()
{
if (bPortsEnumerated == true) return;
HDEVINFO hDevInfo = NULL;
SP_DEVINFO_DATA DeviceInterfaceData;
int i = 0;
DWORD dataType, actualSize = 0;
unsigned char dataBuf[MAX_PATH + 1];
// Reset Port List
nPorts = 0;
// Search device set
hDevInfo = SetupDiGetClassDevs((struct _GUID *)&GUID_SERENUM_BUS_ENUMERATOR,0,0,DIGCF_PRESENT);
if ( hDevInfo ){
while (TRUE){
ZeroMemory(&DeviceInterfaceData, sizeof(DeviceInterfaceData));
DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData);
if (!SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInterfaceData)){
// SetupDiEnumDeviceInfo failed
break;
}
if (SetupDiGetDeviceRegistryPropertyA(hDevInfo,
&DeviceInterfaceData,
SPDRP_FRIENDLYNAME,
&dataType,
dataBuf,
sizeof(dataBuf),
&actualSize)){
sprintf(portNamesFriendly[nPorts], "%s", dataBuf);
portNamesShort[nPorts][0] = 0;
// turn blahblahblah(COM4) into COM4
char * begin = NULL;
char * end = NULL;
begin = strstr((char *)dataBuf, "COM");
if (begin)
{
end = strstr(begin, ")");
if (end)
{
*end = 0; // get rid of the )...
strcpy(portNamesShort[nPorts], begin);
}
if (nPorts++ > MAX_SERIAL_PORTS)
break;
}
}
i++;
}
}
SetupDiDestroyDeviceInfoList(hDevInfo);
bPortsEnumerated = false;
}
示例11: check_removed
/*
* Flag phantom/removed devices for reinstallation. See:
* http://msdn.microsoft.com/en-us/library/aa906206.aspx
*/
void check_removed(char* device_hardware_id)
{
unsigned i, removed = 0;
DWORD size, reg_type, config_flags;
ULONG status, pbm_number;
HDEVINFO dev_info;
SP_DEVINFO_DATA dev_info_data;
char hardware_id[STR_BUFFER_SIZE];
// List all known USB devices (including non present ones)
dev_info = SetupDiGetClassDevsA(NULL, "USB", NULL, DIGCF_ALLCLASSES);
if (dev_info == INVALID_HANDLE_VALUE) {
return;
}
// Find the ones that are driverless
for (i = 0; ; i++)
{
dev_info_data.cbSize = sizeof(dev_info_data);
if (!SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data)) {
break;
}
// Find the hardware ID
if (!SetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_HARDWAREID,
®_type, (BYTE*)hardware_id, STR_BUFFER_SIZE, &size)) {
continue;
}
// Match?
if (safe_strncmp(hardware_id, device_hardware_id, STR_BUFFER_SIZE) != 0) {
continue;
}
// Unplugged?
if (CM_Get_DevNode_Status(&status, &pbm_number, dev_info_data.DevInst, 0) != CR_NO_SUCH_DEVNODE) {
continue;
}
// Flag for reinstall on next plugin
if (!SetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_CONFIGFLAGS,
®_type, (BYTE*)&config_flags, sizeof(DWORD), &size)) {
plog("could not read SPDRP_CONFIGFLAGS for phantom device %s", hardware_id);
continue;
}
config_flags |= CONFIGFLAG_REINSTALL;
if (!SetupDiSetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_CONFIGFLAGS,
(BYTE*)&config_flags, sizeof(DWORD))) {
plog("could not write SPDRP_CONFIGFLAGS for phantom device %s", hardware_id);
continue;
}
removed++;
}
if (removed) {
plog("flagged %d removed devices for reinstallation", removed);
}
}
示例12: uart_list_devices
void uart_list_devices()
{
char name[]="Bluegiga Bluetooth Low Energy";
BYTE* pbuf = NULL;
DWORD reqSize = 0;
DWORD n=0;
HDEVINFO hDevInfo;
//guid for ports
static const GUID guid = { 0x4d36e978, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
char *str;
char tmp[MAX_PATH+1];
int i;
SP_DEVINFO_DATA DeviceInfoData;
snprintf(tmp,MAX_PATH,"%s (COM%%d)",name);
DeviceInfoData.cbSize=sizeof(SP_DEVINFO_DATA);
hDevInfo = SetupDiGetClassDevs(&guid, //Retrieve all ports
0L,
NULL,
DIGCF_PRESENT );
if(hDevInfo==INVALID_HANDLE_VALUE)
return;
while(1)
{
if(!SetupDiEnumDeviceInfo(
hDevInfo,
n++,
&DeviceInfoData
))
{
SetupDiDestroyDeviceInfoList(hDevInfo);
return;
}
reqSize = 0;
SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, NULL, 0, &reqSize);
pbuf = (BYTE*)malloc(reqSize>1?reqSize:1);
if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, pbuf, reqSize, NULL))
{
free(pbuf);
continue;
}
str = (char*)pbuf;
if(sscanf(str,tmp,&i)==1)
{
printf("%s\n", str);
//emit DeviceFound(str,QString("\\\\.\\COM%1").arg(i));
}
free(pbuf);
}
return;
}
示例13: uart_find_serialport
int uart_find_serialport(char *name)
{
BYTE* pbuf = NULL;
DWORD reqSize = 0;
DWORD n=0;
HDEVINFO hDevInfo;
//guid for ports
static const GUID guid = { 0x4d36e978, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
char *str;
char tmp[MAX_PATH+1];
int i;
SP_DEVINFO_DATA DeviceInfoData;
snprintf(tmp,MAX_PATH,"%s (COM%%d)",name);
DeviceInfoData.cbSize=sizeof(SP_DEVINFO_DATA);
hDevInfo = SetupDiGetClassDevs(&guid, //Retrieve all ports
0L,
NULL,
DIGCF_PRESENT );
if(hDevInfo==INVALID_HANDLE_VALUE)
return -1;
while(1)
{
if(!SetupDiEnumDeviceInfo(
hDevInfo,
n++,
&DeviceInfoData
))
{
SetupDiDestroyDeviceInfoList(hDevInfo);
return -1;
}
reqSize = 0;
SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, NULL, 0, &reqSize);
pbuf = malloc(reqSize>1?reqSize:1);
if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, pbuf, reqSize, NULL))
{
free(pbuf);
continue;
}
str = (char*)pbuf;
if(sscanf(str,tmp,&i)==1)
{
free(pbuf);
SetupDiDestroyDeviceInfoList(hDevInfo);
return i;
}
free(pbuf);
}
return -1;
}
示例14: SM_ASSERT
void SMNetworkAdapterSettings::_FingSetupInfo(HDEVINFO* devInfo, SP_DEVINFO_DATA* devInfoData) const
{
SM_ASSERT( !_hardwareId.IsEmpty() );
SMString hwID(_hardwareId);
hwID.MakeUpper();
*devInfo = ::SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if( INVALID_HANDLE_VALUE == *devInfo )
throw SMRuntimeException(::GetLastError());
::ZeroMemory(devInfoData, sizeof(SP_DEVINFO_DATA));
devInfoData->cbSize = sizeof(SP_DEVINFO_DATA);
PTSTR buf = NULL;
DWORD bufSize = 0;
DWORD reqSize = 0;
for(int i=0; SetupDiEnumDeviceInfo(*devInfo,i, devInfoData); i++)
{
if ( !SetupDiGetDeviceInstanceId(*devInfo, devInfoData, buf, bufSize, &reqSize) )
{
if ( bufSize < reqSize )
{
if ( NULL != buf )
{
delete[] buf;
buf = NULL;
bufSize = 0;
}
buf = new TCHAR[reqSize];
if ( NULL == buf )
{
SM_LOG(1, E_FAIL, SMString("Insufficient memory : ") + _com_error(GetLastError()).ErrorMessage());
break;
}
bufSize = reqSize;
if ( !SetupDiGetDeviceInstanceId(*devInfo, devInfoData, buf, bufSize, &reqSize) )
throw SMRuntimeException(::GetLastError());
}
else
{
SM_LOG(1, E_FAIL, SMString("SetupDiGetDeviceInstanceId(): ") + _com_error(GetLastError()).ErrorMessage());
break;
}
}
SMString szBuf = buf;
szBuf.MakeUpper();
if ( szBuf.Find(hwID.DataW()) != -1 )
return;
}
}
示例15: main
int main( int argc, char *argv[ ], char *envp[ ] )
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
/*
hDevInfo = SetupDiGetClassDevs(NULL,
REGSTR_KEY_PCIENUM, // Enumerator
0,
DIGCF_PRESENT | DIGCF_ALLCLASSES );
*/
// Create a HDEVINFO with all present devices.
hDevInfo = SetupDiGetClassDevs(
&GUID_DEVINTERFACE_TAPE,
0, // Enumerator
0,
DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
// DIGCF_PRESENT | DIGCF_ALLCLASSES );
if (hDevInfo == INVALID_HANDLE_VALUE)
{
// Insert error handling here.
return 1;
}
// Enumerate through all devices in Set.
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++)
{
show_property(hDevInfo, &DeviceInfoData, SPDRP_DEVTYPE, "Type");
show_property(hDevInfo, &DeviceInfoData, SPDRP_DEVICEDESC, "Description");
show_property(hDevInfo, &DeviceInfoData, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, "PhysDevName");
}
if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return 1;
}
// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}