Re: Help for use a DLL
- From: Rob Kennedy <me3@xxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 22:16:22 -0500
Antonio Garcia Garcia wrote:
I written an unit in Delphi that can identify the database. This part was translated with tool h2pas.exe from Lazarus compiler.
function egdb_identify(directory: pchar; var egdb_type: TEGDB_TYPE; max_pieces: integer);
It works fine, it returns the database type :-)
If obviously _doesn't_ work fine. It won't even compile.
This is the original in header file. EGDB_API int egdb_identify(char *directory, EGDB_TYPE *egdb_type, int *max_pieces);
Go find the definition of the EGDB_API macro. You'll need it. Here's how I would declare that function in Delphi:
type PEgdbType = ^EGDB_TYPE;
function egdb_identify(directory: PAnsiChar; egdb_type: PEgdbType; max_pieces: PInteger): Integer; stdcall;
That "stdcall" on the end is written on the *assumption* that EGDB_API indicates that it uses the stdcall calling convention. You'll need to check that macro definition to be sure.
But I can't use this structure of functions to open the database :-( I don't know how manage this record!
// The driver handle type Pegdb_driver = ^egdb_driver; egdb_driver = record lookup: function (handle: Pegdb_driver;position: PEGDB_BITMAP; color: integer; cl: integer): longint; cdecl; reset_stats: procedure (handle: Pegdb_driver); get_stats: function (handle: Pegdb_driver): PEGDB_STATS; verify: function (handle: Pegdb_driver): integer; close: function (handle: Pegdb_driver): integer; internal_data: pointer; end;
Please, can anybody tell me how rewrite this in Delphi. Thanks a lot.
It's already in Delphi. You just posted it right here. You just need to add "cdecl" to the ends of the rest of the function-pointer declarations, like you have on the lookup field.
These are the original structures and functions in header file, translated with tool h2pas.exe from Lazarus compiler.
/* The driver handle type */
typedef struct egdb_driver {
int (*lookup)(struct egdb_driver *handle, EGDB_BITMAP *position, int color, int cl);
void (*reset_stats)(struct egdb_driver *handle);
EGDB_STATS *(*get_stats)(struct egdb_driver *handle);
int (*verify)(struct egdb_driver *handle);
int (*close)(struct egdb_driver *handle);
void *internal_data;
} EGDB_DRIVER;
/* Open an endgame database driver. */ EGDB_API EGDB_DRIVER *egdb_open(EGDB_BITMAP_TYPE bitmap_type, int pieces, int cache_mb, char *directory,void (*msg_fn)(char *));
type TMsgProc = procedure(Param: PAnsiChar); cdecl;
function egdb_open(bitmap_type: Egdb_Bitmap_Type; pieces, cache_mb: Integer; directory: PAnsiChar; msg_fn: TMsgProc): PEgdb_Driver; stdcall;
Again, confirm that stdcall. The final parameter of this function is a procedure pointer. You'll need to declare a procedure (*not* a method of an object) that matches the signature above: one PAnsiChar parameter, and cdecl calling convention. You can name the procedure, and its parameter, whatever you want. Presumably, Egdb_Open will call that procedure to pass messages back to your program.
-- Rob .
- Follow-Ups:
- Re: Help for use a DLL
- From: Antonio Garcia Garcia
- Re: Help for use a DLL
- Prev by Date: Re: Getting file names "on the fly" with XP?
- Next by Date: Re: terminal services compatibility
- Previous by thread: Getting file names "on the fly" with XP?
- Next by thread: Re: Help for use a DLL
- Index(es):