Delphi DLL-use函数旨在返回一组值Integer Record

时间:2014-01-06 09:51:31

标签: delphi

目前需要使用Delphi编写一个DLL,以便主程序调用可移动磁盘中指定位置的文件,

主程序设计为VC ++,所以用Strut方式调用DLL的数据为圆形!!

主程序调用我的DLL,传入的组A记录和其他函数时遇到的当前问题已经处理,返回组B记录,

但是使用Delphi编写的DLL,可以接收A组记录,但是返回B组,但总是出错!

以下是DLL函数的代码,想问一下是否有人遇到过这样的问题可以帮助点提一下充耳不闻

谢谢! !

enter code here
library usbdll;

uses
Windows,
SysUtils,
Classes;

{$R *.res}

Type
p_fin=^TSfin;

TSfin = record //A group of Record is the main program calls incoming Record Type
ST_act:Integer;
pathlen:Integer;//Pass true path length, so that I can get to the far left pathlen, then to remove the rear garbled
Id_hand:Integer;
Id_tail:Integer;

path: PWideChar://The reason why the file path Pwidechar do use guidelines because another branch dll is passed to the main program main program <file path + unicode>, is behind the path and dragging a bunch of gibberish characters

Type
p_out=^TRfout;//B Record is set to return to the main program of the Record Type


TRfout= Record
ST_act:Integer;
ST_move:Integer;
Revis:Integer;
Crchk:Integer;
end;

//以下是我的评论。

//使用测试方式有两种,直接返回B组记录,不接收A组记录,A组不接收记录,当主程序一次调用时,立即返回相关数据,结果很正常。

(*

function RFoutEt(test:p_out):Boolean;stdcall;   //ok   Function writing mode

begin

test^.ST_act:=14;
test^.ST_move:=10;
test^.Revis:=12;
test^.Crchk:=8;end;exports RFoutEt;
procedure RFoutE(out Result:TRfout);cdecl;    //ok   Procedure writing mode

begin

Result.ST_act:=14;
Result.ST_move:=10;
Result.Revis:=12;
Result.Crchk:=8;end;exports RFoutEt;
*)

//实际上,我需要将主程序充电到我的组A Record datain命令来处理post-op,得到真正想要移动文件以指定真实路径,并最终返回B组记录。

 function RFoutE(ap_sendin:p_fin;num:Integer):TRfout;stdcall;   //error

 var 
 str_tmp,str_tmp2,temi_diry:string;
 i,copyNum:Integer;

 arr: array[0..100] of Char;

 begin

 //Program by adding the following {} after paragraph, Result is not an empty value is displayed to access illegal address,causing abnormal program termination.

{

StrCopy(arr,Pchar(ap_sendin^.path));  
repeat
str_tmp:=temi_diry;//Use the file path string char array A group referred to in the PWidechar removed 

str_tmp2:=arr[i];
Inc(i);
until i>=ap_sendin.pathlen;

copyNum:=Prs_Filecopy(temi_diry;ap_sendin^.path);//A group of Record with associated data to complete the move of the specified file

}

Result.ST_act:=4;//The following four lines of words alone are able to return data
Result.ST_move:=0;
Result.Revis:=2;
Result.Crchk:=copyNum;end;

PS。以下是使用VC ++尝试多个功能正常需求的测试

struct Sfin{

int ST_act;       
int pathlen;
int Id_hand;
int Id_tail;
wchar_t *path;
};

struct Rfout{

int ST_act;
int ST_move;
int Revis;
int Crchk;
};

Rfout RFoutE(struct Sfin *a, int num)
{

int ret = 1;
Rfout OutStruct;


copyNum = Prs_Filecopy(temi_diry, inAnow, Anow->path);
ret=1;
if(ret==1){
    OutStruct.ST_act =14;
    OutStruct.ST_move =10;
    OutStruct.Revis = 12;
    OutStruct.Crchk = 8;
    Anow = freeA(Anow);

}   
return OutStruct;   
}

1 个答案:

答案 0 :(得分:1)

对于大于机器字大小的返回值,没有标准ABI。 Delphi使用与我遇到的任何其他编译器不同的ABI,因此你没有运气返回大型记录。

您需要将记录作为out参数而不是函数返回值返回。一旦你做出改变,一切都会很好。

看起来你的C ++函数也使用cdecl而不是stdcall。