Click here to Skip to main content
Rate this: bad
good
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 at 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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 367
1 Abhinav S 226
2 thatraja 220
3 OriginalGriff 195
4 Peter Leow 160
0 Sergey Alexandrovich Kryukov 8,849
1 OriginalGriff 5,035
2 Peter Leow 3,949
3 Maciej Los 3,535
4 Abhinav S 3,148


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid