Re: Help for use a DLL



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.

.



Relevant Pages

  • Re: Delphi Jobs
    ... I am a Delphi database programmer. ... Source Safe and Source Off Site on the server side and client side. ... design several pieces for the interactive website. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Embarcaderos Director of Products Blog
    ... What indications were there that it was difficult to sell, ... but Delphi has ALWAYS been about database development. ... All of which DO make perfect sense and could be seen as having a home at ...
    (borland.public.delphi.non-technical)
  • Software specifications
    ... I have been frustrated in this project because my software and hardware is ... another programmer who has been my mentor in Delphi, ... me when it will be ready, as they are struggling with old MSDOS software ... could do the entire database project myself, ...
    (comp.lang.pascal.delphi.misc)
  • Database Landscape for future Delphi work.
    ... I'm a died-in-the-wool Delphi fan, and have been programming in Delphi since ... So I switched my database to Jet 4.0 and to using ADO via Delphi's ... Good support for syncing w/ SQL Server. ...
    (borland.public.delphi.non-technical)
  • Re: acucobol
    ... J have not any experience with cobol ... If there is something who let me to acces to this db with delphi j have solved the problem ... Do you in fact need to learn COBOL at all, or are you just interested in getting data from the DataBase to be used with another language. ... If that's the case, dependent upon the DB used in the AcuCOBOL application you should be able to EXPORT the data, and IMPORT the data into the Delphi DB - that might be your solution. ...
    (comp.lang.cobol)