Delphi 的动态数组肯定是不能通用的,必须用“低级”的数据结构,可以直接用指针(不太好),或者用下面的办法
library TestDll;{$R-} // 临时关闭越界检查type TElement = ...; // 你的数组元素类型
type TArray = array[0..1] of TElement;function CopyArray(var Dst: TArray; const Src: TArray; Len: Integer): Integer; stdcall;
var
I: Integer;
begin
for I := 0 to Len do
begin
Dst[I] := Src[I]
end
end;
{$R+}exports  CopyArray;begin
end.
在 C/C++ 使用上面的 DLL(具体函数原型可能跟编译器有关):typedef ... TElement;
typedef TElement TArray[1];__declspec( dllimport ) int __stdcall CopyArray(TArray Dst, const TArray Src, int Len);

解决方案 »

  1.   

    Delphi 的动态数组肯定是不能通用的,必须用“低级”的数据结构,可以直接用指针(不太好),或者用下面的办法
    library TestDll;{$R-}   // 临时关闭越界检查type TElement = ...; // 你的数组元素类型
    type TArray = array[0..1] of TElement;function CopyArray(var Dst: TArray; const Src: TArray; Len: Integer): Integer; stdcall;
        var
            I: Integer;
    begin
        for I := 0 to Len do
        begin
            Dst[I] := Src[I]
        end;
        Result := Len;
    end;
    {$R+}exports  CopyArray;begin
    end.
    在 C/C++ 使用上面的 DLL:typedef ... TElement;
    typedef TElement TArray[1];__declspec( dllimport ) int __stdcall CopyArray(TArray Dst, const TArray Src, int Len);
    如果用显式加载,就是:typedef int (__stdcall * CopyArrayProc) (TArray Dst, const TArray Src, int Len);hModule = LoadLibrary("TestDll.dll");
    CopyArrayProc CopyArray = (CopyArrayProc) GetProcAddress(hModule, "CopyArray");
    int Result = CopyArray(Dst, Src, Len);
    ...
      

  2.   


    将dll的参数类型定义为var..(忘了怎么写)
    要传进去的数组也转成一样的类型!就可以了!!1