使用 DLL/驱动程序的最佳解决方案?
我正在为我们的 POS 应用程序使用 CD722UN 客户显示器。
它带有一个USB2.0连接和一个包含驱动程序等的安装包。
现在,用于我的应用程序。当我想访问这个驱动程序时我该怎么办?
目前我正在使用“CD722UN 应用程序”的 .dll 路径,但这可能会受到客户端操作系统等的影响。
Declare Function opencd722usb Lib "C:\Program\cd7220 USB\cd722dusb.dll" () As Boolean
Declare Function writecd722usb Lib "C:\Program\cd7220 USB\cd722dusb.dll" (ByRef dataoutput As Byte, ByVal Length As Integer) As Integer
Declare Function readcd722usb Lib "C:\Program\cd7220 USB\cd722dusb.dll" (ByRef DataInput As Byte, ByVal size As Integer) As Integer
Declare Function closecd722usb Lib "C:\Program\cd7220 USB\cd722dusb.dll" () As Boolean
我的第一个想法是首先检查设备管理器中是否安装了设备,并以某种方式使用那里的驱动程序???
或
将 .dll 分发到我们的应用程序文件夹中并使用
searchpath ""安装目录"\cd722dusb.dll"
最好的解决方案是什么?
提前致谢!
Im working with a CD722UN Customer Display for our POS application.
it comes with a USB2.0 connection and a installation package containing a driver ect..
now, for my application. how should i do when i want to access this driver?
at the moment i'm using the "CD722UN application"s .dll path but that can warry from clients OS ect..
Declare Function opencd722usb Lib "C:\Program\cd7220 USB\cd722dusb.dll" () As Boolean
Declare Function writecd722usb Lib "C:\Program\cd7220 USB\cd722dusb.dll" (ByRef dataoutput As Byte, ByVal Length As Integer) As Integer
Declare Function readcd722usb Lib "C:\Program\cd7220 USB\cd722dusb.dll" (ByRef DataInput As Byte, ByVal size As Integer) As Integer
Declare Function closecd722usb Lib "C:\Program\cd7220 USB\cd722dusb.dll" () As Boolean
my first thought was to first check if there was a device installed in the device manager and somehow use the driver from there???
or
distribute the .dll inside our application folder and use
searchpath ""installed directory"\cd722dusb.dll"
what is the best solution?
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您没有关于如何正确访问设备的文档为零时,弄清楚如何自己访问设备通常不是一个好主意。有太多的可能性,并且代码在托管语言中可能会非常尴尬。如果供应商已经提供了访问 DLL,您可能甚至无法获得任何文档。
如果您只需将 DLL 复制到与 EXE 相同的文件夹中,该 DLL 就可以正常工作。首先尝试一下,Declare 语句中只需要 DLL 名称。如果遇到问题,请在安装目录中查找可能需要复制的其他 DLL。如果您可以在运行时发现路径,下一个选项是 P/Invoke SetDllDirectory() 函数。下一个选项是让安装程序将包含 DLL 的目录添加到系统 PATH 环境变量中。对路径进行硬编码是最后的手段。
Figuring out how to access the device yourself is not typically a good idea when you have zero documentation on how to do so properly. There are too many possibilities and the code can be quite awkward in a managed language. You probably can't even get any documentation if the supplier already provides an access DLL.
The odds are pretty good that this DLL will work if you simply copy the DLL into the same folder as your EXE. Try that first, only the DLL name is required in the Declare statement. Look in the install directory for other DLLs that might need to be copied as well if you have trouble. The next option is to P/Invoke the SetDllDirectory() function if you can discover the path at runtime. The next option is to have the installer add the directory that contains the DLL to the system PATH environment variable. Hard-coding the path is your last resort.