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);
...
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);