Delphi调用vb的dll出错!!!
402 2004-10-05 07:14:57 vb调用该dll的演示代码如下:
Private Declare Function Dacsp_init Lib "dacsplib.dll" () As Long
Private Declare Function Dacsp_login Lib "dacsplib.dll" (ByVal Context As Long) As Integer
Private Declare Function Dacsp_final Lib "dacsplib.dll" (ByVal Context As Long) As Integer
Private Declare Function Dacsp_FileEnc Lib "dacsplib.dll" (ByVal Context As Long, ByVal infil As String, ByVal outfile As String, ByVal pubkey As String) As Integer
Private Declare Function Dacsp_FileDec Lib "dacsplib.dll" (ByVal Context As Long, ByVal infil As String, ByVal outfile As String, ByVal keyNo As Integer) As Integer
Private Declare Function Dacsp_StrEnc Lib "dacsplib.dll" (ByVal Context As Long, ByVal indata As String, ByVal indatalen As Integer, ByVal outdata As String, ByVal pubkey As String) As Integer
Private Declare Function Dacsp_StrDec Lib "dacsplib.dll" (ByVal Context As Long, ByVal indata As String, ByVal indatalen As Integer, ByVal outdata As String, ByVal keyNo As Integer) As Integer
Dim Context As Long
Dim ret As Integer
Dim pubkey As Byte
Private Sub Command1_Click()
Dim str As String
Dim str2 As String * 2048
Dim str3 As String * 2048
Dim pubkey As String
Context = Dacsp_init()
ret = Dacsp_login(Context)
If ret < 0 Then
MsgBox ("登陆失败!")
Exit Sub
End If
以上代码能成功运行无错!!
--------------------------------------------------------------------------------------
我改写成Delphi版的代码如下:
Interface
Function Dacsp_init():Longint;
Function Dacsp_login(Context:Longint):Integer;
Function Dacsp_final(Context:Longint):Integer;
Function Dacsp_FileEnc(Context:Longint;infil,outfile,pubkey:String):Integer;
Function Dacsp_FileDec(Context:Longint;infil,outfile:String;keyno:Integer):Integer;
Function Dacsp_StrEnc(Context:Longint;indata:String;indatalen:Integer;outdata,pubkey:String):Integer;
Function Dacsp_StrDec(Context:Longint;indata:String;indatalen:Integer;outdata:String;keyno:Integer):Integer;
implementation
Function Dacsp_init:Longint;external 'dacsplib.dll';
Function Dacsp_login(Context:Longint):Integer;external 'dacsplib.dll';
Function Dacsp_final(Context:Longint):Integer;external 'dacsplib.dll';
Function Dacsp_FileEnc(Context:Longint;infil,outfile,pubkey:String):Integer;external 'dacsplib.dll';
Function Dacsp_FileDec(Context:Longint;infil,outfile:String;keyno:Integer):Integer;external 'dacsplib.dll';
Function Dacsp_StrEnc(Context:Longint;indata:String;indatalen:Integer;outdata,pubkey:String):Integer;external 'dacsplib.dll';
Function Dacsp_StrDec(Context:Longint;indata:String;indatalen:Integer;outdata:String;keyno:Integer):Integer;external 'dacsplib.dll';
procedure TFrm_Main.Button2Click(Sender: TObject);
var
ret:Integer;
Context:Longint;
Context := Dacsp_init();
ret := Dacsp_login(Context);
if ret < 0 Then
Messagedlg('操作失败!',mtError,[mbok],0);
程序一执行就报错,翻译后大概内容为:"内存访问错误,在模块dacsplib中"
请问为什么同样一个dll在vb中能被成功调用,而在delphi中却会报错呢?是不是变量类型的问题?
还是什么传值和传地址之间的转换??
求高手指点~~~