Win32Api USB SetupDiGetDeviceInterfaceDetail fail

前端 未结 2 1299
眼角桃花
眼角桃花 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

提交回复
热议问题