Re: Getting the "bus relations" of a device by Toto
Toto
Mon Oct 16 03:49:02 CDT 2006
Thank you Peter, this was the trick!
Please find the complete code to get the DeviceID of a device parent:
// Enumerate imaging devices and get their parent's DeviceID
bool enumDevices ()
{
// Create a HDEVINFO with all "imaging devices"
HDEVINFO hDevInfo =3D SetupDiGetClassDevs
(&GUID_VideoInputDeviceCategory,
0L, // Enumerator
0L, // hwndParent
DIGCF_PRESENT);
if (hDevInfo =3D=3D INVALID_HANDLE_VALUE)
return false;
// Enumerate through all USB devices in Set.
SP_DEVINFO_DATA deviceInfoData;
deviceInfoData.cbSize =3D sizeof (SP_DEVINFO_DATA);
for (DWORD i=3D0; SetupDiEnumDeviceInfo (hDevInfo, i,
&deviceInfoData); i++)
{
ULONG hdevParent;
// Get parent device handle
if (CM_Get_Parent (&hdevParent, deviceInfoData.DevInst, 0) !=3D
CR_SUCCESS)
continue;
// Get device ID string length
ULONG ulSize =3D 0;
if (CM_Get_Device_ID_Size (&ulSize, hdevParent, 0) !=3D CR_SUCCESS)
continue;
// Get parent device DeviceID
BYTE* strParentDeviceID =3D new BYTE [ulSize + 1];
if (CM_Get_Device_ID (hdevParent, strParentDeviceID, ulSize + 1,
0) !=3D CR_SUCCESS)
continue;
delete [] strParentDeviceID;
}
// Cleanup
SetupDiDestroyDeviceInfoList (hDevInfo);
return true;
}
Peter Wieland [MSFT] a =E9crit :
> I think you may have to dip back into the CfgMgr32 APIs. See
> CM_Get_Parent() in the DDK documentation.
>
> -p
>
>
> "Toto" <marti.gaetan@bluewin.ch> wrote in message
> news:1160637794.348835.93120@b28g2000cwb.googlegroups.com...
> > OK, but how can I get the "bus relations" programmatically in non
> > kernel mode?
> >
> >
> > Peter Wieland [MSFT] wrote:
> >> you can choose the "view by connection" option in device manager to see
> >> the
> >> relations.
> >>
> >> -p
> >>
> >> "Toto" <marti.gaetan@bluewin.ch> wrote in message
> >> news:1160581614.726542.29890@c28g2000cwb.googlegroups.com...
> >> >I have a webcan that is both appearing in the "USB controllers" and
> >> > "Imaging Devices" sections in the Device Manager. How can I find the
> >> > relations between the two drivers (in user mode).
> >> >
> >> > I have tried SetupDiGetDeviceRegistryProperty but it seems there is =
no
> >> > unique property that I can use.
> >> >
> >> > One possible way would be to retrieve the "bus relations" of a device
> >> > as displayed in the Device Manager->Device XXX->Details->Bus relatio=
ns.
> >> > But how ?
> >> >
> >