Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data type C++ / Delphi

Status
Not open for further replies.

carlosparedes

Programmer
Jun 10, 2007
12
GB
I am trying to use a function from C++ in delphi. I keep on getting an access violation error. Could you help me.


Function in C++

VEXPORT int CALLBACK GetCard(char *macAddr,int *cardSetID,int *noFormat,char *cardNumber,int cardNumberSize,char *pin,int pinSize,int *accessType,
unsigned int *uniqueID,int*accessGroup1,int*accessGroup2,
int *accessGroup3,int *accessGroup4,int *accessGroup5,
int *accessGroup6,int *accessGroup7,int *accessGroup8,int *extendedAccess,int *passbackExempt,int *pinCmds,
char *startDate,int startDateSize,char *startTime,
int startTimeSize,char *endDate,int endDateSize,
char *endTime,int endTimeSize,unsigned int *escortID,int *inElevGroup,int *outElevGroup,int *deleted);


My conversion to delphi:

Function GetCardRecord(macAddr:pChar;cardSetID:integer;
noFormat:integer;cardNumber:pChar; cardNumberSize:integer;pin:pchar;
pinSize:integer;accessType:integer;uniqueID:cardinal;accessGroup1:integer;
accessGroup2:integer;accessGroup3:integer;accessGroup4:integer;accessGroup5:integer;
accessGroup6:integer;accessGroup7:integer;accessGroup8:integer;extendedAccess:integer;
passbackExempt:integer;pinCmds:integer;startDate:pChar; startDateSize:integer;startTime:pChar;startTimeSize:integer;
endDate:pChar; endDateSize:integer;endTime:pChar; endTimeSize:integer;escortID:Cardinal;inElevGroup:integer;
outElevGroup:integer;deleted:integer):integer


Please help me

Sandra
 
The first thing that jumps out to me is that C is going to use a different calling convention than Delphi. Try adding "stdcall;" to the Delphi definition, and if that doesn't work, let us know.

should be of some assistance too in the event the suggestion above doesn't help.
 
I have added stdcall; external 'name of dll';
Still giving me the same error.
Sorry.

Thanks
 
What was the target compiler of the C++ code?

Only thing other than the "stdcall;" on the Delphi definition is this: I looked over the definitions, and with things like

Code:
int *accessGroup1

If I read that right, it's not an integer, but a pointer to an integer. I'm not aware (not in front of a copy of Delphi) to know whether it's already defined for you, but you can try something like:

Code:
type
  pinteger = ^integer;

accessgroup1: pinteger;

It seems incredibly odd to me that the function is looking for pointers to integers (that's the way I read it now that I look at it closer), but at least that's something else you can try.
 
try adding var in front of the * parameters

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top