本文整理汇总了C++中SetupDiDestroyDeviceInfoList函数的典型用法代码示例。如果您正苦于以下问题:C++ SetupDiDestroyDeviceInfoList函数的具体用法?C++ SetupDiDestroyDeviceInfoList怎么用?C++ SetupDiDestroyDeviceInfoList使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetupDiDestroyDeviceInfoList函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ResetPortList
BOOL CEnumerateSerial::EnumeratePorts()
{
int SPDRPlist[] = {
SPDRP_HARDWAREID, SPDRP_DEVICEDESC, SPDRP_FRIENDLYNAME, SPDRP_MFG,
SPDRP_LOCATION_INFORMATION, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME,
-1};
// Clear anything from previous enumerate...
ResetPortList();
// First need to convert the name "Ports" to a GUID using SetupDiClassGuidsFromName...
DWORD dwGuids = 0;
SetupDiClassGuidsFromName(_T("Ports"), NULL, 0, &dwGuids);
if (dwGuids == 0) return FALSE;
// Allocate the needed memory...
CHeapPtr<GUID> GuidArray;
GUID *pGuids = (GUID*)GuidArray.Allocate(sizeof(GUID) * dwGuids);
if (pGuids==NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
// Call the function again...
if (!SetupDiClassGuidsFromName(_T("Ports"), pGuids, dwGuids, &dwGuids))
return FALSE;
// Now create a "device information set" which is required to enumerate all the ports...
HDEVINFO hDevInfoSet = SetupDiGetClassDevs(pGuids, NULL, NULL, DIGCF_PRESENT);
if (hDevInfoSet == INVALID_HANDLE_VALUE)
return FALSE;
// Finally do the enumeration...
int nIndex = 0;
SP_DEVINFO_DATA devInfo;
CHeapPtr<TCHAR> tempstr(1000);
CSerialPortInfo *portinfo = NULL;
// Enumerate the current device...
devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
while (SetupDiEnumDeviceInfo(hDevInfoSet, nIndex, &devInfo))
{
portinfo = NULL;
// Get the registry key which stores the ports settings...
HKEY hDeviceKey = SetupDiOpenDevRegKey(hDevInfoSet, &devInfo, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
if (hDeviceKey) {
tempstr.FillZero();
DWORD dwSize = tempstr.SizeOf();
DWORD dwType = 0;
// Read name of port. If formatted as "COMxx" then allocate a port slot...
if ((RegQueryValueEx(hDeviceKey, _T("PortName"), NULL, &dwType, reinterpret_cast<LPBYTE>((TCHAR*)tempstr), &dwSize) == ERROR_SUCCESS) && (dwType == REG_SZ))
if (_tcslen(tempstr) > 3)
if ((_tcsnicmp(tempstr, _T("COM"), 3) == 0) && IsNumber(&(tempstr[3])))
portinfo = AddPort(_ttoi(&(tempstr[3])));
// Close the key now that we are finished with it...
RegCloseKey(hDeviceKey);
}
// If a serial port, then try getting additional useful descriptive info...
if (portinfo) {
for (int i=0; SPDRPlist[i]>=0; i++) {
tempstr.FillZero();
DWORD dwSize = tempstr.SizeOf();
DWORD dwType = 0;
if (SetupDiGetDeviceRegistryProperty(hDevInfoSet, &devInfo, SPDRPlist[i], &dwType, reinterpret_cast<PBYTE>((TCHAR*)tempstr), dwSize, &dwSize) && ((dwType == REG_SZ) || (dwType == REG_MULTI_SZ)))
switch (SPDRPlist[i]) {
case SPDRP_MFG : portinfo->SetManufacturer(tempstr); break;
case SPDRP_HARDWAREID : portinfo->SetHardwareID(tempstr); break;
case SPDRP_DEVICEDESC : portinfo->SetDeviceDesc(tempstr); break;
case SPDRP_FRIENDLYNAME : portinfo->SetFriendlyName(tempstr); break;
case SPDRP_LOCATION_INFORMATION : portinfo->SetLocationInfo(tempstr); break;
case SPDRP_PHYSICAL_DEVICE_OBJECT_NAME : portinfo->SetPhysLocation(tempstr); break;
}
}
// Get COM port properties...
HANDLE hPort = ::CreateFile(portinfo->GetPortDeviceName(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (hPort != INVALID_HANDLE_VALUE) {
COMMPROP cp;
GetCommProperties(hPort, &cp);
portinfo->SetCommProp(cp);
TRACE ("Port %d: CommProp: maxbaud=%08x settablebaud=%08x\n",portinfo->GetPortNum(),cp.dwMaxBaud,cp.dwSettableBaud);
CloseHandle(hPort);
}
}
++nIndex;
}
// Free up the "device information set" now that we are finished with it
SetupDiDestroyDeviceInfoList(hDevInfoSet);
// Return the success indicator
return TRUE;
}
示例2: winutil_get_removable_drives
static PyObject *
winutil_get_removable_drives(PyObject *self, PyObject *args) {
HDEVINFO hDevInfo;
BOOL iterate = TRUE, ddebug = FALSE;
PSP_DEVICE_INTERFACE_DETAIL_DATA interfaceDetailData;
DWORD i;
unsigned int j;
size_t length;
WCHAR volume[BUFSIZE];
struct tagDrives g_drives[MAX_DRIVES];
PyObject *volumes, *key, *candidates, *pdebug = Py_False, *temp;
if (!PyArg_ParseTuple(args, "|O", &pdebug)) {
return NULL;
}
// Find all removable drives
for (j = 0; j < MAX_DRIVES; j++) g_drives[j].letter = 0;
if (!get_all_removable_disks(g_drives)) return NULL;
volumes = PyDict_New();
if (volumes == NULL) return PyErr_NoMemory();
ddebug = PyObject_IsTrue(pdebug);
hDevInfo = create_device_info_set((LPGUID)&GUID_DEVINTERFACE_VOLUME,
NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (hDevInfo == INVALID_HANDLE_VALUE) { Py_DECREF(volumes); return NULL; }
// Enumerate through the set
for (i=0; iterate; i++) {
candidates = PyList_New(0);
if (candidates == NULL) { Py_DECREF(volumes); return PyErr_NoMemory();}
interfaceDetailData = get_device_ancestors(hDevInfo, i, candidates, &iterate, ddebug);
if (interfaceDetailData == NULL) {
PyErr_Print();
Py_DECREF(candidates); candidates = NULL;
continue;
}
length = wcslen(interfaceDetailData->DevicePath);
interfaceDetailData->DevicePath[length] = L'\\';
interfaceDetailData->DevicePath[length+1] = 0;
if (ddebug) console_out(L"Device path: %s\n", interfaceDetailData->DevicePath);
// On Vista+ DevicePath contains the information we need.
temp = PyUnicode_FromWideChar(interfaceDetailData->DevicePath, length);
if (temp == NULL) return PyErr_NoMemory();
PyList_Append(candidates, temp);
Py_DECREF(temp);
if(GetVolumeNameForVolumeMountPointW(interfaceDetailData->DevicePath, volume, BUFSIZE)) {
if (ddebug) console_out(L"Volume: %s\n", volume);
for(j = 0; j < MAX_DRIVES; j++) {
if(g_drives[j].letter != 0 && wcscmp(g_drives[j].volume, volume)==0) {
if (ddebug) printf("Found drive: %c\n", (char)g_drives[j].letter); fflush(stdout);
key = PyBytes_FromFormat("%c", (char)g_drives[j].letter);
if (key == NULL) return PyErr_NoMemory();
PyDict_SetItem(volumes, key, candidates);
Py_DECREF(key); key = NULL;
break;
}
}
}
Py_XDECREF(candidates); candidates = NULL;
PyMem_Free(interfaceDetailData);
} //for
SetupDiDestroyDeviceInfoList(hDevInfo);
return volumes;
}
示例3: mobiledevice_connect
irecv_error_t mobiledevice_connect(irecv_client_t* client) {
irecv_error_t ret;
SP_DEVICE_INTERFACE_DATA currentInterface;
HDEVINFO usbDevices;
DWORD i;
LPSTR path;
irecv_client_t _client = (irecv_client_t) malloc(sizeof(struct irecv_client));
memset(_client, 0, sizeof(struct irecv_client));
// Get DFU paths
usbDevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DFU, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(!usbDevices) {
return IRECV_E_UNABLE_TO_CONNECT;
}
currentInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
for(i = 0; SetupDiEnumDeviceInterfaces(usbDevices, NULL, &GUID_DEVINTERFACE_DFU, i, ¤tInterface); i++) {
DWORD requiredSize = 0;
PSP_DEVICE_INTERFACE_DETAIL_DATA details;
SetupDiGetDeviceInterfaceDetail(usbDevices, ¤tInterface, NULL, 0, &requiredSize, NULL);
details = (PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(requiredSize);
details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if(!SetupDiGetDeviceInterfaceDetail(usbDevices, ¤tInterface, details, requiredSize, NULL, NULL)) {
irecv_close(_client);
free(details);
SetupDiDestroyDeviceInfoList(usbDevices);
return IRECV_E_UNABLE_TO_CONNECT;
} else {
LPSTR result = (LPSTR) malloc(requiredSize - sizeof(DWORD));
memcpy((void*) result, details->DevicePath, requiredSize - sizeof(DWORD));
free(details);
path = (LPSTR) malloc(requiredSize - sizeof(DWORD));
memcpy((void*) path, (void*) result, requiredSize - sizeof(DWORD));
TCHAR* pathEnd = strstr(path, "#{");
*pathEnd = '\0';
_client->DfuPath = result;
break;
}
}
SetupDiDestroyDeviceInfoList(usbDevices);
// Get iBoot path
usbDevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_IBOOT, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(!usbDevices) {
irecv_close(_client);
return IRECV_E_UNABLE_TO_CONNECT;
}
currentInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
for(i = 0; SetupDiEnumDeviceInterfaces(usbDevices, NULL, &GUID_DEVINTERFACE_IBOOT, i, ¤tInterface); i++) {
DWORD requiredSize = 0;
PSP_DEVICE_INTERFACE_DETAIL_DATA details;
SetupDiGetDeviceInterfaceDetail(usbDevices, ¤tInterface, NULL, 0, &requiredSize, NULL);
details = (PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(requiredSize);
details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if(!SetupDiGetDeviceInterfaceDetail(usbDevices, ¤tInterface, details, requiredSize, NULL, NULL)) {
irecv_close(_client);
free(details);
SetupDiDestroyDeviceInfoList(usbDevices);
return IRECV_E_UNABLE_TO_CONNECT;
} else {
LPSTR result = (LPSTR) malloc(requiredSize - sizeof(DWORD));
memcpy((void*) result, details->DevicePath, requiredSize - sizeof(DWORD));
free(details);
if(strstr(result, path) == NULL) {
free(result);
continue;
}
_client->iBootPath = result;
break;
}
}
SetupDiDestroyDeviceInfoList(usbDevices);
free(path);
ret = mobiledevice_openpipes(_client);
if (ret != IRECV_E_SUCCESS) return ret;
*client = _client;
return IRECV_E_SUCCESS;
}
示例4: hid_enumerate
//.........这里部分代码省略.........
size_t len;
/* VID/PID match. Create the record. */
tmp = (struct hid_device_info*) calloc(1, sizeof(struct hid_device_info));
if (cur_dev) {
cur_dev->next = tmp;
}
else {
root = tmp;
}
cur_dev = tmp;
/* Get the Usage Page and Usage for this device. */
res = HidD_GetPreparsedData(write_handle, &pp_data);
if (res) {
nt_res = HidP_GetCaps(pp_data, &caps);
if (nt_res == HIDP_STATUS_SUCCESS) {
cur_dev->usage_page = caps.UsagePage;
cur_dev->usage = caps.Usage;
}
HidD_FreePreparsedData(pp_data);
}
/* Fill out the record */
cur_dev->next = NULL;
str = device_interface_detail_data->DevicePath;
if (str) {
len = strlen(str);
cur_dev->path = (char*) calloc(len+1, sizeof(char));
strncpy(cur_dev->path, str, len+1);
cur_dev->path[len] = '\0';
}
else
cur_dev->path = NULL;
/* Serial Number */
res = HidD_GetSerialNumberString(write_handle, wstr, sizeof(wstr));
wstr[WSTR_LEN-1] = 0x0000;
if (res) {
cur_dev->serial_number = _wcsdup(wstr);
}
/* Manufacturer String */
res = HidD_GetManufacturerString(write_handle, wstr, sizeof(wstr));
wstr[WSTR_LEN-1] = 0x0000;
if (res) {
cur_dev->manufacturer_string = _wcsdup(wstr);
}
/* Product String */
res = HidD_GetProductString(write_handle, wstr, sizeof(wstr));
wstr[WSTR_LEN-1] = 0x0000;
if (res) {
cur_dev->product_string = _wcsdup(wstr);
}
/* VID/PID */
cur_dev->vendor_id = attrib.VendorID;
cur_dev->product_id = attrib.ProductID;
/* Release Number */
cur_dev->release_number = attrib.VersionNumber;
/* Interface Number. It can sometimes be parsed out of the path
on Windows if a device has multiple interfaces. See
http://msdn.microsoft.com/en-us/windows/hardware/gg487473 or
search for "Hardware IDs for HID Devices" at MSDN. If it's not
in the path, it's set to -1. */
cur_dev->interface_number = -1;
if (cur_dev->path) {
char *interface_component = strstr(cur_dev->path, "&mi_");
if (interface_component) {
char *hex_str = interface_component + 4;
char *endptr = NULL;
cur_dev->interface_number = strtol(hex_str, &endptr, 16);
if (endptr == hex_str) {
/* The parsing failed. Set interface_number to -1. */
cur_dev->interface_number = -1;
}
}
}
}
cont_close:
CloseHandle(write_handle);
cont:
/* We no longer need the detail data. It can be freed */
free(device_interface_detail_data);
device_index++;
}
/* Close the device information handle. */
SetupDiDestroyDeviceInfoList(device_info_set);
return root;
}
示例5: installVideoDriver
/**
* Install the VBox video driver.
*
* @returns TRUE on success.
* @returns FALSE on failure.
* @param szDriverDir The base directory where we find the INF.
*/
BOOL installVideoDriver(TCHAR* szDriverDir)
{
HDEVINFO hDevInfo;
SP_DEVINSTALL_PARAMS DeviceInstallParams={0};
SP_DRVINFO_DATA drvInfoData={0};
SP_DRVINFO_DETAIL_DATA DriverInfoDetailData={0};
DWORD cbReqSize;
/* Vars used for reading the INF */
HINF hInf;
TCHAR szServiceSection[LINE_LEN];
INFCONTEXT serviceContext;
TCHAR szServiceData[LINE_LEN];
TCHAR deviceRegStr[1000];//I'm lazy here. 1000 ought to be enough for everybody...
SP_DEVINFO_DATA deviceInfoData;
DWORD configFlags;
HKEY hkey;
DWORD disp;
TCHAR regKeyName[LINE_LEN];
BOOL rc;
/* Create an empty list */
hDevInfo = SetupDiCreateDeviceInfoList((LPGUID) &GUID_DEVCLASS_DISPLAY,
NULL);
if (hDevInfo == INVALID_HANDLE_VALUE)
return FALSE;
memset(&DeviceInstallParams, 0, sizeof(SP_DEVINSTALL_PARAMS));
DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
rc=SetupDiGetDeviceInstallParams(hDevInfo,
NULL,
&DeviceInstallParams);
if(!rc)
return FALSE;
DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
DeviceInstallParams.Flags |= DI_NOFILECOPY | /* We did our own file copying */
DI_DONOTCALLCONFIGMG |
DI_ENUMSINGLEINF; /* .DriverPath specifies an inf file */
/* Path to inf file */
wsprintf(DeviceInstallParams.DriverPath,
TEXT("%ws\\%ws"),
szDriverDir, TEXT(VBOXGUEST_VIDEO_INF_NAME));
rc=SetupDiSetDeviceInstallParams(hDevInfo,
NULL,
&DeviceInstallParams);
if(!rc)
return FALSE;
/* Read the drivers from the inf file */
if (!SetupDiBuildDriverInfoList(hDevInfo, NULL, SPDIT_CLASSDRIVER))
{
SetupDiDestroyDeviceInfoList(hDevInfo);
return FALSE;
}
/* Get the first found driver.
Our Inf file only contains one so this is fine */
drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
if(FALSE==SetupDiEnumDriverInfo(hDevInfo, NULL, SPDIT_CLASSDRIVER,
0, &drvInfoData)){
SetupDiDestroyDeviceInfoList(hDevInfo);
return FALSE;
}
/* Get necessary driver details */
DriverInfoDetailData.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
if (!(!SetupDiGetDriverInfoDetail(hDevInfo,
NULL,
&drvInfoData,
&DriverInfoDetailData,
DriverInfoDetailData.cbSize,
&cbReqSize)
&&GetLastError()== ERROR_INSUFFICIENT_BUFFER) )
{
SetupDiDestroyDriverInfoList(hDevInfo, NULL, SPDIT_CLASSDRIVER);
SetupDiDestroyDeviceInfoList(hDevInfo);
return FALSE;
}
hInf = SetupOpenInfFile(DriverInfoDetailData.InfFileName,
NULL, INF_STYLE_WIN4, NULL);
//.........这里部分代码省略.........
示例6: enumerate_usb_hid_devices
//.........这里部分代码省略.........
return clean_throw_exp_usbenumeration(env, 1, 2, HRESULT_FROM_SETUPAPI(GetLastError()), NULL, NULL, &hiddevinst_list, NULL, &hid_dev_info_set);
}
/* get HardwareID of this device;
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\VID_04D8&PID_00DF&MI_02\7&33842C3F&0&0000\HardwareID */
memset(keybuf, '\0', 1024);
_stprintf_s(keybuf, 1024, TEXT("SYSTEM\\CurrentControlSet\\Enum\\%s"), buffer);
charbuffer_size = sizeof(charbuffer);
memset(charbuffer, '\0', 512);
status = RegGetValue(HKEY_LOCAL_MACHINE, keybuf, TEXT("HardwareID"), RRF_RT_REG_MULTI_SZ, NULL, (PVOID)charbuffer, &charbuffer_size);
if (status != ERROR_SUCCESS) {
return clean_throw_exp_usbenumeration(env, 1, 2, GetLastError(), NULL, NULL, &hiddevinst_list, NULL, &hid_dev_info_set);
}
/* save device instance and hardware id (including terminating null character) in the
list for later comparision */
instidinfo = NULL;
instidinfo = (struct hiddev_inst_cont_id *) malloc(sizeof(struct hiddev_inst_cont_id));
if (instidinfo == NULL) {
return clean_throw_exp_usbenumeration(env, 1, 1, 0, E_MALLOCSTR, NULL, &hiddevinst_list, NULL, &hid_dev_info_set);
}
_tcscpy_s(instidinfo->instance, 512, buffer);
_tcscpy_s(instidinfo->hwid, 512, charbuffer);
insert_hiddev_instance_list(&hiddevinst_list, instidinfo);
/* increment to get the next HID device instance */
hid_member_index++;
}
/* release HID info set as it is no longer needed */
SetupDiDestroyDeviceInfoList(hid_dev_info_set);
/* allocate memory to hold information used during processing and returning information
to caller. */
x = init_jstrarraylist(&list, 100);
if (x < 0) {
return clean_throw_exp_usbenumeration(env, 2, 1, 0, E_CALLOCSTR, NULL, &hiddevinst_list, NULL, NULL);
}
/* From here onwards, enumerate over all USB interfaces looking for HID interface and try to
associate with its device instance and then create information that will be passed to
application. */
/* ~~~~~~~~~~~~~ ENUMERATE ALL USB DEVICES ~~~~~~~~~~~~~ */
/* get information set for all usb devices matching the GUID */
usb_dev_info_set = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (usb_dev_info_set == INVALID_HANDLE_VALUE) {
return clean_throw_exp_usbenumeration(env, 3, 2, HRESULT_FROM_SETUPAPI(GetLastError()), NULL, &list, &hiddevinst_list, &usb_dev_info_set, NULL);
}
/* enumerate all devices in this information set */
usb_member_index = 0;
while (1) {
ZeroMemory(&usb_dev_instance, sizeof(usb_dev_instance));
usb_dev_instance.cbSize = sizeof(usb_dev_instance);
/* from information set, get device by index */
ret = SetupDiEnumDeviceInfo(usb_dev_info_set, usb_member_index, &usb_dev_instance);
if (ret == FALSE) {
error_code = GetLastError();
if (error_code == ERROR_NO_MORE_ITEMS) {
break;
开发者ID:surpriserom,项目名称:Pilotage-automatique-d-un-voilier-via-un-bus-CAN-Arduino,代码行数:67,代码来源:windows_list_usbhid_dev.c
示例7: GetSymbolicLink
ULONG GetSymbolicLink(void)
{
//OutputDebugString("GetSymbolicLink\r\n");
int found_index = 0;
HDEVINFO hDevInfo;
// obtain a handle to device information set for all
// kernel streaming audio devices present on the system
hDevInfo = SetupDiGetClassDevs(
&CamacGuid,
NULL,
NULL,
DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE)
{ // function returned 0
// No audio devices are present on the system
return 0;
}
else
{
TCHAR HardwareID[512];
USHORT found_index = 0;
// Enumerate first device of our class.
SP_DEVICE_INTERFACE_DATA ifdata;
ifdata.cbSize = sizeof(ifdata);
for ( DWORD devindex = 0;
SetupDiEnumInterfaceDevice(hDevInfo, NULL,&CamacGuid, devindex, &ifdata);
++devindex )
{
// Determine the symbolic link name for this device instance. Since
// this is variable in length, make an initial call to determine
// the required length.
DWORD needed;
SetupDiGetDeviceInterfaceDetail(hDevInfo, &ifdata, NULL, 0, &needed, NULL);
// this call determines the size of memory to allocate
PSP_INTERFACE_DEVICE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);
// zero the structure
memset (detail,0,needed);
// set the size of the structure without the string at the end
detail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
SP_DEVINFO_DATA did = {sizeof(SP_DEVINFO_DATA)};
SetupDiGetDeviceInterfaceDetail(hDevInfo, &ifdata, detail, needed, NULL, &did);
// Determine the device's link name
SetupDiGetDeviceRegistryProperty(hDevInfo, &did,SPDRP_HARDWAREID, NULL, (PBYTE) HardwareID, sizeof(HardwareID), NULL);
memset(symbolic_link, 0, sizeof(symbolic_link));
strncpy(symbolic_link, detail->DevicePath, sizeof(symbolic_link));
free((PVOID) detail);
ifdata.cbSize = sizeof(ifdata); // reinitialize for next use
}
SetupDiDestroyDeviceInfoList(hDevInfo);
}
return found_index;
}
示例8: LOG_INFO
//.........这里部分代码省略.........
name += QString::fromUtf8(vendor_buf) + " ";
CFRelease(vendor_name_ref);
}
else {
name += QObject::tr("(unknown vendor name) ");
}
/* get product name */
char product_buf[256];
CFIndex product_buflen = 256;
CFTypeRef product_name_ref = NULL;
product_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj,
kIOServicePlane, CFSTR("USB Product Name"),
kCFAllocatorDefault, 0);
if(product_name_ref != NULL) {
CFStringGetCString((CFStringRef)product_name_ref, product_buf, product_buflen,
kCFStringEncodingUTF8);
name += QString::fromUtf8(product_buf);
CFRelease(product_name_ref);
}
else {
name += QObject::tr("(unknown product name)");
}
if(id) {
usbids.insertMulti(id, name);
LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16) << name;
}
}
IOObjectRelease(usb_iterator);
#endif
#if defined(Q_OS_WIN32)
HDEVINFO deviceInfo;
SP_DEVINFO_DATA infoData;
DWORD i;
// Iterate over all devices
// by doing it this way it's unneccessary to use GUIDs which might be not
// present in current MinGW. It also seemed to be more reliably than using
// a GUID.
// See KB259695 for an example.
deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
infoData.cbSize = sizeof(SP_DEVINFO_DATA);
for(i = 0; SetupDiEnumDeviceInfo(deviceInfo, i, &infoData); i++) {
DWORD data;
LPTSTR buffer = NULL;
DWORD buffersize = 0;
QString description;
// get device desriptor first
// for some reason not doing so results in bad things (tm)
while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
SPDRP_DEVICEDESC, &data, (PBYTE)buffer, buffersize, &buffersize)) {
if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
if(buffer) free(buffer);
// double buffer size to avoid problems as per KB888609
buffer = (LPTSTR)malloc(buffersize * 2);
}
else {
break;
}
}
description = QString::fromWCharArray(buffer);
// now get the hardware id, which contains PID and VID.
while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData,
SPDRP_HARDWAREID, &data, (PBYTE)buffer, buffersize, &buffersize)) {
if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
if(buffer) free(buffer);
// double buffer size to avoid problems as per KB888609
buffer = (LPTSTR)malloc(buffersize * 2);
}
else {
break;
}
}
unsigned int vid, pid;
// convert buffer text to upper case to avoid depending on the case of
// the keys (W7 uses different casing than XP at least).
int len = _tcslen(buffer);
while(len--) buffer[len] = _totupper(buffer[len]);
if(_stscanf(buffer, _TEXT("USB\\VID_%x&PID_%x"), &vid, &pid) == 2) {
uint32_t id;
id = vid << 16 | pid;
usbids.insert(id, description);
LOG_INFO("USB VID: %04x, PID: %04x", vid, pid);
}
if(buffer) free(buffer);
}
SetupDiDestroyDeviceInfoList(deviceInfo);
#endif
return usbids;
}
示例9: SetupDiGetClassDevs
/// <summary>
/// Get physical device paths.
/// </summary>
/// <param name="drives">Found drives</param>
/// <returns>Error code</returns>
DWORD PhysicalDisk::GetPhysicalPaths( std::vector<std::wstring>& drives )
{
HDEVINFO diskClassDevices = nullptr;
GUID diskClassDeviceInterfaceGuid = GUID_DEVINTERFACE_DISK;
SP_DEVICE_INTERFACE_DATA deviceInterfaceData = { 0 };
PSP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData = nullptr;
DWORD requiredSize = 0;
DWORD deviceIndex = 0;
HANDLE disk = INVALID_HANDLE_VALUE;
STORAGE_DEVICE_NUMBER diskNumber = { 0 };
DWORD bytesReturned = 0;
//
// Get the handle to the device information set for installed
// disk class devices. Returns only devices that are currently
// present in the system and have an enabled disk device
// interface.
//
diskClassDevices = SetupDiGetClassDevs( &diskClassDeviceInterfaceGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
if (diskClassDevices == INVALID_HANDLE_VALUE)
return GetLastError();
ZeroMemory( &deviceInterfaceData, sizeof(SP_DEVICE_INTERFACE_DATA) );
deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
for (; SetupDiEnumDeviceInterfaces( diskClassDevices, NULL, &diskClassDeviceInterfaceGuid, deviceIndex, &deviceInterfaceData ); ++deviceIndex)
{
SetupDiGetDeviceInterfaceDetailW( diskClassDevices, &deviceInterfaceData, NULL, 0, &requiredSize, NULL );
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
goto Exit;
deviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc( requiredSize );
ZeroMemory( deviceInterfaceDetailData, requiredSize );
deviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (!SetupDiGetDeviceInterfaceDetail( diskClassDevices, &deviceInterfaceData, deviceInterfaceDetailData, requiredSize, NULL, NULL ))
goto Exit;
disk = CreateFile( deviceInterfaceDetailData->DevicePath,
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if (disk == INVALID_HANDLE_VALUE)
goto Exit;
if (!DeviceIoControl( disk, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &diskNumber, sizeof(STORAGE_DEVICE_NUMBER), &bytesReturned, NULL ))
goto Exit;
CloseHandle( disk );
disk = INVALID_HANDLE_VALUE;
drives.emplace_back( L"\\\\?\\PhysicalDrive" + std::to_wstring( diskNumber.DeviceNumber ) );
if (deviceInterfaceDetailData)
{
free( deviceInterfaceDetailData );
deviceInterfaceDetailData = nullptr;
}
}
Exit:
if (INVALID_HANDLE_VALUE != diskClassDevices)
SetupDiDestroyDeviceInfoList( diskClassDevices );
if (INVALID_HANDLE_VALUE != disk)
CloseHandle( disk );
if (deviceInterfaceDetailData)
free( deviceInterfaceDetailData );
return GetLastError();
}
示例10: __declspec
//.........这里部分代码省略.........
//Interface data is returned in SP_DEVICE_INTERFACE_DETAIL_DATA
//which we need to allocate, so we have to call this function twice.
//First to get the size so that we know how much to allocate
//Second, the actual call with the allocated buffer
bResult = SetupDiGetDeviceInterfaceDetail(
hDeviceInfo,
&deviceInterfaceData,
NULL, 0,
&requiredLength,
NULL);
//Check for some other error
if (!bResult)
{
if ((ERROR_INSUFFICIENT_BUFFER==GetLastError()) && (requiredLength>0))
{
//we got the size, allocate buffer
pInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR, requiredLength);
if (!pInterfaceDetailData)
{
// ERROR
printf("Error allocating memory for the device detail buffer.\n");
goto done;
}
}
else
{
printf("Error SetupDiEnumDeviceInterfaces: %d.\n", GetLastError());
goto done;
}
}
//get the interface detailed data
pInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
//Now call it with the correct size and allocated buffer
bResult = SetupDiGetDeviceInterfaceDetail(
hDeviceInfo,
&deviceInterfaceData,
pInterfaceDetailData,
requiredLength,
NULL,
&DeviceInfoData);
//Check for some other error
if (!bResult)
{
printf("Error SetupDiGetDeviceInterfaceDetail: %d.\n", GetLastError());
goto done;
}
//copy device path
size_t nLength = wcslen (pInterfaceDetailData->DevicePath) + 1;
lpDevicePath = (TCHAR *) LocalAlloc (LPTR, nLength * sizeof(TCHAR));
StringCchCopy(lpDevicePath, nLength, pInterfaceDetailData->DevicePath);
lpDevicePath[nLength-1] = 0;
//printf("Device path: %s\n", lpDevicePath);
}
if (!lpDevicePath)
{
//Error.
printf("Error %d.", GetLastError());
goto done;
}
//Open the device
*hDeviceHandle = CreateFile (
lpDevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (*hDeviceHandle == INVALID_HANDLE_VALUE)
{
//Error.
printf("Error %d.", GetLastError());
goto done;
}
done:
LocalFree(lpDevicePath);
LocalFree(pInterfaceDetailData);
bResult = SetupDiDestroyDeviceInfoList(hDeviceInfo);
return bResult;
}
示例11: battery_init
int battery_init() {
#define GBS_HASBATTERY 0x1
#define GBS_ONBATTERY 0x2
DWORD dwResult = GBS_ONBATTERY;
HDEVINFO hdev = NULL;
int idev = 0;
BOOL b;
DWORD cbRequired = 0;
SP_DEVICE_INTERFACE_DATA did;
hdev = SetupDiGetClassDevs(&GUID_DEVCLASS_BATTERY,
0,
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (INVALID_HANDLE_VALUE == hdev) {
//return hdev;
printf("GUID_DEVCLASS_BATTERY error\n");
return -1;
}
for (idev = 0; idev < 100; idev++) {
printf("for\n");
memset(&did, 0, sizeof(did));
did.cbSize = sizeof(did);
b = SetupDiEnumDeviceInterfaces(hdev,
0,
&GUID_DEVCLASS_BATTERY,
idev,
&did);
if (!b) {
break;
}
SetupDiGetDeviceInterfaceDetail(hdev,
&did,
0,
0,
&cbRequired,
0);
if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) {
PSP_DEVICE_INTERFACE_DETAIL_DATA pdidd =
(PSP_DEVICE_INTERFACE_DETAIL_DATA) LocalAlloc(LPTR, cbRequired);
if (!pdidd) {
log_err("battery_init: LocalAlloc failed, size %d", cbRequired);
SetupDiDestroyDeviceInfoList(hdev);
return -1;
}
pdidd->cbSize = sizeof(*pdidd);
if (SetupDiGetDeviceInterfaceDetail(hdev,
&did,
pdidd,
cbRequired,
&cbRequired,
0))
{
// Enumerated a battery. Ask it for information.
HANDLE hBattery = CreateFile(pdidd->DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE != hBattery) {
//printf("battery handle: %d\n", hBattery);
//_bat[idev] = hBattery;
_bathandle = hBattery;
LocalFree(pdidd);
break;
} else {
log_warn("battery_init: failed to open device file: %s", pdidd->DevicePath);
}
} else {
log_warn("battery_init:SetupDiGetDeviceInterfaceDetail failed");
}
LocalFree(pdidd);
} // end if ERROR_INSUFFICIENT_BUFFER
} // end for
SetupDiDestroyDeviceInfoList(hdev);
if (_bathandle != 0) {
BATTERY_INFORMATION BatteryInfo;
memset(&BatteryInfo, 0, sizeof(BATTERY_INFORMATION));
if (BatteryQueryInformation(_bathandle,
BatteryInformation,
(LPVOID)&BatteryInfo,
sizeof(BatteryInfo))) {
//.........这里部分代码省略.........
示例12: FindKnownHidDevices
BOOLEAN
FindKnownHidDevices (
OUT PHID_DEVICE * HidDevices, // A array of struct _HID_DEVICE
OUT PULONG NumberDevices // the length of this array.
)
/*++
Routine Description:
Do the required PnP things in order to find all the HID devices in
the system at this time.
--*/
{
HDEVINFO hardwareDeviceInfo;
SP_DEVICE_INTERFACE_DATA deviceInfoData;
ULONG i;
BOOLEAN done;
PHID_DEVICE hidDeviceInst;
GUID hidGuid;
PSP_DEVICE_INTERFACE_DETAIL_DATA functionClassDeviceData = NULL;
ULONG predictedLength = 0;
ULONG requiredLength = 0;
PHID_DEVICE newHidDevices;
HidD_GetHidGuid (&hidGuid);
*HidDevices = NULL;
*NumberDevices = 0;
//
// Open a handle to the plug and play dev node.
//
hardwareDeviceInfo = SetupDiGetClassDevs ( &hidGuid,
NULL, // Define no enumerator (global)
NULL, // Define no
(DIGCF_PRESENT | // Only Devices present
DIGCF_DEVICEINTERFACE)); // Function class devices.
if (INVALID_HANDLE_VALUE == hardwareDeviceInfo)
{
return FALSE;
}
//
// Take a wild guess to start
//
*NumberDevices = 4;
done = FALSE;
deviceInfoData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);
i=0;
while (!done)
{
*NumberDevices *= 2;
if (*HidDevices)
{
newHidDevices =
realloc (*HidDevices, (*NumberDevices * sizeof (HID_DEVICE)));
if (NULL == newHidDevices)
{
free(*HidDevices);
}
*HidDevices = newHidDevices;
}
else
{
*HidDevices = calloc (*NumberDevices, sizeof (HID_DEVICE));
}
if (NULL == *HidDevices)
{
SetupDiDestroyDeviceInfoList (hardwareDeviceInfo);
return FALSE;
}
hidDeviceInst = *HidDevices + i;
for (; i < *NumberDevices; i++, hidDeviceInst++)
{
if (SetupDiEnumDeviceInterfaces (hardwareDeviceInfo,
0, // No care about specific PDOs
&hidGuid,
i,
&deviceInfoData))
{
//
// allocate a function class device data structure to receive the
// goods about this particular device.
//
SetupDiGetDeviceInterfaceDetail (
hardwareDeviceInfo,
&deviceInfoData,
NULL, // probing so no output buffer yet
0, // probing so output buffer length of zero
&requiredLength,
NULL); // not interested in the specific dev-node
//.........这里部分代码省略.........
示例13: GetUSBDevices
/*
* Refresh the list of USB devices
*/
BOOL GetUSBDevices(DWORD devnum)
{
// The first two are standard Microsoft drivers (including the Windows 8 UASP one).
// The rest are the vendor UASP drivers I know of so far - list may be incomplete!
const char* storage_name[] = { "USBSTOR", "UASPSTOR", "VUSBSTOR", "ETRONSTOR", "ASUSSTPT" };
const char* scsi_name = "SCSI";
const char* usb_speed_name[USB_SPEED_MAX] = { "USB", "USB 1.0", "USB 1.1", "USB 2.0", "USB 3.0" };
// Hash table and String Array used to match a Device ID with the parent hub's Device Interface Path
htab_table htab_devid = HTAB_EMPTY;
StrArray dev_if_path;
char letter_name[] = " (?:)";
char uefi_togo_check[] = "?:\\EFI\\Rufus\\ntfs_x64.efi";
BOOL r = FALSE, found = FALSE, is_SCSI;
HDEVINFO dev_info = NULL;
SP_DEVINFO_DATA dev_info_data;
SP_DEVICE_INTERFACE_DATA devint_data;
PSP_DEVICE_INTERFACE_DETAIL_DATA_A devint_detail_data;
DEVINST parent_inst, grandparent_inst, device_inst;
DWORD size, i, j, k, l, datatype, drive_index;
ULONG list_size[ARRAYSIZE(storage_name)] = { 0 }, list_start[ARRAYSIZE(storage_name)] = { 0 }, full_list_size, ulFlags;
HANDLE hDrive;
LONG maxwidth = 0;
int s, score, drive_number, remove_drive;
char drive_letters[27], *device_id, *devid_list = NULL, entry_msg[128];
char *label, *entry, buffer[MAX_PATH], str[MAX_PATH], *method_str;
usb_device_props props;
IGNORE_RETVAL(ComboBox_ResetContent(hDeviceList));
StrArrayClear(&DriveID);
StrArrayClear(&DriveLabel);
StrArrayCreate(&dev_if_path, 128);
// Add a dummy for string index zero, as this is what non matching hashes will point to
StrArrayAdd(&dev_if_path, "");
device_id = (char*)malloc(MAX_PATH);
if (device_id == NULL)
goto out;
// Build a hash table associating a CM Device ID of an USB device with the SetupDI Device Interface Path
// of its parent hub - this is needed to retrieve the device speed
dev_info = SetupDiGetClassDevsA(&_GUID_DEVINTERFACE_USB_HUB, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
if (dev_info != INVALID_HANDLE_VALUE) {
if (htab_create(DEVID_HTAB_SIZE, &htab_devid)) {
dev_info_data.cbSize = sizeof(dev_info_data);
for (i=0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) {
if (usb_debug)
uprintf("Processing Hub %d:", i + 1);
devint_detail_data = NULL;
devint_data.cbSize = sizeof(devint_data);
// Only care about the first interface (MemberIndex 0)
if ( (SetupDiEnumDeviceInterfaces(dev_info, &dev_info_data, &_GUID_DEVINTERFACE_USB_HUB, 0, &devint_data))
&& (!SetupDiGetDeviceInterfaceDetailA(dev_info, &devint_data, NULL, 0, &size, NULL))
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
&& ((devint_detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A)calloc(1, size)) != NULL) ) {
devint_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
if (SetupDiGetDeviceInterfaceDetailA(dev_info, &devint_data, devint_detail_data, size, &size, NULL)) {
// Find the Device IDs for all the children of this hub
if (CM_Get_Child(&device_inst, dev_info_data.DevInst, 0) == CR_SUCCESS) {
device_id[0] = 0;
s = StrArrayAdd(&dev_if_path, devint_detail_data->DevicePath);
if ((s>= 0) && (CM_Get_Device_IDA(device_inst, device_id, MAX_PATH, 0) == CR_SUCCESS)) {
if ((k = htab_hash(device_id, &htab_devid)) != 0) {
htab_devid.table[k].data = (void*)(uintptr_t)s;
}
if (usb_debug)
uprintf(" Found ID[%03d]: %s", k, device_id);
while (CM_Get_Sibling(&device_inst, device_inst, 0) == CR_SUCCESS) {
device_id[0] = 0;
if (CM_Get_Device_IDA(device_inst, device_id, MAX_PATH, 0) == CR_SUCCESS) {
if ((k = htab_hash(device_id, &htab_devid)) != 0) {
htab_devid.table[k].data = (void*)(uintptr_t)s;
}
if (usb_debug)
uprintf(" Found ID[%03d]: %s", k, device_id);
}
}
}
}
}
free(devint_detail_data);
}
}
}
SetupDiDestroyDeviceInfoList(dev_info);
}
free(device_id);
// Build a single list of Device IDs from all the storage enumerators we know of
full_list_size = 0;
ulFlags = CM_GETIDLIST_FILTER_SERVICE;
if (nWindowsVersion >= WINDOWS_7)
ulFlags |= CM_GETIDLIST_FILTER_PRESENT;
for (s=0; s<ARRAYSIZE(storage_name); s++) {
// Get a list of device IDs for all USB storage devices
// This will be used to find if a device is UASP
if (CM_Get_Device_ID_List_SizeA(&list_size[s], storage_name[s], ulFlags) != CR_SUCCESS)
//.........这里部分代码省略.........
示例14: DetectAlreadyConnectedDevices
//.........这里部分代码省略.........
if (!bResult)
{
if (dwError == ERROR_NO_MORE_DEVICES || dwError == ERROR_NO_MORE_ITEMS)
break;
}
/*
Get the required size for the
PSP_DEVICE_INTERFACE_DETAIL_DATA
structure
*/
bResult = SetupDiGetDeviceInterfaceDetail(
hDevInfo,
&spDeviceInterfaceData,
NULL,
0,
&dwRequiredSize,
NULL
);
/*
Allocate that required size
*/
if (!bResult)
{
if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
pspDeviceInterfaceDetailData = new SP_DEVICE_INTERFACE_DETAIL_DATA[dwRequiredSize];//(PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR, dwRequiredSize);
pspDeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
}
else
break;
}
/*
Get the details on that device
*/
bResult = SetupDiGetDeviceInterfaceDetail(
hDevInfo,
&spDeviceInterfaceData,
pspDeviceInterfaceDetailData,
dwRequiredSize,
NULL,
NULL
);
if (bResult)
{
STORAGE_DEVICE_NUMBER storageDeviceNumber;
ZeroMemory(&storageDeviceNumber, sizeof(STORAGE_DEVICE_NUMBER));
storageDeviceNumber.DeviceNumber = 0;
DWORD dwSize = 0;
/*
Get the device handle
*/
HANDLE hDrive = CreateFile(
pspDeviceInterfaceDetailData->DevicePath,
GENERIC_READ,
FILE_SHARE_READ |
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
0
);
if (hDrive != INVALID_HANDLE_VALUE)
{
/*
Get the device number
*/
bResult = DeviceIoControl(
hDrive,
IOCTL_STORAGE_GET_DEVICE_NUMBER,
NULL,
0,
&storageDeviceNumber,
sizeof(storageDeviceNumber),
&dwSize,
NULL
);
if (bResult)
{
char cDrive = GetVolumeLabelByDiskNumber(storageDeviceNumber.DeviceNumber);
if (cDrive)
{
int iIndex = cDrive - 'A';
printf("%c:\\ will be watched\n", cDrive);
tpThreads[iIndex] = new ThreadObject(Inspection, (LPVOID)cDrive);
tpThreads[iIndex]->Start();
}
}
}
CloseHandle(hDrive);
}
delete pspDeviceInterfaceDetailData;
}
}
}
SetupDiDestroyDeviceInfoList(hDevInfo);
}
示例15: ProcessWiimotes
// Find and connect wiimotes.
// Does not replace already found wiimotes even if they are disconnected.
// wm is an array of max_wiimotes wiimotes
// Returns the total number of found and connected wiimotes.
void WiimoteScanner::FindWiimotes(std::vector<Wiimote*> & found_wiimotes, Wiimote* & found_board)
{
if (!s_loaded_ok)
return;
ProcessWiimotes(true, [](HANDLE hRadio, const BLUETOOTH_RADIO_INFO& rinfo, BLUETOOTH_DEVICE_INFO_STRUCT& btdi)
{
ForgetWiimote(btdi);
AttachWiimote(hRadio, rinfo, btdi);
});
// Get the device id
GUID device_id;
pHidD_GetHidGuid(&device_id);
// Get all hid devices connected
HDEVINFO const device_info = SetupDiGetClassDevs(&device_id, nullptr, nullptr, (DIGCF_DEVICEINTERFACE | DIGCF_PRESENT));
SP_DEVICE_INTERFACE_DATA device_data;
device_data.cbSize = sizeof(device_data);
PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = nullptr;
for (int index = 0; SetupDiEnumDeviceInterfaces(device_info, nullptr, &device_id, index, &device_data); ++index)
{
// Get the size of the data block required
DWORD len;
SetupDiGetDeviceInterfaceDetail(device_info, &device_data, nullptr, 0, &len, nullptr);
detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(len);
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
// Query the data for this device
if (SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, nullptr, nullptr))
{
auto const wm = new Wiimote;
wm->devicepath = detail_data->DevicePath;
bool real_wiimote = false, is_bb = false;
CheckDeviceType(wm->devicepath, real_wiimote, is_bb);
if (is_bb)
{
found_board = wm;
}
else if (real_wiimote)
{
found_wiimotes.push_back(wm);
}
else
{
delete wm;
}
}
free(detail_data);
}
SetupDiDestroyDeviceInfoList(device_info);
// Don't mind me, just a random sleep to fix stuff on Windows
//if (!wiimotes.empty())
// SLEEP(2000);
}