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
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
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.