【发布时间】:2018-03-31 16:19:36
【问题描述】:
我有以下 c++ 函数:
public:
__int32 __declspec(dllexport) __stdcall finalizeModelling(
__int32 model,
float * vertices,
__int32 * indices,
__int32 FVF
);
顶点和索引变量是数组。
在德尔福我有:
TFinalizeModelling =
function (AModel : NativeInt; var AVertices : array of TFloat; var AIndices : array of Integer; AFVF : NativeInt) : NativeInt; stdcall;
我尝试使用:
TFloat = Single;
PVerticesArray = ^TPVerticesArray;
TPVerticesArray = array of TFloat;
PIndicesArray = ^TPIndicesArray;
TPIndicesArray = array of Integer;
和
TFinalizeModelling =
function (AModel : NativeInt; var AVertices : PVerticesArray ; var AIndices : PIndicesArray ; AFVF : NativeInt) : NativeInt; stdcall;
我已经声明了两个变量:
vArray: PVerticesArray;
indices: PIndicesArray;
然后我进行如下函数调用:
EngineDll.FinalizeModelling(FModel, vArray, indices, 0);
但我遇到了访问冲突。
我的问题是: 在 C++ 中声明和 SetLength 与函数一起使用的动态数组的正确方法是什么?
函数会被多次调用,数组长度不同,内容也不同。
【问题讨论】:
-
每个参数都被错误地声明了。 C++ int 映射到 Delphi 中的 Integer,并且大概 __int32 扩展为 int。至于数组,将它们声明为指针并传递您的 delphi 数组的第一个元素的地址。最后,这看起来不像是静态方法。是实例方法吗?