Home > database >  PB call external DLL, the DLL is written by Delphi, please related experience friends advise.
PB call external DLL, the DLL is written by Delphi, please related experience friends advise.

Time:09-19

There is such a DLL: M1card. DLL
DLL and object in CPIC (prototype is M1card. CPIC)
Procedure InitCard (const Key Code: WideString; Sector, CtCode: Integer); Safecall;

The function ReadCardInfo (var DataFlag: Integer; Var CardData: TCardData) : Integer; Safecall;
DataFlag: return error on behalf of
CardData: charge sector data

TCardData=https://bbs.csdn.net/topics/record
Balance: Double;//card amount (4 bytes)
BtDate: WideString;//subsidies logo (written into the card, date of subsidies, prevent repeated to receive 3 bytes) used to read
The Timer: WideString;//timing (5 bytes) used to read
LimitMoney1: WideString;//limit (3 bytes) do not fill out or fill in "000000"
LimitTimes1: Integer;//indefinitely (1 byte)
OrderTime: WideString;//reservation time (2 bytes) used to read
OrderRecord: WideString;//reservation record (4 bytes) used to read
UseTimes: Integer;//use (3 bytes) decimal
WriteFlag: Integer;//write card logo (1 byte) used to read
end;

I also declare a person structure is s_carddata in PB, the calling code is as follows:
Long code, RTN, ctcode
The string key, code
S_carddata carddata
OleObject obj

Obj=Create OleObject
Obj. ConnectToNewObject (" M1card. CPIC ")
Obj. InitCard (Key Code, 1, ctcode)//this call normal
RTN=obj. ReadCardInfo (code, carddata)//the wrong line call, error code 35

.
I also tried not use ole, but directly in the local external functions provides a statement function
The function long ReadCardInfo (ref long flag, ref s_carddata carddata) library "M1card. DLL
"So call will prompt the error code 15

So, preliminary judgment this DLL can only be invoked by means of ole, this sentence obj ReadCardInfo (code, carddata), may be passed carddata structure parameter error,
Consult everybody how should handle?

CodePudding user response:

Problems should be defined in the structure type, do not use an int in the pb, with a long

Or


Obj. ReadCardInfo (code, ref carddata)

CodePudding user response:

In PB, the definition of structure, int has been to long, double constant, widestring converted to string
Obj. ReadCardInfo (code, ref
carddata)Call, also tried to add ref and not add ref, is the same error

Obj. InitCard (Key Code, 1, ctcode)//this call normal
RTN=obj. ReadCardInfo (code, carddata)//the wrong line call

The calls to normal, not used structure parameters, call is normal, the next line used carddata structure, call is wrong

CodePudding user response:

refer to the second floor qqlovepopo response:
in PB, the definition of structure, int has been to long, double constant, widestring converted to string
Obj. ReadCardInfo (code, ref
carddata)Call, also tried to add ref and not add ref, is the same error

Obj. InitCard (Key Code, 1, ctcode)//this call normal
RTN=obj. ReadCardInfo (code, carddata)//the wrong line call

The calls to normal, not used structure parameters, call is normal, the next line used carddata structure, error call


That should be still a problem with the structure, if for pchar WideString type, compatibility is better, if a WideString or string, compatibility, other language called error-prone, adjust the interface advice, if they do not adjust, suggest you use Delphi to encapsulate a DLL, and then call in pb

CodePudding user response:

Encapsulated with Delphi that trouble again,
, M1card. This interface DLL file, and divided into CPIC, a few classes, such as CPID CPIC is the specific function, such as ReadCardInfo (para1, para2), in a DLL, TCardData this structure is not under CPIC and CPID, but directly in M1card. DLL, CPIC is at the same level, and that how to make the PB can refer to get M1card. DLL this structure,
I've tried
OleObject objcard

Objcard=Create OleObject
Objcard. ConnectToNewObject (" M1card TCardData ")


Obj. InitCard (Key Code, 1, ctcode)//this call normal
RTN=obj. ReadCardInfo (code, ref objcard)
Or reference,

CodePudding user response:

The VB demo, they provide no defined structure, but direct reference M1card. DLL structures
Dim carddata as Tcarddata
And then direct call
Obj. ReadCardInfo (code, carddata)
  • Related