在DLL中使用WinUSB?(Using WinUSB within a DLL?)

编程入门 行业动态 更新时间:2024-10-27 11:19:45
DLL中使用WinUSB?(Using WinUSB within a DLL?)

我正在研究一种可以与单个应用程序通信的USB设备。 看起来我们可能想要一个Windows驱动程序,它为应用程序提供了更好的软件接口。 (与让应用程序本身通过WinUSB向设备发送低级命令相反。)

是否可以在DLL中使用WinUSB? 选择用于开发USB客户端驱动程序的驱动程序模型并没有具体解决这个问题。

在这种情况下是否有理由我应该考虑编写基于UMDF或KMDF的驱动程序,或者调用WDM例程的混合驱动程序?

I'm working on a USB device that will talk to a single application. It looks like we may want to have a Windows driver that presents a nicer software interface to the application. (As opposed to having the application itself send lower-level commands to the device via WinUSB.)

Is it possible to use WinUSB from within a DLL? Choosing a driver model for developing a USB client driver doesn't address that specifically.

Are there reasons in this situation that I should instead consider writing a UMDF-based or KMDF-based driver, or a hybrid driver that calls WDM routines?

最满意答案

使用WinUSB可能是正确的方法。 你绝对可以在DLL中使用WinUSB。 通常,您可以编写一个DLL来调用另一个DLL中的函数,并且winusb.dll没有什么特别之处可以阻止您这样做。 此外,它已经在其他项目中完成,如libusb和libusbp,它们编译为使用winusb.dll的DLL。

我还鼓励您使代码跨平台:不要直接从您的DLL调用WinUSB,而是使用USB抽象库,如libusb或libusbp 。 即使您只想支持Windows,这些库比SetupAPI和WinUSB更容易使用,因此它们应该节省开发时间。 如果您希望代码在不同的操作系统上运行,它们还可以节省大量时间。

我认为在这种情况下编写自己的UMDF或KMDF驱动程序的唯一原因是,如果您需要WinUSB不支持的Windows USB堆栈的高级功能。 例如,如果您需要将设备切换到不同的USB配置,或者使用电源管理进行棘手的操作,或允许多个应用程序同时使用该设备。 如果您只想来回发送一些数据,WinUSB是个不错的选择。

Using WinUSB is probably the right way to go. You can definitely use WinUSB within a DLL. In general, you can write a DLL that calls functions in another DLL, and there is nothing special about winusb.dll that prevents you from doing that. Also, it is already done in other projects like libusb and libusbp, which compile to a DLL that uses winusb.dll.

I would also encourage you to make your code cross-platform: don't call WinUSB directly from your DLL, but instead use a USB abstraction library such as libusb or libusbp. Even if you only want to support Windows, these libraries are lot easier to use than SetupAPI and WinUSB, so they should save development time. They will also save a lot of time if you ever want your code to work on different operating systems.

I think the only reason to write your own UMDF or KMDF driver in a situation like this is if you need advanced features of the Windows USB stack that are not supported by WinUSB. For instance, if you needed to switch your device to a different USB configuration, or do tricky stuff with power management, or allow multiple applications to use the device at once. If you just want to send some data back and forth, WinUSB is a fine choice.

更多推荐

本文发布于:2023-07-30 06:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:DLL   WinUSB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!