delphi 编写的dll函数
Function GetStationData(DoWith:Integer;FSavePath:Pchar;Var Buffer:Integer):Integer; stdcall;
var i:Integer;
    TmpPath:String;
    TmpList:TStrings;
begin
  //0:直接输出,1:输出保存为文件,2:xml,3:数据库;4:自定义数据结构
  Result:=Integer(ProcessDataOk);
  SetLength(TStringDynArray(Buffer),High(DataBuffer)+1);
  if Result=1 then
try
  case DoWith of
  0:for i:=Low(DataBuffer) to High(DataBuffer) do
    begin
      TStringDynArray(Buffer)[i]:=DataBuffer[i];
    end;
  1:;
    else
      Result:=-2;
  2:;
  4:;
  end;
Except
  Result:=-1;
end;
end;vb申明
Private Declare Function GetStationData Lib "dll文件名" (ByVal DoWith As Integer, ByVal FSavePath As String, ByVal Buffer As Long) As Long
这样申明对不对,还有改如何提出函数中的字符串数组,delphi下没问题

解决方案 »

  1.   

    ;Var Buffer:Integer  这个应该是地址传递所以VB声明应该改一下
    Private Declare Function GetStationData Lib "dll文件名" (ByVal DoWith As Integer, ByVal FSavePath As String, byref Buffer As Long) As Long 
      

  2.   

    我要传出的是字符串数组,但就是传不出来
    Dim strA() As String, point As Long
        ReDim strA(1)
        strA(0) = "a"
        point = VarPtr(strA(0))
        MsgBox point
        GetStationData 0, "", point
       MsgBox point
    point这个地址指针已经变了,如何取得stra这个数组的值?
      

  3.   

    试一下这样可以吧Private Declare Function GetStationData Lib "dll文件名" (ByVal DoWith As Integer, ByVal FSavePath As String, byref Buffer() As string) As Long GetStationData 0, "", strA(0)
      

  4.   

    Private Declare Function GetStationData Lib "dll文件名" (ByVal DoWith As Long, ByVal FSavePath As String, ByVal Buffer As String) As Long     Dim sBuffer As String
        '初始化缓冲区
        sBuffer=Space$(255)    GetStationData 0, "", sBuffer
      

  5.   

    to simon__sun 这样不行,我试过了to 楼上几位,上面有我的delphi的dll函数,这样写不匹配的吧,单独传字符串是没问题,但我要传出的是字符串数组,或者可以考虑delphi修改函数
      

  6.   

    你的 delphi 函数中,第二个参数没有使用?
      

  7.   

    如果可以,请将你的Dll文件及调用的VB代码公布。天狼工作室 http://www.j2soft.cn/
      

  8.   

    如果可以,请将你的Dll文件及调用的VB代码公布。天狼工作室 http://www.j2soft.cn/
      

  9.   

    dll函数源码
    Function GetStationData(DoWith:Integer;FSavePath:Pchar;Var Buffer:Integer):Integer; stdcall;
    Function GetStationData(DoWith:Integer;FSavePath:Pchar;Var Buffer:Integer):Integer; stdcall;
    var i:Integer;
        TmpPath:String;
        TmpList:TStrings;
    begin
      //0:直接输出,1:输出保存为文件,2:xml,3:数据库;4:自定义数据结构
      Result:=Integer(ProcessDataOk);
      if Result=1 then
      begin
        SetLength(TPCharDynArray(Buffer),High(DataBuffer)+1);
        try
        case DoWith of
        0:for i:=Low(DataBuffer) to High(DataBuffer) do
          begin
            TPCharDynArray(Buffer)[i]:=PChar(DataBuffer[i]);
          end;
        1:if High(DataBuffer)=High(PathBuffer) then
          begin
            TmpList:=TStringList.Create;
            for i:=Low(DataBuffer) to High(DataBuffer) do
            begin
              if FSavePath='' then
                TmpPath:=DllPath+PathBuffer[i]
              else
                if FSavePath[Length(FSavePath)]='\' then
                  TmpPath:=FSavePath+PathBuffer[i]
                else
                  TmpPath:=FSavePath+'\'+PathBuffer[i];
              if Not DirectoryExists(ExtractFilePath(TmpPath)) then
                ForceDirectories(ExtractFilePath(TmpPath));
              if DirectoryExists(ExtractFilePath(TmpPath)) then
              begin
                TmpList.Text:=DataBuffer[i];
                TmpList.SaveToFile(TmpPath);
              end;
            end;
            TmpList.Free;
          end
          else
            Result:=-2;
        2:;
        4:;
        end;
        Except
          Result:=-1;
        end;
      end;
    end;
    vb声明
    Private Declare Function GetStationData Lib "User_Check_Data.dll" (ByVal DoWith As Integer, ByVal FSavePath As String, ByRef Buffer As Long) As Long
    vb调用
    Private Sub Command2_Click()
    Dim strA() As String, PoInt As Long
        ReDim strA(1)
        strA(0) = "1"
        PoInt = VarPtr(strA(0))
        MsgBox PoInt
        GetStationData 0, "", PoInt
        CopyMemory VarPtr(strA(0)), ByVal PoInt, 100
       MsgBox strA(0)
    End Sub
      

  10.   

    没有delphi环境,你可以把DLL传上来,帮你调一下看
      

  11.   

    library TestDll;uses
      SysUtils,
      Classes;
     type
       TPCharDynArray =Array of Pchar;
     type
       MyData=record
         Name:Pchar;
         ID:Integer;
       end;
       PMyData=^MyData;
    {$R *.res}
    Function GetStationData(DoWith:Integer;Var Buffer:Integer):Integer; stdcall;
    var i:Integer;
        DataBuffer:TPcharDynArray;
    begin    SetLength(DataBuffer,2);
        DataBuffer[0]:='数据1';
        DataBuffer[1]:='2';
        Result:=High(DataBuffer)+1;
        SetLength(TPCharDynArray(Buffer),High(DataBuffer)+1);
        for i:=Low(DataBuffer) to High(DataBuffer) do
          begin
            TPCharDynArray(Buffer)[i]:=PChar(DataBuffer[i]);
          end;
    end;Function GetMyData(var Point:Integer):Integer;stdcall;
    var aa:MyData;
    begin
       aa.Name:='Test';
       aa.ID:=1;
       Point:=Integer(@aa);
       Result:=1;
    end;
    Exports
      GetStationData name 'GetStationData',
      GetMyData name 'GetMyData';
    begin
    end.
    这是delphi源码,dll文件怎么上传啊
      

  12.   

    http://download.csdn.net/source/1412823
    dll下载地址,请帮忙提供vb代码
      

  13.   

    返回值就是表示成功与否,关系不大,主要的我的dll从网上获取数据,所有的验证都在这个dll里面,然后应用的时候就从dll里面取回数据,里面有字符串数组,用字符串传递没问题,还有一种自定义的数据结构,该结构体只有常规变量,integer,pchar等