5,391
社区成员
发帖
与我相关
我的任务
分享
//lib.dpr
library lib;
{$R *.res}
type
TArray = array[0..1] of Integer;
function Foo: TArray; stdcall;
begin
Result[0]:=1;
Result[1]:=2;
end;
exports
Foo;
begin
end.
//app.dpr
program app;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
TArray = packed record
Data: array[0..1] of Integer;
end;
function Foo: TArray; stdcall; external 'lib.dll';
var
_Array: TArray;
begin
_Array:=Foo;
WriteLn(_Array.Data[0], ' ', _Array.Data[1]);
ReadLn;
end.
//test.cpp
#include <iostream.h>
#include <windows.h>
#pragma pack(push, 1)
struct TArray {
int Data[2];
TArray(const TArray& Array) {
memcpy(Data, Array.Data, sizeof(Data));
}
};
#pragma pack(pop)
typedef TArray (__stdcall *TFoo)();
int main(int argc, char* argv[])
{
HMODULE hModule = LoadLibrary("lib.dll");
TFoo Foo = (TFoo)GetProcAddress(hModule, "Foo");
TArray Array = Foo();
cout << Array.Data[0] << ends << Array.Data[1] << endl;
cin.get();
return 0;
}