Re: Help for use a DLL
- From: "Antonio Garcia Garcia" <aggg63@xxxxxxxx>
- Date: Wed, 31 Aug 2005 07:33:24 +0000 (UTC)
Rob Kennedy wrote:
Thanks a lot for your answer.
> 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.
I'm sorry for this mistake. But I have an unit with all definition
types like this
type
PEgdbType = ^EGDB_TYPE;
I work at home where I can't post to news server. At work I wrote the
function from my bad memory. My apologies for this.
I have this in my unit.
> function egdb_identify(directory: PAnsiChar; egdb_type: PEgdbType;
> max_pieces: PInteger): Integer; stdcall;
If I said that function works and return the database type: first, It
compile very well; second, I can watch the variable egdb_type and see
that returns the database type correctly. I'm sorry for point this
comment.
> > 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.
I will do all suggestions. Next time will write the complete unit I use
to access to DLL. Thanks again.
.
- References:
- Re: Help for use a DLL
- From: Rob Kennedy
- Re: Help for use a DLL
- Prev by Date: Re: terminal services compatibility
- Next by Date: Re: OOP style
- Previous by thread: Re: Help for use a DLL
- Next by thread: Re: Gantt serie with different colors
- Index(es):
Relevant Pages
|