Let's take a look at the problem of transferring values between PB-called Delphi DLL.

Source: Internet
Author: User
PB calls the value transfer between the DLL of Delphi. Let's take a look at Delphi/Windows SDK/API.
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061110115522258.html

PB master Program Call the DLL of Delphi. After the function is executed, the DLL returns a string to the Pb main program. The DLL uses the pchar type .. How can I receive it under Pb?


Int RC, sectorID = 15, I = 1
Char readstr [64]
Int li_data [64]
Char ls_data [64]
String data =''

Rc = m1querycard (15, ref readstr)

Do while I <= 64
Li_data [I] = ASC (readstr [I])
Ls_data [I] = get_hex (li_data [I])
I ++
Loop

// Readstr = get_hex_str (readstr)
MessageBox ('foxhis ', ls_data)

The above is a pb program... M1querycard (15, ref readstr) is a function in the DLL written by Delphi .. Readstr is a string that is returned by DLL in the pchar type.

The data cannot be read .. Who knows what the problem is?

Put your Delphi DLL function type and relatedCodeI also paste it. Otherwise, how can I see it?

The DLL Code of Delphi:

VaR
Readcarddatahex: string; // global variable

Function m1querycard (sectorID: callback int; var carddatas: pchar): integer; stdcall; // query card
VaR
....
Hexdata1, hexdata2: string;
Begin
.....
For I: = 0 to 15 do
Begin
Hexdata2: = hexdata2 + inttohex (carddata2 [I], 2 );
End;
End;
Readcarddatahex: = hexdata1 + hexdata2;
Carddatas: = pchar (readcarddatahex );
Result: = 0;
End;



My Delphi program calls normally like this:
Function m1querycard (sectorID: callback int; var carddatas: pchar): integer; stdcall; External m1dll;

PB calls the DLL in Delphi, which is a debugging problem between different development tools;

You can use Delphi to write a small test program to test the DLL. After the DLL function is correct, Pb calls the test;

Note that the DLL output type defined in external functions in PB must be correct. Generally, there should be no major problems.

Oh, I posted it so soon,

I think the problem is as follows:

Carddatas: = pchar (readcarddatahex); // readcarddatahex is a string class, which only points to the pointer,

Try it like this:
Strcopy (carddatas, readcarddatahex );

Strcopy (carddatas, pchar (readcarddatahex ));

To compile .. This is not the case. The program is dead. The XX error is prompted when the code in the DLL has not been executed ..

How is your m1querycard declared in Pb?

Function int m1querycard (INT sectorID, ref string carddatas) Library 'm1. dll ';

This is previously defined and cannot be used. I don't know if the other party has changed it.

I don't remember the special type of string in Pb.

In Delphi, pchar is the cha pointer, and your above Pb code: Char readstr [64];

Try again as follows:
Function int m1querycard (INT sectorID, ref char * carddatas) Library 'm1. dll ';

Well, I'm not sure if I can do it. I 've been using petabytes for a few years. I forgot.

In addition, how is your Delphi test code called?

If the second parameter of DLL does not use VaR, what will happen? Try it like this:

Function m1querycard (sectorID: shortint; carddatas: pchar): integer; stdcall; // query card
...

If you do not use VaR, you cannot get the return value.
The statement for calling Delphi is:
Function m1querycard (sectorID: callback int; var carddatas: pchar): integer; stdcall; External 'm1. dll ';

Alas. Depressed .. Not at all .. It is used in a simple way .. I save the read data as a text file, and the other party opens the file and reads it for processing ..

This definition is as follows:
Function m1querycard (sectorID: shortint; carddatas: pchar): integer; stdcall;

In Delphi, The pchar type can return data without var,

VaR
Cc: array [0 .. 256] of char
II: Random int;
Begin

M1querycard (I, CC );

Showmessage (CC); // you can return data.





Try this way:

In the DLL of Delphi:
Function m1querycard (sectorID: shortint; carddatas: pchar): integer; stdcall;

PB statement:
Function int m1querycard (INT sectorID, ref string carddatas) Library 'm1. dll ';

If this is the case, no problem will occur. The PB on my host has been deleted long ago.

Oh. Depressed .. I have never tried this. There is no problem with calling my Delphi Program. There is a problem with Pb ..
Let's talk to the other party in the afternoon .. I saved it as a file and read it .. Now we can use this method to transmit data .. Khan .. Really depressing

The pb program can be written as follows:

Int RC, sectorID = 15, I = 1
String readstr
Int li_data [64]
Char ls_data [64]
String data =''

Readstr = spaces (64)
Rc = m1querycard (15, readstr)

PB statement:
Function m1querycard (integer Len, ref string readstr )......


Try writing the Delphi program like this:
Function m1querycard (sectorID: integer; carddatas: pchar): integer; stdcall;

Shortint PB is not supported.

Use fastmm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.