Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DLL call in Delphi

Posted on 2008-10-13
8
Medium Priority
?
772 Views
Last Modified: 2012-05-05
Hi all,
I am trying to write some functions for a dll which means I need to declare the function, and call the function - sorry im not very good at these!
I have an example piece of code which was written in C++ and this is how it calls the function
 RDR_SendCommandGetData(reader_handle, "select", "", buffer);

I have details on how what the functions requires here

RDR_SendCommandGetData // this is the function name
The RDR_SendCommandGetData function sends a command to a reader specified by its
handle and receives data.


Win char* RDR_SendCommandGetData(void* hReader, char* command, char* / this is some kind of declaration or description on the function
data, char* buffer);

Parameter Description // next are the defination of the variables required.
hReader:      Handle of reader to send a command.
command: 0 terminated string with the command e,g one of the commands I know is "select"
data: ASCII 0 terminated string containing the data
                  BIN length of data (1 byte) + data  // note when using the select command there is no data
buffer: A buffer of the return value.
                        ASCII protocol: The buffer size has the range of 514 bytes.
                        BIN protocol: The buffer size has the range of 256 bytes.
                        
I am getting confused with the char variable types and think they need to be pointers or something like that, I have put my code below but please appreciate it is wrong as I have been trying allsorts

function declared

function RDR_SendCommandGetData(readerhandle:integer;command:pointer;data:pointer;cardid:pointer):integer; stdcall; external 'Reader.dll' name 'RDR_SendCommandGetData'; // gets card ID

Im trying to call it as follows

readcard := RDR_SendCommandGetData(readerhandle, @command,@buffer,@cardid);
I have set command,buffer, and cardid as string type variables.

I really appreciate any help as my normal programmer is on leave and Im trying to sort this on my own (fat chance without you guys!)

thanks

Dave




                        
                        
                        
                        
0
Comment
Question by:monitorwa
  • 5
  • 3
8 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 22701152
Win char* RDR_SendCommandGetData(void* hReader, char* command, char* data, char* buffer);

translates to

function RDR_SendCommandGetData(hReader:pointer; command:pchar; data:pchar; buffer:pchar):pchar; stdcall; external 'dll_name_here.dll';
0
 

Author Comment

by:monitorwa
ID: 22707714
Thanks ciuly - I dont suppose you could add how you call the function and declare the variables?

thanks

Dave

0
 
LVL 28

Expert Comment

by:2266180
ID: 22709523
just like the parameters...

var
  readcard:pchar;
  readerhandle:pointer;
  command, buffer, cardid:pchar;
begin
  initialize readerhandle with some RDR_ call I suppose
  command:='select';
  buffer:='';// whatever
  cardid:='';// whatever
  readcard := RDR_SendCommandGetData(readerhandle, command,buffer,cardid);
  close readerhandle if needed with some other RDR_ call
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:monitorwa
ID: 22727871
sorry for the slow response, I have been trying all sorts of things with no success. I have done exactly as you listed above and keep getting an access violation at address 000000

Any odeas?

thanks
Dave
0
 

Author Comment

by:monitorwa
ID: 22728015
ok I think it may be from the way I had opened the port and reader, the instructions process is as follows

RDR_OpenComm
RDR_DetectReader
RDR_OpenReader
RDR_SendCommand
RDR_GetData
RDR_CloseReader
RDR_CloseComm

and the C++ definition is as follows

void* RDR_OpenComm(char* device, char autodetect, struct
presetSettings* settings);

char* RDR_DetectReader(void* hComm, char* buffer);

void* RDR_OpenReader(void* hComm, unsigned char id, short
knownReader);

char* RDR_SendCommandGetData(void* hReader, char* command, char*
data, char* buffer);


My attempts that dont work are as follows  - first the defination
function RDR_OpenComm(com_port:pchar;autodetect:char;settings:tdcb):pointer; stdcall; external 'Reader.dll' name 'RDR_OpenComm'; // returns port handle
function RDR_DetectReader(porthandle:pointer;detect_buffer:pchar):pchar; stdcall; external 'Reader.dll' name 'RDR_DetectReader'; // returns reader handle

and called as follows

com_port := 'com4';
porthandle := RDR_OpenComm(com_port,'1',structure);
RDR_DetectReader(porthandle, detect_buffer);


vars are
structure: tdcb;
com_port : pchar;
readerhandle,porthandle,  readeropen : pointer;
reply, command1,data,buffernew : string;
readcard :pchar;
command, buffer, cardid , detect_buffer , readerhand:pchar;


I have also attached the document that list all of these and more - Im really struggling here, it appears to get the com handle ok but cant get past the next stage

thanks

Dave





Reader-DLL-V3-3-0-User-Manual-03.zip
0
 

Author Comment

by:monitorwa
ID: 22763678
I guess Ill just have to put this one down as to hard for everyone!
Thanks to Ciurly but his answers didnt actually work

Dave
0
 
LVL 28

Accepted Solution

by:
2266180 earned 1500 total points
ID: 22765206
sorry. I've been busy and forgot about this one. I have about 4 questions in queue (meaning they are waiting for a few weeks).

that manual stuff looks pretty big so it will probably take me hours to read through, time that I don't have.

what we can do to speed thing up is you posting the c++ code and your translation and me correcting it. like in previous post, corrected translation is:

type
  pdcb=^tdcb;

function RDR_OpenComm(com_port:pchar;autodetect:char;settings:pdcb):pointer; stdcall; external 'Reader.dll' name 'RDR_OpenComm'; // returns port handle

function RDR_DetectReader(porthandle:pointer;detect_buffer:pchar):pchar; stdcall; external 'Reader.dll' name 'RDR_DetectReader'; // returns reader handle

also, these functions return some stuff. that stuff needs to be valiudated and that will show where the problem is. liek in your code, validating the result of rdr_opencomm should have yelded some errors. I suspect the returned pointer would be nil or pointing to an error structure or whatever. check the manual to see how to check the result of teh functions and where the errors are reported.

then get back to me with the info.

I don't mean to scare you or something, but I have one question which the asker is waiting for me like for 3 or 4 weeks now.
when it comes to more complicated problems that involve me, there are really only 3 possible scenarios:
- some other expert with more free time is pitching in
- the asker works with me so that he does the work and I give the isntructions and correct where needed
- the asker waits until I got time to solve the problem all by myself

these complicated problems take many hours and sometimes days to work on. you can imagine that my free time is not that much. when did you ever had a few days to do nothing and got bored? In my case that was like 10-12 years ago. my free time is what I take from the time allocated to my paid projects which is like a break.

so, bottom line: you cannot solve this by yourself. however, together we can solve it. so help me to help you ;)
0
 

Author Comment

by:monitorwa
ID: 22772743
Hi Ciuly,
I really appreciate your assistance so far and fully understand what you are saying - yea who gets spare time, certainly not me either! What I will do is award you the points as I am sure we would get there int he end but I dont need to waste your time anymore as my developer has come back from holidays and I think he has it all working now. I was really just trying to get a better understanding of these things but its not important enough for you to spend a lot of time trying to more or less teach me, so thanks again and maybe you will help with other questions I have
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question