声明并在VB.NET中有不同的结果
我一直在尝试调用非托管 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Declare 语句的默认字符集是 Ansi。您需要将字符集设置为 Unicode 以正确匹配 DllImport。
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.
MSDN documentation for the Declare statement