Hello,
I hope someone can help.
I been struggling for days on this function, and it is quite hard to get an answer from the internet.
I am trying to get the location information of the child usb device, using CM_Get_DevNode_Property.
It works perfectly ok on Windows 7 x64, but fails on Windows 7 x86, with return code : CR_INVALID_FLAG
I searched and searched on the internet, but cannot find a good answer.
I do hope someone can.
Below is the code function, i used to get the location information. Thank you very much in advance.
Have a good day.
internal void EnumerateNode()
{
uint inst;
int result = NativeMethods.CM_Get_Child(out inst, this.DevicePtr, 0);
while (inst != 0)
{
int nBytes = 4096;
IntPtr ptrInstanceBuf = Marshal.AllocHGlobal(nBytes);
try
{
NativeMethods.CM_Get_Device_ID(inst, ptrInstanceBuf, nBytes, 0);
string instanceID = Marshal.PtrToStringAuto(ptrInstanceBuf);
IntPtr locationBuffer = Marshal.AllocHGlobal(nBytes);
try
{
ulong size = (ulong)nBytes;
NativeMethods.DevPropKey location = new NativeMethods.DevPropKey();
location.guid = new Guid(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0);
location.id = NativeMethods.Device_LocationInfoId;
ulong propType = 0;
string locationInfo = string.Empty;
if (NativeMethods.CM_Get_DevNode_Property(inst, location, out propType, locationBuffer, ref size, 0) == 0)
{
locationInfo = Marshal.PtrToStringUni(locationBuffer);
}
UsbNode node = new UsbNode(instanceID, locationInfo, inst);
this.UsbNodes.Add(node);
node.EnumerateNode();
NativeMethods.CM_Get_Sibling(out inst, inst, 0);
}
finally
{
Marshal.FreeHGlobal(locationBuffer);
}
}
finally
{
Marshal.FreeHGlobal(ptrInstanceBuf);
}
}
}