Solved

Converting C header file statements to Delphi

Posted on 2004-04-27
8
575 Views
Last Modified: 2012-11-10
I need help converting two statements from a C header file to their Delphi equivalents.  The first one is the extern const statement below.  I'm not sure if this should be defined as a pointer or what.

The second statement is the typedef that I've attempted to convert...I just wanted someone to check it and let me know if it is correct.

Thanks

1.
/* Memory function tables */
extern const BioAPI_MEMORY_FUNCS BioAPIMemoryFuncs;

2. Original C statement...

 typedef void * (BioAPI *BioAPI_MALLOC) ( uint32 Size,
                                                              void * Allocref,
                                                              const char * File,
                                                              uint32 Line);

My converted Delphi equivalent.....

  type
    BioApi_Malloc = procedure( Size: Cardinal;
                                             Allocref: Pointer;
                                             Const _File: Char;
                                             Line: Cardinal);

0
Comment
Question by:rwcochran
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
ID: 10930845

The typedef for  _File should be PChar. It would also help to see what BioAPIMemoryFuncs is actually declared as, before making a judgement on the data type definition


Regards,
Russell
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10930869

This also returns a void (generic) pointer, so it is not a procedure

 type
    BioApi_Malloc = function(Size: Cardinal;
                                        Allocref: Pointer;
                                        Const _File: PChar;
                                        Line: Cardinal): Pointer;

Russell
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 10930950
type
    BioApi_Malloc = function(Size: Cardinal;
                                        Allocref: Pointer;
                                        Const _File: PChar;
                                        Line: Cardinal): Pointer; stdcall;

To guess at the calling convention.

The other declaration is a global variable which is not easily accessible in Delphi.
0
 

Author Comment

by:rwcochran
ID: 10932816
Thanks for the help guys.  I found the BioAPIMemoryFuncs definition in another source file (see below)...how would this be converted to Delphi?

Thanks again....

/* Memory function tables */
const BioAPI_MEMORY_FUNCS BioAPIMemoryFuncs =
{
      _BioAPI_malloc,
      _BioAPI_free,
      _BioAPI_realloc,
      _BioAPI_calloc,
      NULL
};
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 26

Expert Comment

by:Russell Libby
ID: 10933028

Here is the delphi translation based on C source I found on the Net. Appears uou might have a newer definition, as the malloc function takes more parameters than the version I looked at. Also, are YOU are supposed to implement the memory functions on your side of this?? Hard to tell without seeing the full source, so I declared _BioPAPI_XXXX calls as variable types.


type
  TBioAPI_MALLOC       =  function(Size: Cardinal; Allocref: Pointer): Pointer; stdcall;
  TBioAPI_FREE         =  procedure(MemBlock: Pointer; Allocref: Pointer); stdcall;
  TBioAPI_REALLOC      =  function(Memblock: Pointer; Size: Cardinal; Allocref: Pointer): Pointer; stdcall;
  TBioAPI_CALLOC       =  function(Num: Cardinal; Size: Cardinal; AllocRef: Pointer): Pointer; stdcall;

type
  TBioAPI_MEMORY_FUNCS =  packed record
     Malloc_func:      TBioAPI_MALLOC;
     Free_func:        TBioAPI_FREE;
     Realloc_func:     TBioAPI_REALLOC;
     Calloc_func:      TBioAPI_CALLOC;
     AllocRef:         Pointer;
  end;

var
  _BioAPI_malloc:      TBioAPI_MALLOC; // These obviously need to be set
  _BioAPI_free:        TBioAPI_FREE;
  _BioAPI_realloc:     TBioAPI_REALLOC;
  _BioAPI_calloc:      TBioAPI_CALLOC;

  BioAPI_MEMORY_FUNCS: TBioAPI_MEMORY_FUNCS;


initialization

  BioAPI_MEMORY_FUNCS.Malloc_func:=@_BioAPI_malloc;
  BioAPI_MEMORY_FUNCS.Free_func:=@_BioAPI_free;
  BioAPI_MEMORY_FUNCS.Realloc_func:=@_BioAPI_realloc;
  BioAPI_MEMORY_FUNCS.Calloc_func:=@_BioAPI_calloc;
  BioAPI_MEMORY_FUNCS.Allocref:=nil;

end.
0
 

Author Comment

by:rwcochran
ID: 10933397
Very helpful....thanks.  As far as whether I have to implement the memory functions on my side or not, at this point I'm not sure.  

I'm just slowing working through the basic BioApi functions.... I'm trying to get to the point where I can talk to the fingerprint reader.  I ran into the BioAPIMemoryFuncs reference when working on the following function:

      bioReturn := BioAPI_ModuleAttach(uuid, bioVersion, BioAPIMemoryFuncs, 0,
                                  0, 0, 0, NULL, 0, NULL, &hModule);

I've already implemented the following BioApi functions and they seem to work fine.
  bioReturn := BioAPI_Init( bioVersion, 0, nil, 0, nil );
  bioReturn := BioAPI_ModuleLoad( uuid, 0, nil, nil);

The next BioApi function I'll be woking on is:
    bioReturn = BioAPI_SetGUICallbacks(hModule,
                                       NULL, NULL,
                                       state_callback, &callbac_ctx);

I really appreciate all the help.
0
 

Expert Comment

by:asiasker
ID: 38473456
hi rllibby,
"Here is the delphi translation based on C source I found on the Net"
i need translations of other files.. if you see them i wil be Thankfull.
0
 

Expert Comment

by:asiasker
ID: 38587869
hi rllibby and  rwcochran ,

rllibby :"Here is the delphi translation based on C source I found on the Net"
i need translations of other files.. if you see them i wil be Thankfull.

rwcochran , can you help to me  same problem as you already solved?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 287
Virtuailstring tree compare node issue 14 105
Communication Between RC4 Delphi <-> PHP 3 101
How to build JSON File in Delphi 6 3 17
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now