VB to Xojo translation help

I need to make a dll work with Xojo… but I am failing…

Here’s the VB6 code the comes with the documentation. I tried and it works… In xojo, the Dll seems to load fine, but I get a connection error…

[code]

Private Declare Function InitIDCard Lib “IDCard.dll” (ByVal lpUserId As String, ByVal nType As Long, ByVal lpDirectory As String) As Long

Private Sub Command1_Click()

If m_bIsInitSuccess = True Then
        ResultTextBox.Text = "The recognition engine is loaded successfully."

        Exit Sub
    End If
    Dim nRet As Long
    Dim strTmp As String
    strTmp = "5317480525913680254"
    
    nRet = InitIDCard(StrConv(strTmp, vbUnicode), 0, StrConv("", vbUnicode))
    If nRet = 0 Then
        ResultTextBox.Text = "The recognition engine is loaded successfully."
      
        m_bIsInitSuccess = True
    Else
        ResultTextBox.Text = "Recognition engine loaded failure. Err ." & Str(nRet)

        m_bIsInitSuccess = False
    End If

End Sub[/code]

Here’s the proposed Xojo Code

[code]Declare Function InitIDCard Lib “IDCard.dll” (ByVal lpUserId As cString, ByVal nType As Integer, ByVal lpDirectory As cString) As integer

If m_bIsInitSuccess = True Then
MsgBox ( “The recognition engine is loaded successfully.”)

Exit Sub

End If

Dim nRet As Integer
Dim strTmp As CString = “5317480525913680254”

nRet = InitIDCard(strTmp, 0, “”)

If nRet = 0 Then
MsgBox ( “The recognition engine is loaded successfully.”)

m_bIsInitSuccess = True

Else
MsgBox ( "Recognition engine loaded failure. Err " + Str(nRet))

m_bIsInitSuccess = False

End If[/code]

Thanks!

Found the solution… I had to use Wstring…

I have VERY little experience with declares…

Maybe someone can enlighten me on when to use Cstring and when to use Wstring ?

Hi Roman,

Here is an explanation from my I Wish I Knew How To… Implement Declares with Xojo on Windows book.

[code]A function with an ‘A’ suffix (MessageBoxA) means that it uses an ANSI string. ANSI is a standard which has 256 computer symbols (8-bits) and all older OS’s use ASCII. All Windows operating systems support ANSI and many of the languages used today are not supported on ANSI. An example would be writing a program in the English language and the characters may not port over to the Japanese language. Writing code in Unicode solves this multi-language problem.

A ‘W’ suffix (MessageBoxW) means that the function uses a Unicode string (Wide). Unicode has up to 65,536 characters and is much more complex. All of these characters enable the operating system to support almost all of the languages on earth. Many Newer Windows OS systems use Unicode such as: Windows NT (as UCS-2), Windows 2000, Windows XP, Windows 7,8,10 and future releases of Windows.

When using a string in an ANSI (A) declare, use CString. When using a string in a Wide (Unicode W) declare, use the WString.

New programs should all be written in Unicode.
[/code]

Warm regards.

It’s clear now.
Thank you so much Eugene!!