VB调用DELPHI写的dll出现很奇怪的问题,请高人相助啊 !!!我有个delphi座的 Dll,里面有个窗体,源码客户没有给。
在delphi里调用为
//声明--------------------------------------------------------
function RunMyDllcurv(dbuf:array of single; dlen:integer):integer;stdcall;external 'Pdllcurv' index 1;
//调用--------------------------------------------------------
procedure TForm_demo.Button4Click(Sender: TObject);//调用正常
var
curvlen:integer;
curvdata:array[0..99999] of single;
begin
   curvlen:=100000
   RunMyDllcurv(curvdata, curvlen) ;
end;//************************************************************在VB里调用为
//声明--------------------------------------------------------
Private Declare Function RunMyDllcurv Lib "Pdllcurv.dll" (dbuf As Single, ByVal dleen As Long) As Long
//调用--------------------------------------------------------
Private Sub Command1_Click()//调用不正常
Dim buff(99999) As Single  Call RunMyDllcurv(buff(1), 100000)End Sub具体表现为:
1。
当 Pdllcurv.dll 在 vb 系统目录里时, 调式时,按下 Command1 按钮
后, dil 里的窗体可以正常显示,但关闭该窗体后,会出现一个“dll 调用约定错误”的错误
2.
当 生成exe文件后 把 Pdllcurv.dll 放在exe文件所在目录里,按下 Command1 按钮
后,dil 里的窗体没有显示,却出现“读取内搓错误”消息条。

解决方案 »

  1.   

    从你的代码来看,我个人觉得是函数的参数类型不对,在delphi中是dbuf:array of single,是一个动态的数组,,
    而VB中,dbuf As Single,而是single又是Dim buff(99999) As Single偶对VB不熟,不太确定
      

  2.   

    用delphi写标准DLL 
    1.不可以在DLL里面分配字符串空间给调用函数,字符串空间必须在外部分配。
    2.不可以将字符串作为返回值,你看见那个WIN API有字符串返回值了。
    3.一般都要传递给函数PCHAR的空间长度,避免字符串空间不足。常见写法fun xxx(ps: pchar; ilen: integer): integer
    var
      s: string;
    begin
      s := 'abc';
      result :=  length(s);
      if ilen = 0 then 
        exit;
      if result > ilen then
        result :=  ilen ;
      CopyMemory(ps, PChar(s), result);
    end;var
      ss: string;
      i: integer;
    begin
      i := xxx(PChar(ss), 0);
      SetLength(ss, i);
      i := xxx(pChar(ss), i);
    end;
      

  3.   

    to  comerliang(天地良心)(性欲被自己倒分倒没了,以后再也不敢倒分了) ( 我还是不明白 
      

  4.   

    RunMyDllcurv(buff(1), 100000)vb里buff应该是从0开始的吧
      

  5.   

    对VB不熟,但觉得RunMyDllcurv(buff(1), 100000)有问题,delphi的RunMyDllcurv参数应该为数组
    buff的地址,而你的VB给的是buff第一个成员的内容,记得VB的参数有传值和传地址两种,你应该是将buff的首地址传入,而不能用buff(1)
      

  6.   

    RunMyDllcurv(buff(0), 100000),问题依旧
      

  7.   

    //delphi声明--------------------------------------------------------
    function RunMyDllcurv(dbuf:array of single; dlen:integer):integer;stdcall;external 'Pdllcurv' index 1;//vb声明--------------------------------------------------------
    Private Declare Function RunMyDllcurv Lib "Pdllcurv.dll" (dbuf As Single, ByVal dleen As Long) As Longvb声明中的函数参数明显和delphi不同嘛。
      

  8.   

    to chuchenggang() 
    应该如何声明 3Q!
      

  9.   

    VB中的数组只能按地址传递   
      2。数组作为形参时,应为   “数组名()”     注意是空括号   
      3。数组作为实参时,应为     “数组名”           注意不要括号   
    不知道这样行不行:
    在VB里调用为
    //声明--------------------------------------------------------
    Private Declare Function RunMyDllcurv Lib "Pdllcurv.dll" (dbuf() As Single, ByVal dleen As Long) As Long
    //调用--------------------------------------------------------
    Private Sub Command1_Click()//调用不正常
    Dim buff(99999) As Single  Call RunMyDllcurv(buff, 100000)End Sub你试试!
      

  10.   

    to jeffy(小飞) 这样写。调试是vb自动退出.....
    //声明--------------------------------------------------------
    Private Declare Function RunMyDllcurv Lib "Pdllcurv.dll" (dbuf() As Single, ByVal dleen As Long) As Long
    //调用--------------------------------------------------------
    Private Sub Command1_Click()
    Dim buff(99999) As Single  Call RunMyDllcurv(buff, 100000)End Sub
      

  11.   

    Call RunMyDllcurv(byval buff, 100000)
    试验一下
      

  12.   

    to  maxin5043() 我写如下 会有编译错误“数组参数必须为bybef”如何处理???Private Declare Function RunMyDllcurv Lib "Pdllcurv.dll" (ByRef dbuf() As Single, ByVal dleen As Long) As Long
    Private Sub Command1_Click()
    Dim buff(0) As Single  On Error Resume Next
      
      
      Call RunMyDllcurv(ByVal buff, 1)End Sub