VB DLL aufruf in Autoit umsetzen

  • Hallo,

    Ich möschte eine DLL die in VB einwandfrei Funktioniert aufrufen,

    Spoiler anzeigen

    Public Declare Function RSA_encrypt Lib "rsa_dll.dll" _
    (ByRef Source As Byte, ByVal Source_size As Long, _
    ByRef Target As Byte, ByVal Target_size As Long, _
    ByRef Certificate As Byte, ByVal Certificate_size As Long) As Long

    Public Declare Function RSA_decrypt Lib "rsa_dll.dll" _
    (ByRef Source As Byte, ByVal Source_size As Long, _
    ByRef Target As Byte, ByVal Target_size As Long, _
    ByRef Certificate As Byte, ByVal Certificate_size As Long) As Long

    Public Declare Function RSA_verify Lib "rsa_dll.dll" _
    (ByRef Source As Byte, ByVal Source_size As Long, _
    ByRef Target As Byte, ByVal Target_size As Long, _
    ByRef Certificate As Byte, ByVal Certificate_size As Long) As Long

    Public Declare Function RSA_sign Lib "rsa_dll.dll" _
    (ByRef Source As Byte, ByVal Source_size As Long, _
    ByRef Target As Byte, ByVal Target_size As Long, _
    ByRef Certificate As Byte, ByVal Certificate_size As Long) As Long

    Public Declare Function RSA_generate_keys Lib "rsa_dll.dll" _
    (ByRef Key As Byte, ByRef Certificate As Byte, _
    ByRef Key_size As Long, ByRef Certificate_size As Long) As Long

    Public Declare Function HMaxF_RSA_version Lib "rsa_dll.dll" (ByRef Target As Byte, ByVal Target_size As Long) As Long


    'delare public variable
    Public FileHandle As Integer

    Public SourceFile As String
    Public TargetFile As String
    Public KeyFile As String
    Public CertificateFile As String

    Public SourceBytes() As Byte
    Public TargetBytes() As Byte
    Public KeyBytes() As Byte
    Public CertificateBytes() As Byte

    Public SourceLength As Long
    Public TargetLength As Long
    Public KeyLength As Long
    Public CertificateLength As Long

    Public StartTime As Long
    Public FinishTime As Long

    Public Op_Mode As Long
    Public Result As Long ' return value

    nur alles was ich Fersuche endet in eine Absturtz der Autoit.exe

    hier mein Letzer Versuch:

    Spoiler anzeigen
    [autoit]

    Func RSA_encrypt(ByRef $Source, ByRef $Certificate)

    [/autoit] [autoit][/autoit] [autoit]

    local $Source_size = BinaryLen($Source) * 2
    If $Source_size < 255 Then $Source_size = 255
    local $Certificate_size = BinaryLen($Certificate)
    Local $Target, $Target_size = $Source_size * 4

    [/autoit] [autoit][/autoit] [autoit]

    $result = DllCall("rsa_dll.dll", "long", "RSA_encrypt", "byte", $Source, "long", $Source_size, "byte", $Target, "long", $Target_size, "byte", $Certificate, "long", $Certificate_size)

    [/autoit] [autoit][/autoit] [autoit]

    Return $Target

    [/autoit]

    ich habe das Thema DLLcall leider irgentwie nicht verstanden.

    ich vermute es hat irgentwas mit der Vareabelen Reservierung zu tun, Die wird nemlich im VB so geregelt:

    Spoiler anzeigen


    .
    .
    .
    Private Sub cmdEncrypt_Click()

    If SourceLength = 0 Then
    MsgBox "Source buffer is empty !", vbOKOnly, "Error"
    Exit Sub
    End If

    If CertificateLength = 0 Then
    MsgBox "Certificate buffer is empty !", vbOKOnly, "Error"
    Exit Sub
    End If

    'reserve enough space
    TargetLength = SourceLength * 2
    If (TargetLength < 256) Then
    TargetLength = 256 ' set minimum of one block size
    End If
    ReDim TargetBytes(0 To (TargetLength - 1))

    DoIt 1 ' encrypt

    If Result <> 0 Then
    Form1.lblMsg.Caption = "Success !" & vbCrLf & StrConv(TargetBytes, vbUnicode)

    'resize to the correct value
    ReDim Preserve TargetBytes(0 To (Result - 1))
    TargetLength = Result
    Else
    Form1.lblMsg.Caption = "Error, RSA encrypt return zero value"
    End If

    End Sub
    .
    .
    .
    Private Sub DoIt(Operation As Long)
    Op_Mode = Operation

    FormDoer.Show vbModal, Me ' show as modal
    End Sub
    .
    .
    .
    Private Sub cmdStart_Click()
    StartTime = Timer

    Me.cmdCancel.Enabled = False
    Me.cmdStart.Enabled = False

    Me.MousePointer = vbHourglass

    'select operation
    Select Case Op_Mode
    Case 1
    Me.lblMsg.Caption = "Encryption in progress ..."

    Result = RSA_encrypt(SourceBytes(0), SourceLength, TargetBytes(0), TargetLength, CertificateBytes(0), CertificateLength)
    Case 2
    Me.lblMsg.Caption = "Decryption in progress ..."

    Result = RSA_decrypt(SourceBytes(0), SourceLength, TargetBytes(0), TargetLength, KeyBytes(0), KeyLength)
    Case 3
    Me.lblMsg.Caption = "Signing in progress ..."

    Result = RSA_sign(SourceBytes(0), SourceLength, TargetBytes(0), TargetLength, KeyBytes(0), KeyLength)
    Case 4
    Me.lblMsg.Caption = "Verification in progress ..."

    Result = RSA_verify(SourceBytes(0), SourceLength, TargetBytes(0), TargetLength, CertificateBytes(0), CertificateLength)
    Case 5
    Me.lblMsg.Caption = "Generating Keys in progress ..."

    Result = RSA_generate_keys(KeyBytes(0), CertificateBytes(0), KeyLength, CertificateLength)
    End Select


    Me.MousePointer = vbDefault

    Me.cmdCancel.Caption = "&Finish"
    Me.cmdCancel.Enabled = True

    'check error
    If (Op_Mode = 5) Then
    If (Result <> 0) Then
    Me.lblMsg.Caption = "Generate keys error"
    Exit Sub
    End If
    Else
    If (Result = 0) Then
    Me.lblMsg.Caption = "Process fail !"
    Exit Sub
    End If
    End If

    FinishTime = Timer
    Me.lblMsg.Caption = "Finished and success, elapsed time = " & FinishTime - StartTime
    End Sub
    .
    .
    .

    Danke düe Nützliche Tipps