Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm converting a C++ code use to interface to a proprietary USB driver to C#. I want to get rid of using a C++ dll and wrap the interface it in a C# class.

When I call SetupDiGetDeviceInterfaceDetail in C++, the code returns the following working path:

"\\?\usb#vid_1fed&pid_0002#6&2bc2ca&0&3#{51fe8f30-ef12-11dd-ba2f-0800200c9a66}"

I can use this path without any problem in C++ to access my driver.

When I do the same function call in C#, the returned path is "\\".

It seems that C# doesn't support a "?" in the path string. Hardcoding the valid path in FileStream constructor always return and invalid path error if the "?" is present in the string.

Any idea why C# refuses it or doesn't return the right path?

---

I found the trouble with my path search. My destination buffer wasn't declared correctly. The path is now retreive correctly. But I still have the "?" caracter refused when I try to create the FileStream.

string DevPath = @"\\?\usb#vid_1fed&pid_0002#6&2bc2ca&0&3#{51fe8f30-ef12-11dd-ba2f-0800200c9a66}\PIPE00";

FileStream fs = new FileStream(DevPath, FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream returns "Illegal characters in path. "
Posted
Updated 21-Dec-12 10:29am
v2
Comments
CHill60 21-Dec-12 12:14pm    
Can you post your C# code that calls the function?

1 solution

I found a similar issue on the net not sure whether you gone through this or not. If not check this win32api-usb-setupdigetdeviceinterfacedetail-fail[^]
this is something related to the PInvoke API call

excert from the above link
C#
// 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 


some info here too MSDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900