why the SetupDiGetDevicePropertyW function back to false?

  • Thread starter Thread starter twohorses111
  • Start date Start date
T

twohorses111

Guest
I want to use the SetupDiGetDevicePropertyW function to get DEVPKEY_Device_LocationInfo information for HID devices(Location Info: Port_ 0003. Hub_ 0003), I use the SetupDiGetDevicePropertyW function, but the functions back to false. Can anyone help me see it? The main code is as follows:


[DllImport("hid.dll", SetLastError = true)]
public static extern IntPtr HidD_GetHidGuid(ref Guid gClass);

[DllImport("setupapi.dll", SetLastError = true)]
public static extern IntPtr SetupDiGetClassDevs(ref Guid gClass, UInt32 iEnumerator, IntPtr hParent, DiGetClassFlags nFlags);

[DllImport("setupapi.dll", SetLastError = true)]
public static extern bool SetupDiEnumDeviceInfo(
IntPtr DeviceInfoSet, UInt32 MemberIndex, ref SP_DEVINFO_DATA DeviceInterfaceData);

[DllImport("setupapi.dll", SetLastError = true)]
static extern bool SetupDiGetDevicePropertyW(
IntPtr deviceInfoSet,
[In] ref SP_DEVINFO_DATA DeviceInfoData,
[In] ref DEVPROPKEY propertyKey,
[Out] out UInt32 propertyType,
byte[] propertyBuffer,
UInt32 propertyBufferSize,
out UInt32 requiredSize,
UInt32 flags);

Guid myguid;
myguid = new Guid();
IntPtr result;
result = HidD_GetHidGuid(ref myguid);

IntPtr DeviceInfoSet;
DeviceInfoSet = SetupDiGetClassDevs(ref myguid, 0, IntPtr.Zero, DiGetClassFlags.DIGCF_PRESENT | DiGetClassFlags.DIGCF_DEVICEINTERFACE);

SP_DEVINFO_DATA deviceInfoData = new SP_DEVINFO_DATA();

deviceInfoData.cbSize = (uint)Marshal.SizeOf(typeof(SP_DEVINFO_DATA));

bool success = SetupDiEnumDeviceInfo(DeviceInfoSet, iMemberIndex, ref deviceInfoData);

DeviceInfo deviceInfo = new UsbEnumHelper.DeviceInfo();

byte[] ptrBuf = new byte[BUFFER_SIZE];
uint propRegDataType;
uint RequiredSize;

DevicePortDesc = new DEVPROPKEY();
DevicePortDesc.fmtid = new Guid(0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0);
DevicePortDesc.pid = 15

bool success = SetupDiGetDevicePropertyW(hDeviceInfoSet, ref deviceInfoData, ref DevicePortDesc, out propRegDataType, ptrBuf, BUFFER_SIZE, out RequiredSize, 0);

Continue reading...
 

Similar threads

Back
Top