扫描USB硬件时,怎么获取usb设备类别guid的GUID

得到设备_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
上传于||暂无简介
阅读已结束,如果下载本文需要使用2下载券
想免费下载本文?
定制HR最喜欢的简历
你可能喜欢本帖子已过去太久远了,不再提供回复功能。3210人阅读
VC++(40)
#include &windows.h&
#include &stdio.h&
#include &Shlwapi.h&
#include &conio.h&
extern &C& {
// Declare the C libraries used
#include &setupapi.h&
// Must link in setupapi.lib
#include &hidsdi.h&
// Must link in hid.lib
static /*const*/ GUID GUID_DEVINTERFACE_USB_DEVICE =
{ 0xA5DCBF10L, 0xD2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };
TCHAR * GetErrString(TCHAR *str, DWORD errcode)
if(FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpbuf,
lstrcpy(str,(LPCWSTR)lpbuf);
LocalFree(lpbuf);
int main(int argc, char* argv[])
char szTraceBuf[256];
// Get device interface info set handle for all devices attached to system
HDEVINFO hDevInfo = SetupDiGetClassDevs(
&GUID_DEVINTERFACE_USB_DEVICE, /* CONST GUID * ClassGuid - USB class GUID */
NULL, /* PCTSTR Enumerator */
NULL, /* HWND hwndParent */
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE /* DWORD Flags */
if (hDevInfo == INVALID_HANDLE_VALUE)
sprintf(szTraceBuf, &SetupDiClassDevs() failed. GetLastError() & \
&returns: 0x%x\n&, GetLastError());
OutputDebugStringA(szTraceBuf);
sprintf(szTraceBuf, &Device info set handle for all devices attached to & \
&system: 0x%x\n&, hDevInfo);
OutputDebugStringA(szTraceBuf);
// Retrieve a context structure for a device interface of a device
// information set.
DWORD dwIndex = 0;
SP_DEVICE_INTERFACE_DATA devInterfaceD
ZeroMemory(&devInterfaceData, sizeof(SP_DEVICE_INTERFACE_DATA));
devInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
BOOL bRet = FALSE;
neededLength,requiredL
PSP_DEVICE_INTERFACE_DETAIL_DATA
ClassDeviceD
HIDD_ATTRIBUTES
while(TRUE)
bRet = SetupDiEnumDeviceInterfaces(
hDevInfo, /* HDEVINFO DeviceInfoSet */
NULL, /* PSP_DEVINFO_DATA DeviceInfoData */
&GUID_DEVINTERFACE_USB_DEVICE, /* CONST GUID * InterfaceClassGuid */
&devInterfaceData /* PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData */
if (!bRet)
TCHAR buffer[1024];
TCHAR szTraceBuf[1024];
GetErrString(buffer,GetLastError());
wsprintf(szTraceBuf, L&SetupDiEnumDeviceInterfaces failed msg:%s&,buffer);
OutputDebugStringW(szTraceBuf);
if (GetLastError() == ERROR_NO_MORE_ITEMS)
发现一个HID设备,获取设备的详细信息
第一次调用SetupDiGetDeviceInterfaceDetail得到ClassDeviceData的大小,但返回错误
SetupDiGetDeviceInterfaceDetail(hDevInfo,&devInterfaceData,
NULL,0,&requiredLength,NULL);
neededLength
=requiredL
ClassDeviceData
=(PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(neededLength);
ClassDeviceData-& cbSize
=sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
//第二次调用SetupDiGetDeviceInterfaceDetail
使用 合适的neededLength.
(!SetupDiGetDeviceInterfaceDetail(hDevInfo,&devInterfaceData,
ClassDeviceData,neededLength,&requiredLength,NULL))
free(ClassDeviceData);
SetupDiDestroyDeviceInfoList(hDevInfo);
建立HID设备的句柄
HANDLE handle=CreateFile(ClassDeviceData-& DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,OPEN_EXISTING,0,NULL);
attributes
以便得到Vendor
HidD_GetAttributes(handle,&attributes);
TCHAR buffer[1024];
wsprintf(buffer,L&name:%s pid=%d vid=%d version=%d \n&,ClassDeviceData-& DevicePath,attributes.ProductID,attributes.VendorID,attributes.VersionNumber);
OutputDebugStringW(buffer);
CloseHandle(handle);
free(ClassDeviceData);
dwIndex++;
sprintf(szTraceBuf, &Number of device interface sets representing all & \
&devices attached to system: %d\n&, dwIndex);
OutputDebugStringA(szTraceBuf);
SetupDiDestroyDeviceInfoList(hDevInfo);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1135460次
积分:19050
积分:19050
排名:第344名
原创:753篇
转载:323篇
评论:169条
我的其他技术博客站点,欢迎关注。
(13)(39)(31)(17)(18)(34)(21)(42)(49)(10)(14)(10)(11)(21)(21)(26)(24)(15)(17)(24)(9)(24)(14)(17)(15)(24)(39)(28)(14)(19)(27)(35)(10)(16)(31)(12)(13)(41)(32)(16)(18)(14)(2)(10)(37)(9)(29)(3)(30)(12)(16)(10)(1)
算法分析与设计和算法导论2088人阅读
操作系统(14)
1、硬件设备在注册表中位置:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class下;
2、获取设备端口号:
l& 首先要知道设备的GUID号,同时要看这个号在系统提供的库中是否有定义,如果没有的话,得在应用之前定义一下:如GUID号为5F4-40E5-96BA-BD86D03004B2则应定义为:
Static const GUID GUID_DEVCLASS_***={0x5FxE5,{0x96,0xBA,0XBD,0x86,0xD0,0x30,0x04, 0xB2}};
l& SetupDiGetClassDevs();获取该类型所有设备信息结构的句柄。
使用此函数,需要包含头文件setupapi.h。
此外,在project setting中的link页面需要添加setupapi.lib。
l& SetupDiEnumDeviceInfo();枚举指定类型设备信息,建立循环去一个一个匹配比对
l& SetupDiGetDeviceRegistryProperty();获取单个装置的详细信息
l& 通过strstr()函数比对设备名,即在设备管理器中看到的端口号前的名称,找到设备,再通过端口类型,比如COM字符,找到它,其后的字符就应该是串口号。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:120661次
积分:2046
积分:2046
排名:第15412名
原创:75篇
转载:61篇
(1)(1)(1)(1)(1)(1)(3)(17)(12)(5)(5)(4)(3)(5)(2)(3)(3)(8)(8)(20)(4)(4)(13)(11)

我要回帖

更多关于 oracle获取guid 的文章

 

随机推荐