声明并在VB.NET中有不同的结果

发布于 2024-09-07 18:38:37 字数 759 浏览 1 评论 0原文

我一直在尝试调用非托管 DLL 的登录方法。

如果我使用声明登录失败。

Private Declare Function Login Lib "dllCore" (ByVal lpName As String, ByVal lpPassword As String) As Int32

Login ("Steve", "123456") ' THIS FAILS TO LOGIN ALTHOUGH THE PARAMS ARE CORRECT

如果我使用 DllImport,它就可以工作!

    <DllImport("dllCore.dll", 
                EntryPoint:="Login", 
                SetLastError:=True, 
                CharSet:=CharSet.Unicode, 
                ExactSpelling:=True, 
                CallingConvention:=CallingConvention.StdCall)> 
        Private Function Login(ByVal username As String, ByVal password As String) As Integer
        End Function

Login ("Steve", "123456") ' NOW WORKS 

有谁知道我为什么会出现这种行为?

I've been trying to call a login method of an unmanaged DLL.

If I use Declare the login fails.

Private Declare Function Login Lib "dllCore" (ByVal lpName As String, ByVal lpPassword As String) As Int32

Login ("Steve", "123456") ' THIS FAILS TO LOGIN ALTHOUGH THE PARAMS ARE CORRECT

If I use DllImport, it works !!

    <DllImport("dllCore.dll", 
                EntryPoint:="Login", 
                SetLastError:=True, 
                CharSet:=CharSet.Unicode, 
                ExactSpelling:=True, 
                CallingConvention:=CallingConvention.StdCall)> 
        Private Function Login(ByVal username As String, ByVal password As String) As Integer
        End Function

Login ("Steve", "123456") ' NOW WORKS 

Has anyone any ideas why I get this behaviour ??

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

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

发布评论

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

评论(1

如日中天 2024-09-14 18:38:37

Declare 语句的默认字符集是 Ansi。您需要将字符集设置为 Unicode 以正确匹配 DllImport。

Private Declare Unicode Function Login Lib "dllCore" (ByVal lpName As String, ByVal lpPassword As String) As Int32

Declare 语句的 MSDN 文档

The default character set for a Declare statement is Ansi. You need to set the charset to Unicode to properly match the DllImport.

Private Declare Unicode Function Login Lib "dllCore" (ByVal lpName As String, ByVal lpPassword As String) As Int32

MSDN documentation for the Declare statement

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文