我從USB設備插入我得到的設備ID的工作...MSDN CM_GET_Parent例不起作用
上述申請工作在雙贏的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);
}
前段時間我發佈了一個代碼示例在http://stackoverflow.com/questions/3098696/how-to-get-the-vid-pid-and-drive-letter-for所有使用'CM_Get_Parent'和我在Windows 7下測試過的usb-mass-storage-devices-plug。所以如果你有一個'CM_Get_Parent()'函數不工作的例子,你應該發佈相應的代碼示例可以用來重現問題。 – Oleg 2010-08-06 10:44:59