Click here to Skip to main content
12,354,630 members (55,777 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:

"\\?\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 21-Dec-12 5:34am
SysProg564
Edited 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

Rate this: bad
 
good
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
 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[^]
  Permalink  

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.160621.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2016
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