我想使用在DLL中声明的函数,该函数将指针作为输入/输出参数来填充非指针参数的记录。
来自DLL的功能:
function WFS_GetMlaData( handle: WFS_HDL;
mla_idx: Integer;
mla_name: TCharWFSBufferArray;
var cam_pitch_um: PDouble;
var lenslet_pitch_um: PDouble;
var center_spot_offset_x: PDouble;
var center_spot_offset_y: PDouble;
var lenslet_f_um: PDouble;
var grd_corr_0: PDouble;
var grd_corr_45: PDouble): Integer stdcall;
记录:
MlaInfo = record
i : Integer;
idx : Integer;
name : TCharWFSBufferArray;
camPitchUm : double;
lensletPitchUm : double;
spotOffsetx : double;
spotOffsety : double;
lensletFocalLengthUm : double;
grdCorr0 : double;
grdCorr45 : double;
end;
函数调用:
if err = WFS_GetMlaData(handle,
MlaList[i].idx,
MlaList[i].name,
PDouble(MlaList[i].camPitchUm),
PDouble(MlaList[i].lensletPitchUm),
PDouble(MlaList[i].spotOffsetx),
PDouble(MlaList[i].spotOffsety),
PDouble(MlaList[i].lensletFocalLengthUm),
PDouble(MlaList[i].grdCorr0),
PDouble(MlaList[i].grdCorr45) ) then MyWFS_HandleErrors(handle, err);
在上面的情况下,使用类似的函数将指针传递给整数,它可以工作,在上述情况下,我有无效的类型转换错误。
答案在“参数(Delphi)-值和变量参数”文档中。我的粗体强调:
如果例程的声明指定了var参数,则在调用该例程时,必须传递一个可分配的表达式-即,变量,类型常量(处于{$ J +}状态),解引用的指针,字段或索引变量。
关于您的情况,我的建议是声明一个新类型:
PMlaInfo = ^TMlaInfo;
并更改函数的签名:
function WFS_GetMlaData(AHandle: WFS_HDL; const AMlaInfo: PMlaInfo): Integer stdcall;
但是有一种“ hack ”(取消引用的指针):
PDouble((@MlaList[i].camPitchUm)^)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句