Win32Api USB SetupDiGetDeviceInterfaceDetail fail

前端 未结 2 1298
眼角桃花
眼角桃花 2021-01-07 03:51

I am attempting to connect to a USB GPS device. I can successfully connect to the device if I manually create a file via CreateFile WinApi (using the path specified in Devi

相关标签:
2条回答
  • 2021-01-07 04:25

    I believe I found the problem.

    After poking around pinvoke.net, I found the following

    // build a Device Interface Detail Data structure
     SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SP_DEVICE_INTERFACE_DETAIL_DATA();
     if (IntPtr.Size == 8) // for 64 bit operating systems
         didd.cbSize = 8; 
     else  didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // for 32 bit systems
    

    Changing this in my code allows me to obtain the DevicePath properly.

    Reference for those interested.

    http://pinvoke.net/default.aspx/setupapi.SetupDiGetDeviceInterfaceDetail

    0 讨论(0)
  • 2021-01-07 04:33

    Congratulations, it is working. You'll get a Unicode string, it's twice as long. And a FALSE return is correct. You just need to call Marshal.GetLastWin32Error() and verify that you got ERROR_INSUFFICIENT_BUFFER. Your C code is broken, probably because you forgot to initialize theBytesReturned to zero.

    0 讨论(0)
提交回复
热议问题