我现在使用delphi 做出dll了,使用delphi 能够正确调用,但是使用vb怎么样调用呢
delphi中的dll 的函数
function DecodeBase64(Source:ShortString):ShortString; stdcall;
function EncodeBase64(Source:ShortString):ShortString;stdcall;
在delphi 的调用方法
function DecodeBase64(Source:ShortString):ShortString; stdcall;external 'Project2.dll';
function EncodeBase64(Source:ShortString):ShortString;stdcall;
external 'Project2.dll';怎样将 这段delphi 更改成vb调用的呢

解决方案 »

  1.   

    对Delphi不懂,你可以试试下面的声明:
    function DecodeBase64(Source:ShortString):ShortString; stdcall;
    --------------------------
    Declare Function DecodeBase64 Lib "'Project2.dll'" Alias "DecodeBase64 " (Byval Source As String) As Stringfunction EncodeBase64(Source:ShortString):ShortString;stdcall;
    --------------------------
    Declare Function EncodeBase64Lib "'Project2.dll'" Alias "EncodeBase64" (Byval Source As String) As String
      

  2.   

    谢谢  benyfeifei(狒狒)
      我就是这样调用的,就是使用的时候出个错误提示.  然后就关闭了.这个错误.我明天给你贴出来.
      

  3.   

    错误提示是:
    "0x0000000"指令引用的"0x0000000"内存,该内存不能为"read".
    要终止程序,请单击"确定".
    要调试程序,请单击"取消".
      

  4.   

    网上查了一下,知道ShortString是什么东东了。strShort = record
        wLength: WORD;
        szBuf: array of Char;
    end;
    --------------------Type ShortString
      wLength As Integer
      szBuf As String*255  '或者szBuf(0 to 254) As Byte  ShortString 只支持255 个字符
    End TypeDeclare Function DecodeBase64 Lib "'Project2.dll'" Alias "DecodeBase64 " (Byval Source As ShortString) As ShortString
      

  5.   

    Type ShortString
      wLength As Integer
      szBuf As String * 255 '或者szBuf(0 to 254) As Byte  ShortString 只支持255 个字符
    End TypeDeclare Function EncodeBase64 Lib "Project2.dll" Alias "DecodeBase64 " (ByVal Source As ShortString) As ShortString
    Declare Function DecodeBase64 Lib "Project2.dll" Alias "DecodeBase64 " (ByVal Source As ShortString) As ShortString
    Private Sub Command1_Click()
      Text2.Text = DecodeBase64(Text2.Text)
    End SubPrivate Sub Command2_Click()
      Text3.Text = DecodeBase64(Text2.Text)
    End Sub
    提示:compile error:
     user-defined try may not be passed byval
      

  6.   

    把你的DLL给我吧,我帮你测一下。
    [email protected]
      

  7.   

    或者你这样试试:
    Private Type ShortString
      wLength As Integer
      szBuf() As Byte
    End TypePrivate Declare Function EncodeBase64 Lib "Project2.dll" Alias "DecodeBase64 " (Source As ShortString) As ShortString
    Private Declare Function DecodeBase64 Lib "Project2.dll" Alias "DecodeBase64 " (Source As ShortString) As ShortStringPrivate Sub Command1_Click()    Dim udtCode As ShortString
        udtCode.szBuf = StrConv(Text2.Text, vbFromUnicode)
        udtCode.wLength = UBound(udtCode.szBuf) + 1
        Text2.Text=StrConv(EncodeBase64(udtCode).szBuf,vbUnicode)
    End Sub
    Private Sub Command1_Click()    Dim udtCode As ShortString
        udtCode.szBuf = StrConv(Text2.Text, vbFromUnicode)
        udtCode.wLength = UBound(udtCode.szBuf) + 1
        Text3.Text=StrConv(DecodeBase64(udtCode).szBuf,vbUnicode)
    End Sub
      

  8.   

    http://community.csdn.net/Expert/TopicView.asp?id=4777062
    和http://community.csdn.net/Expert/TopicView.asp?id=4777361
    也都是我问的帖子
    您已经成功将信发送到: [email protected]信我已经发了
      

  9.   

    改好了,已经给你回复了。函数的数据类型定义根本不是ShortString,而是PChar类型,而且两个函数的参数传递方式也不一致,一下没注意调试的时候老出现异常错误。