Home > Back-end >  Delphi written DLL dynamic library. A, A call dynamic library B dynamic libraries
Delphi written DLL dynamic library. A, A call dynamic library B dynamic libraries

Time:09-16

With docking of the project Delphi to write a. d. LL, in a. d. LL call another B.D LL read and write CARDS, separate test call B.D LL no problem, but the encapsulation a. d. LL, again through the external program calls when a. d. LL quote memory errors,

A. d. LL within the functions as follows:
The function ReadCard (iPortID: Integer; IBeep: Integer; Var dm: Integer; Var typeid: Integer; Var userid: PChar; Var watertabinfo: PChar) : Integer; Stdcall;
Type
Tic_init=function (icdev: Integer; Time: Integer) : Integer; Stdcall;//initialize serial port
Tdv_beep=function (icdev: Integer; Time: Integer) : Integer; Stdcall;//buzzer
Tqt_T5557_read=function (icdev: Integer; Addr: Integer; Var Revbuffer: an array of byte) : integer; Stdcall;//read card
Tic_exit=function (icdev: Integer) : Integer; Stdcall;//close a serial port
Var
Rstr: string;
Tdll: Thandle;//load the DLL
Topencom: Tic_init;
Tbeep: Tdv_beep;
Tread: Tqt_T5557_read;
Tclose: Tic_exit;
FPointer: TFarProc;
ReBuff: array [0.. 6, 0.. 3] of byte;
FHZ, fh, refh, I: Integer;
Ss: array [28] 1.. of string;//card 28 bytes
The begin
Tdll:=LoadLibrary (' qtid. DLL);//load the DLL file
If Tdll & gt; 0 then
The begin
Try
FPointer:=GetProcAddress call (Tdll, PChar (' ic_init '));//find the initialize serial port function position
If FPointer<> Nil then
The begin
Topencom:=Tic_init (FPointer);
FHZ:=Topencom (iPortID - 1960-0).//initialize serial port function called
If FHZ & gt; 0 then
The begin
FPointer:=GetProcAddress call (Tdll, PChar (' qt_T5557_read '));//find read card function position
If FPointer<> Nil then
The begin
//SetLength (reBuff, 4);
Tread:=Tqt_T5557_read (FPointer);
Rstr:=';
For I:=1 to 7 do
The begin
Fh:=Tread (FHZ, I, reBuff [I - 1));
If fh=0 then Rstr:=Rstr + PChar (BytesToHex (reBuff] [I - 1));
//SetLength (reBuff, 0);
end;
If length (Rstr) & gt; 50 then
The begin
For I:=1 to 28 do ss: [I]=copy (Rstr, I * 2-1, 2);
//Rstr:=';
Dm:=HexToDec (ss [1]);//plant code
If the trim (ss) [2]='11' then
The begin
Typeid:=1;//card types for user card
Userid:=PChar (IntToStr (HexToDec (ss + ss [3] [4])));//the user number
End
The else
The begin
If the Trim (ss) [2]='22' then
The begin
Userid:='0';
Case HexToDec (Trim (ss) [5]) of
4: the typeid:=9;//accumulate card
5: the typeid:=6;//parameter Settings card
6: the typeid:=11;//test card
8: the typeid:=7;//reset card
9: the typeid:=8;//
25: the typeid:=13;//repair card
26: the typeid:=12;//test card
The else
Typeid:=9999;
end;
End
The else
The begin
Typeid:=88;
Userid:='77';
end;
end;
Watertabinfo:=PChar (Rstr);
End
The else
The begin
Watertabinfo:=PChar (Rstr);
Dm:=44;
Typeid:=66;
Userid:='55';
end;

Refh:=1;

If iBeep=1 then
The begin
FPointer:=GetProcAddress call (Tdll, PChar (' dv_beep '));//to find the location of the buzzer function
If FPointer<> Nil then
The begin
Tbeep:=Tdv_beep (FPointer);
Fh:=Tbeep (FHZ, 10);
end;
end;
End
The else refh:=3;
End
The else refh:=2;

FPointer:=GetProcAddress call (Tdll, PChar (' ic_exit '));//find closed serial position
If FPointer<> Nil then
The begin
Tclose:=Tic_exit (FPointer);
Tclose (FHZ);
end;

End
The else refh:=3;
The Finally
FreeLibrary (Tdll);//release the DLL, otherwise will always takes up memory, until out of Windows or turn it off;
The End;
End
The else refh:=4;
Result:=refh;
end;

CodePudding user response:

In the turn to the great god , his first cap,

CodePudding user response:

The function ReadCard (iPortID: Integer; IBeep: Integer; Var dm: Integer; Var typeid: Integer; Var userid: PChar; Var watertabinfo: PChar) : Integer; Cdecl;//change the stdcall to cdecl try

CodePudding user response:

Estimation is B.D LL interface definitions is not correct, is written in what tool, C file to see his head

CodePudding user response:

Can you be debugged a. d. LL code, see which line the error?
So the code is too laborious,
  • Related