关于delphi调用vc编的dll(200分)

  • 主题发起人 主题发起人 DearLily
  • 开始时间 开始时间
D

DearLily

Unregistered / Unconfirmed
GUEST, unregistred user!
vc的函数是这样的:
extern "C" __declspec(dllexport) int ReConstructor(float* projection, float* presult)。传递的参数为指向一批数据的指针。

delphi中写了这样一个调用dll的单元:
unit recdll;
interface
function reconstruct(projection:pointer;presult:pointer):integer;
implementation
function ReConstructor(projection:pointer;presult:pointer):integer;stdcall;external 'recdll.dll' name 'ReConstructor';

function reconstruct(projection:pointer;presult:pointer):integer;
begin
result:=ReConstructor(projection,presult);
end;
end.

然后在主单元中直接调用该单元,用a:=reconstruct(@singlearr,@reconarr);singlearr,reconarr均为静态数组,运行时为何总是说地址出错?
 
stdcall;?cdecl?
 
用cdecl这个调用惯例试试

以前我也遇到过这个问题,用cdecl就解决了
 
楼上正解。
 
不行啊,cdecl和stdcall我都试过了,不行。
 
dll传递地址指针,delphi调用时是用究竟该以怎样的参数形式表示?大侠指教啊
 
如果从C的定义来说:
extern "C" __declspec(dllexport) int ReConstructor(float* projection, float* presult)
我会认为参数为单精度型,且要求回传值。
在delphi中,我会这样用:
function ReConstructor(projection:Psingle;presult:Psingle):integer;stdcall;external 'recdll.dll';

然后如下调用:
var
projection:single;presult:single;
begin
ReConstructor(@projection,@presult);
end;
 
多人接受答案了。
 
后退
顶部