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);
NativeMethods.CM_Get_Device_ID(inst, ptrInstanceBuf, nBytes,
0
);
string
instanceID = Marshal.PtrToStringAuto(ptrInstanceBuf);
IntPtr
locationBuffer = Marshal.AllocHGlobal(nBytes);
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);
Remarks
"This function is reserved for system use. Do not use this function in your class installers, co-installers, or device installation applications. Use
SetupDiGetDeviceProperty
instead."
Perhaps you have already tried this path.
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.