Deiphi的代码怎么转换成C或者C ++
我手里有一段用Delphi写的源码,好像是用来生成一个DLL文件的。
我想把它里面的函数内容转化为C语言或者C++编写的,不知道哪位大佬能帮我看一看,不胜感激~
library PSIdll;
const
Pkg8400Len = 4120;
Pkg8400ChNum = 1024;
type
Byte69 = array[0..68] of Byte;
Single16 = array[0..15] of Single;
Byte8400 = array[0..Pkg8400Len-1] of Byte;
Single8400 = array[0..Pkg8400ChNum-1] of Single;
DataPkgType =packed record
st: Byte;
SN: integer;
ChData: Single16;
end;
//以下是PSI扫描器数据包解码函数
//单个4字节格式7->单精度浮点数
Function ToSingle(s1,s2,s3,s4:byte): Single; stdcall;
Var spt:^single;
sary:array[0..3] of byte;
begin
sary[0]:=s4;
sary[1]:=s3;
sary[2]:=s2;
sary[3]:=s1;
spt:=@sary;
ToSingle:=spt^;
end;
//单个4字节格式8->单精度浮点数
Function ToSingle8(s1,s2,s3,s4:byte): Single; stdcall;
Var spt:^single;
sary:array[0..3] of byte;
begin
sary[0]:=s1;
sary[1]:=s2;
sary[2]:=s3;
sary[3]:=s4;
spt:=@sary;
ToSingle8:=spt^;
end;
//单个69字节数据包->16个单精度浮点数
Function Decode9000(var rBuff: Byte69; psiFormat:integer;var SN:Longint; var ChData:Single16): integer;stdcall;
var
myData: ^DataPkgType;
byteAry: Byte69;
i: integer;
Begin
if (rBuff[0]>3) or (rBuff[0]<1) then
begin
Decode9000:=1;
for i:=0 to 15 do
begin
ChData[i] := 0.0;
end;
SN:= 0;
exit;
end;
case psiFormat of
7:
begin
byteAry[0]:= rBuff[0];
for i:=0 to 16 do
begin //交换字节顺序,格式7->格式8
byteAry[i*4+1]:= rBuff[i*4+4];
byteAry[i*4+2]:= rBuff[i*4+3];
byteAry[i*4+3]:= rBuff[i*4+2];
byteAry[i*4+4]:= rBuff[i*4+1];
end;
myData:=@byteAry;
end;
8:
myData:=@rBuff;
else
Decode9000:=1;
exit;
end;
Decode9000:=0;
ChData :=myData^.ChData;
SN:= myData^.SN;
End;
//==============================
//Decode DTCInitium 和8400数据包
Function DecodeDTC8400(var rBuff: Byte8400; var SN:Longint; var ChData:Single8400): integer;stdcall;
Var spt:^single;
sary:array[0..3] of byte;
DataNum: integer;
i: integer;
Begin
DecodeDTC8400:=1;
//报头解析:应答包
case rBuff[1] of
4,8,9,128: //简单应答包
begin
DecodeDTC8400:=1;
for i:=0 to 63 do
begin
ChData[i] := 0.0;
end;
SN:= 0;
end;
19: //数据流包
if rBuff[0] = 250 then
begin
DecodeDTC8400:=0;
SN := rBuff[4];
SN := SN *256 + rBuff[5];
DataNum := rBuff[6];
DataNum := DataNum *256 + rBuff[7]; //得到数据点数
//字节倒序,8400总是使用格式7,大头格式
for i:=0 to DataNum-1 do //DataNum-1
begin //交换字节顺序,格式7->格式8
sary[0]:= rBuff[i*4+24+3];
sary[01]:= rBuff[i*4+24+2];
sary[02]:= rBuff[i*4+24+1];
sary[03]:= rBuff[i*4+24];
spt:=@sary;
ChData[i] := spt^;
end;
end;
else //其它不解码
begin
DecodeDTC8400:=1;
for i:=0 to 63 do
begin
ChData[i] := 0.0;
end;
SN:= 0;
end;
end;
End;
exports
ToSingle ,
ToSingle name 'Tosingle',
ToSingle name 'ToSingle7',
ToSingle8,
DecodeDTC8400,
Decode9000;
begin
end.