从 VB 调用非托管 DLL

发布于 2024-07-23 20:23:22 字数 284 浏览 5 评论 0原文

我在查找 VB.NET 中对非托管 DLL 进行函数调用的语法时遇到了一些麻烦。 有人熟悉这个吗?

我们假设非托管 DLL“Connector.DLL”中有一个函数“Connected”。 我想通过创建一个抽象函数调用来调用这个函数。

我见过一些代码,看起来像

[DllImport("Connector.DLL")]
Public Shared Function Connect(ByVal intPort)

但是这种语法对我不起作用。

I'm having some trouble finding the syntax for making function calls to unmanaged DLLs in VB.NET. Is anyone familiar with this?

Let's just assume there's a function "Connected" in unmanaged DLL "Connector.DLL". I want to call this function by creating an abstract function call to it.

I've seen some code out there that looks something like

[DllImport("Connector.DLL")]
Public Shared Function Connect(ByVal intPort)

But that syntax doesn't work for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在深巷 2024-07-30 20:23:22

尝试以下代码。

Public Declare Function Connect Lib "Connector.DLL" (<MarshalAs(UnmanagedType.I4)> ByVal intPort As Integer) As Integer

Try the following code.

Public Declare Function Connect Lib "Connector.DLL" (<MarshalAs(UnmanagedType.I4)> ByVal intPort As Integer) As Integer
千年*琉璃梦 2024-07-30 20:23:22

在 Visual Studio 中,添加对此 Dll 的引用。

在代码中:

Dim vr as new COMDllClass()
vr.FunctionInDll()

编辑每条评论:

尝试以下代码:

<DllImport("Connector.DLL")> _
Public Shared Function Connect(ByVal intPort)

In Visual Studio, add a reference to this Dll.

In Code:

Dim vr as new COMDllClass()
vr.FunctionInDll()

EDIT per comment:

Try this code:

<DllImport("Connector.DLL")> _
Public Shared Function Connect(ByVal intPort)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文