查找USB驱动程序的路径 [英] Finding path to USB driver
问题描述
大家好,
我正在将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返回路径中的非法字符。
我在网上发现了一个类似的问题,不知道你是否经历过这个或者不。如果没有,请查看此 win32api-usb-setupdigetdeviceinterfacedetail-fail [ ^ ]
这是与PInvoke有关的东西API调用
来自以上链接
/ / 构建设备接口详细信息数据结构
SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SP_DEVICE_INTERFACE_DETAIL_DATA( );
if ( IntPtr .Size == 8 ) // 适用于64位操作系统
didd.cbSize = 8 跨度>;
else didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // 适用于32位系统
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. "
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
这篇关于查找USB驱动程序的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!