Link to home
Start Free TrialLog in
Avatar of DaveMon
DaveMonFlag for United States of America

asked on

how to call functions

Hello All,

I am programming an application for a handheld   computer  that has a barcode scanner as a peripheral device,  I have obtained the software Dev Kit from the manufacturer, and it contains all the header files and libraries to operate any approved periphs for the unit.

My question is this:  how do I call the functions from the header files and or libraries to enable this unit to scan barcodes?  I belive the process  goes  somewhat like  step1) Initialise scanner
step2) get scanned data step3) uninitialise scanner.    I am  currrently waiting  on more  information from the Dev Kit manufacturer  but  would  like  to begin  tryin  some  ideas.
As you can probably tell,  I am very new at C programming,  so any extra detail you can spare  will go a long  way  and  be very appreciated.  For the record,  the Development environment is a package  called "Penright!"   and  it is  a visual IDE  that  allows  custom C code to be added.
Bottom  line......how  do I call functions in my header files?   what  do I look for? what  is the syntax?   what errors  will I receive  if  I do it wrong?   I know  this  is a potentially  endless question,  and  I dont  expect  a C tutorial....but   a little  guidance and  a little  overview  would  be great.   Thanks  in Advance  

DaveMon
Avatar of homer99
homer99

DaveMon:

The first thing that you need to do is to include the header file at the top of your code:
#include<header.h>

Then you have to find out the names of the functions that are contained in the header file.

Then you should note what parameters are necessary to call the funcion.

For example if the function in the header file is called:

int function1(int num1, int num2)

This function is called function1 it has two integer parameters (num1, num2) and it returns an integer.
So in your code you can call it like this:

#include<header.h>

main()
{
int integer1
int integer2
int integer3
..
..
..
integer3 = function1(integer1, integer2)
..
..
..
}
This would call function1 using integer1 and integer2 as parameters and return answer into integer3.







Also all code contained in the brackets of the main function should end with ;
I don't reply to you Q about Function :
homer99 said basic things, other see
in every C/C++ tutorial. But about scanning barcode:
I risk to answer, becouse i have made same system(work
name: Shop). And reply is very simple: you don't need
make anything! Detailes:
You use plug-in cable of keybord and set it in Scaner.
You use plug-in cable of Scaner and set it in Computer.
Now: if user presses key on the keybord, key simple
go to computer , but if user scans a Barcode, you get
Input : some digits( 1234567890123 for example,
usually 13 digits) . You programm in this moment
is in BarCode Contol and treats it (my, for example,
get data about Products from DataBase and display
name of product,price...).
Question: what will be, if you in other Control(for example
in name of product) and user scans a Barcode? For protect from this, i test Name of product : can't be all digits!

I hope, it helps. Alex

Avatar of DaveMon

ASKER

I appreciate the help alex,   but  the  unit  in question  has  no  keyboard,  only  a touch  panel,  and I am using  one companies  software  to make  another  companies hardware work ( with the aid  of  their  libs  and  header  files )....while  Im  here.....Homer  could you tell me basically, how  I would  call the function in this header   file?    

///////////////////////////
// SCAN is the scanned data from the read routine
// Reading is this converted to ASCII
// Both routines remove start and stop sentinels from the data

#include "SCNTST.h"


// 6 bit data TEXT and Numeric
int decode_track1 (char *reading, char *scan);

// 6 bit data Numeric only (and separators)
int decode_track2 (char *reading, char *scan);

// This routine calculates the length of the barcode data
int data_length (char *buffer);

//////////////////////////////////

again,  all I need  are  basic  guidelines  as  to how  these  calls  are made  in code

DaveMon
there are three functions declared in the header file:

int decode_track1 (char *reading, char *scan);
int decode_track2 (char *reading, char *scan);
int data_length (char *buffer);



for example, in your C code:

int nReturnVal;
int nDataLen;

char szReading[1024]; // define this however big you need it to be...
char szScan[1024];   // same here...

you would like to see the user documentation on how these functions are actually used, however...
nReturnVal = decode_track1(&szReading, &szScan);

nDataLen = data_length(&szScan);
You tell your program what procedures you are going to use by putting
#include<thenameoftheheaderfile.h>
near the top of your program, just like homer said.

You call the procedures just like you would call a procedure that you wrote.

You also will have to tell the linker to include the object file that contains the procedures.  It will look something like procedures.o
You didn't say what compiler you are using so no one can tell you the exact command.
Hi Dave
The above mentioned steps are alright.
 it will be nice if you have all your header files in one directory and then give the path for library searching as that directory's path.Otherwise sometimes you get an error saying that library not found or something similar to that.
Anup
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You also need to tell the compiler where the library files are located on your drive.

The header file takes care of the compile step so your program can compile your function calls.

For the link step: you need to supply information to the linker so the library that corresponds to the header can be drawn into your executable program. The IDE that you are using will have an option screen that allows you to specify what library files to include and where they can be found. If you don't do this you will get linker errors along the lines of "Unresolved symbol" or "undefined function" or something like that.

Bill Nicholson
Avatar of DaveMon

ASKER

Big  Thanks   to everyone....Im  going  to accept  Alex's   answer   and  post  2  twenty  point  questions   for  captainkirk  and homer99  in  the  C  area.....again,  thanks   everyone


DaveMon