我手里有一段用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;
//==============================
//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.
uj5u.com熱心網友回復:
如果方法可行,另有報酬,感謝感謝
uj5u.com熱心網友回復:
編譯一下直接用就可以了
非要翻譯,也很容易
// PSIdll.cpp
#include <windows.h>
const int Pkg8400Len = 4120;
const int Pkg8400ChNum = 1024;
眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......
值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......