开发者

Declare and <DllImport> in VB.NET have different results

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 ??


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜