查找USB驱动程序的路径

查找USB驱动程序的路径

本文介绍了查找USB驱动程序的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在将C ++代码转换为专用USB驱动程序与C#的接口。我想摆脱使用C ++ DLL并将它包装在C#类中。



当我在C ++中调用SetupDiGetDeviceInterfaceDetail时,代码返回以下工作路径:



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



我可以使用这条路径在C ++中没有任何问题来访问我的驱动程序。



当我在C#中执行相同的函数调用时,返回的路径是\\。



似乎C#不支持?在路径字符串中。如果?,在FileStream构造函数中对有效路径进行硬编码总是返回并且无效路径错误存在于字符串中。



知道为什么C#拒绝它或者没有回到正确的路径?



- -



我发现路径搜索有问题。我的目标缓冲区没有被正确声明。该路径现在正确地进行了检索。但我还有?当我尝试创建FileStream时,caracter拒绝。



字符串DevPath = @\\?\\\ bb#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返回路径中的非法字符。

解决方案

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

解决方案


这篇关于查找USB驱动程序的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 11:58