Click here to Skip to main content
12,894,700 members (62,334 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
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:


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 21-Dec-12 5:34am
Updated 21-Dec-12 10:29am
CHill60 21-Dec-12 12:14pm
Can you post your C# code that calls the function?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
// build a Device Interface Detail Data structure
 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[^]

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100