Delphi DLL使用函数设计来返回一组整数记录值

Delphi DLL使用函数设计来返回一组整数记录值,delphi,Delphi,目前需要使用Delphi编写一个DLL,以便主程序调用文件中可移动磁盘中的指定位置 主程序是用VC++设计的,所以用struct方式调用DLL的数据为round 当主程序调用my DLL、传入的A组记录和其他函数以返回B组记录时遇到的当前问题 但使用Delphi编写的DLL,可以接收A组记录,但返回B组,但总是出错 下面是DLL函数的代码,想问一下是否有人遇到这样的问题可以帮忙点一下,提一下就充耳不闻了 谢谢 enter code here library usbdll; uses Windo

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

主程序是用VC++设计的,所以用struct方式调用DLL的数据为round

当主程序调用my 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;
//实际上,我需要将主程序的数据计入我的组A记录中,以便处理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;
下面是一个测试,使用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;   
}

对于大于机器字大小的返回值,没有标准ABI。Delphi使用的ABI与我遇到的任何其他编译器都不同,因此您将无法通过这种方式返回大型记录

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


它看起来也像你的C++函数使用了CCDL而不是STDCALL.< /P>,记录如何返回确实有很大的不同。Borland/Embarcadero编译器返回任何大于32位的输出参数,即使记录被正式声明为函数结果。MS在两个寄存器EDX:EAX中返回高达64位的数据,这两个寄存器的大小都比Delphi大。其他编译器也是这样做的。区别在于可能作为寄存器返回的记录的大小。

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;   
}