搜索
简帛阁>技术文章>USB Device Finder

USB Device Finder

http://www.velleman.eu/images/tmp/usbfind.c

#ifdef __cplusplus
extern "C" { #endif #include <windows.h> #include <tchar.h> #include <setupapi.h> #include <initguid.h> #include <stdio.h> // This is the GUID for the USB device class DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED); // (A5DCBF10-6530-11D2-901F-00C04FB951ED) int main() { HDEVINFO hDevInfo; SP_DEVICE_INTERFACE_DATA DevIntfData; PSP_DEVICE_INTERFACE_DETAIL_DATA DevIntfDetailData; SP_DEVINFO_DATA DevData; DWORD dwSize, dwType, dwMemberIdx; HKEY hKey; BYTE lpData[1024]; // We will try to get device information set for all USB devices that have a // device interface and are currently present on the system (plugged in). hDevInfo = SetupDiGetClassDevs( &GUID_DEVINTERFACE_USB_DEVICE, NULL, 0, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); if (hDevInfo != INVALID_HANDLE_VALUE) { // Prepare to enumerate all device interfaces for the device information // set that we retrieved with SetupDiGetClassDevs(..) DevIntfData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); dwMemberIdx = 0; // Next, we will keep calling this SetupDiEnumDeviceInterfaces(..) until this // function causes GetLastError() to return ERROR_NO_MORE_ITEMS. With each // call the dwMemberIdx value needs to be incremented to retrieve the next // device interface information. SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &GUID_DEVINTERFACE_USB_DEVICE, dwMemberIdx, &DevIntfData); while(GetLastError() != ERROR_NO_MORE_ITEMS) { // As a last step we will need to get some more details for each // of device interface information we are able to retrieve. This // device interface detail gives us the information we need to identify // the device (VID/PID), and decide if it's useful to us. It will also // provide a DEVINFO_DATA structure which we can use to know the serial // port name for a virtual com port. DevData.cbSize = sizeof(DevData); // Get the required buffer size. Call SetupDiGetDeviceInterfaceDetail with // a NULL DevIntfDetailData pointer, a DevIntfDetailDataSize // of zero, and a valid RequiredSize variable. In response to such a call, // this function returns the required buffer size at dwSize. SetupDiGetDeviceInterfaceDetail( hDevInfo, &DevIntfData, NULL, 0, &dwSize, NULL); // Allocate memory for the DeviceInterfaceDetail struct. Don't forget to // deallocate it later! DevIntfDetailData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize); DevIntfDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); if (SetupDiGetDeviceInterfaceDetail(hDevInfo, &DevIntfData, DevIntfDetailData, dwSize, &dwSize, &DevData)) { // Finally we can start checking if we've found a useable device, // by inspecting the DevIntfDetailData->DevicePath variable. // The DevicePath looks something like this: // // \\?\usb#vid_04d8&pid_0033#5&19f2438f&0&2#{a5dcbf10-6530-11d2-901f-00c04fb951ed} // // The VID for Velleman Projects is always 10cf. The PID is variable // for each device: // // ------------------- // | Device | PID | // ------------------- // | K8090 | 8090 | // | VMB1USB | 0b1b | // ------------------- // // As you can see it contains the VID/PID for the device, so we can check // for the right VID/PID with string handling routines. if (NULL != _tcsstr((TCHAR*)DevIntfDetailData->DevicePath, _T("vid_10cf&pid_8090"))) { // To find out the serial port for our K8090 device, // we'll need to check the registry: hKey = SetupDiOpenDevRegKey( hDevInfo, &DevData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ ); dwType = REG_SZ; dwSize = sizeof(lpData); RegQueryValueEx(hKey, _T("PortName"), NULL, &dwType, lpData, &dwSize); RegCloseKey(hKey); // Eureka! wprintf(_T("Found a device on port '%s'\n"), lpData); } } HeapFree(GetProcessHeap(), 0, DevIntfDetailData); // Continue looping SetupDiEnumDeviceInterfaces( hDevInfo, NULL, &GUID_DEVINTERFACE_USB_DEVICE, ++dwMemberIdx, &DevIntfData); } SetupDiDestroyDeviceInfoList(hDevInfo); } return 0; }

 

http://wwwvellemaneu/images/tmp/usbfindcifdef__cplusplusexternC{endifinclude<windowsh>include&
解决:efiusbdevicehasbeenblockedbythecurrentsecuritypolicy问题描述:U盘装系统或者其他操作时,是因为BIOS安全策略,出现上述错误无法进入后续步骤。
打开「终端」,输入以下内容,然后「Return」键,这样就把隐藏的文件和文件夹显示了;defaultswritecomapplefinderAppleShowAllFilesbooleantrue;k
Mac在Finder中隐藏文件是默认是看不到的也不能修改,可以通过终端显示隐藏文件然后在Finder中查看或者修改$defaultswritecomapplefinderAppleShowAllFil
简单来讲,设备指纹是指可以用于标识出该设备的设备特征或者独特的设备标识。设备指纹因子通常包括计算机的操作系统类型,安装的各种插件,浏览器的语言设置及其时区、设备的硬件ID,手机的IMEI,电脑的网卡M
在linux系统中你使用一些命令时(例如nmon、iostat如下截图所示),有可能会看到一些名字为dmxx的设备,那么这些设备到底是什么设备呢,跟磁盘有什么关系呢?以前不了解的时候,我也很纳闷其实d
背景Android提供了很多不错的工具供开发者使用,如此篇文章标题所说的Monitor,当接收新的项目的时候,我往往习惯于先从UI入手,通过各个控件布局的加载点击等逻辑梳理代码,但是当代码里比较大,或
效果:方法:添加:打开finder后,长按command,可以将其他app拖到菜单栏。删除:同理,长按command,将不需要的图标拖出菜单栏即可。PS:强烈推荐gotoshell这个小工具,可以很
usb插入拔出对应数字状态usbusb2:usb_set_device_state7>8enumusb_device_state{/*NOTATTACHEDisn'tintheUSBspec,
区别:拆解两根线之后,会发现USB数据线的第4pin是悬空的,OTG数据线的第4pin是短接到地的,手机芯片应该是通过第4pin判断插入的是OTG数据线还是USB数据线,并以此来决定是否打开OTG供