msdn CM_GET_Parent 示例不起作用
我正在努力从我插入的 USB 设备获取设备 ID...
上面的应用程序适用于 win-Xp,但不适用于 Windows 7
当我尝试计算它时,我发现 CM_Get_Parent () 不起作用...
任何人都可以吗指导我为什么它不起作用......以及是否有任何可以在 Windows 7
源代码上工作的兼容功能:
HDEVINFO hDevInfo;
GUID guid;
BYTE buffer[ 1024 ];
DWORD dwRequiredSize ;
WCHAR buf[ 1024 ];
DEVINST devInstParent;
WCHAR volume[1024];
int aLength, anIndex;
SP_DEVICE_INTERFACE_DATA devInterfaceData;
SP_DEVINFO_DATA devInfoData;
PSP_DEVICE_INTERFACE_DETAIL_DATA pDevDetail;
guid = GUID_DEVINTERFACE_VOLUME;
hDevInfo = SetupDiGetClassDevs( &guid, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT );
if( hDevInfo == INVALID_HANDLE_VALUE )
{
qDebug() << "Error - SetupDiGetClassDevs failed\n";
}
for( DWORD dwIndex = 0;; dwIndex ++ )
{
ZeroMemory( &devInterfaceData, sizeof( devInterfaceData ) );
devInterfaceData.cbSize = sizeof(devInterfaceData );
if( !SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &guid,dwIndex, &devInterfaceData ) )
{
break;
}
ZeroMemory( &devInfoData, sizeof( devInfoData ) );
devInfoData.cbSize = sizeof(devInfoData);
pDevDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)buffer;
pDevDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA );
// Get device interface detail data to get Device Instance from
// SP_DEVINFO_DATA and Device Path from SP_DEVICE_INTERFACE_DETAIL_DATA
SetupDiGetDeviceInterfaceDetail(
hDevInfo,&devInterfaceData,
pDevDetail, // SP_DEVICE_INTERFACE_DETAIL_DATA
1024,&dwRequiredSize,&devInfoData ); // SP_DEVINFO_DATA
CM_Get_Parent( &devInstParent,devInfoData.DevInst, 0 );
CM_Get_Parent( &devInstParent,devInstParent, 0 );
CM_Get_Device_ID( devInstParent, buf, 1024,0 );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下稍作修改的代码
在我的 Windows 7 计算机上运行没有任何问题,并产生如下输出:
基于评论的更新:在 VMware 中的 Windows XP 上,相同的实用程序产生以下
输出它是另一个操作系统上的另一台计算机(虚拟计算机),我们收到另一个设备列表。您当前的问题是使函数
CM_Get_Parent()
在 Windows XP 和 Windows 7 上运行。发布的代码就像我们所看到的那样。或者它现在可以在您的 Windows XP 或 Windows 7 计算机上正常工作吗?如何获取pid和vid(产品id和ventor id)我在获取有关 Windows7 - 32 位系统上的磁盘驱动器结果的信息,但对于任何驱动器号 而不适用于音量设备。人们可以轻松更改代码以显示更多信息,例如卷名称、总线名称和其他信息。但这一切已经是另一个问题了。
更新:我从 在 .ok-soft-gmbh.com/ForStackOverflow/EnumMassStorage.c" rel="nofollow noreferrer">http://www.ok-soft-gmbh.com/ForStackOverflow/EnumMassStorage.c 因为受到限制stackoverflow.com 中的消息大小。测试输出类似于 http://www.ok-soft-gmbh.com /ForStackOverflow/EnumMassStorage.txt
The following a litle modified code
work without any problem on my Windows 7 computer and produce output like following:
UPDATED based on the comment: On my Windows XP in the VMware the same utility produce the following output
Of cause it is another computer (a virtual computer) on the other operation system and we receive another list of devices. You current question was to make the function
CM_Get_Parent()
working on both Windows XP and Windows 7. The posted code do this like we can see. Or it is now work correctly on your Windows XP or Windows 7 computer?How to get pid and vid (product id and ventor id) I described in Get information about disk drives result on windows7 - 32 bit system, but for any drive letters and not for the volume devices. One can easy change the code to show more information like Volume name, Bus name and other information. But this all is already another question.
UPDATED: I placed the extended version of program from Get information about disk drives result on windows7 - 32 bit system under http://www.ok-soft-gmbh.com/ForStackOverflow/EnumMassStorage.c because of restriction with the message size in stackoverflow.com. The test output looks like http://www.ok-soft-gmbh.com/ForStackOverflow/EnumMassStorage.txt