Results 1 to 3 of 3

Thread: (re)Defining library API

  1. #1

    (re)Defining library API

    You know, I'm working on the next high revision of Allegro.pas. In the FPC mailing list somebody suggested to use the "ctypes" unit to fix the problems with data types, specially because it ensures the correct data type despite the platform (i.e. 32bit -> 64bit and such).

    I was wondering it would be better to define INLINE wrappers from standard Pascal data types to ctype data type. For example:

    Code:
    INTERFACE
    
      FUNCTION al_get_allegro_version: LONGWORD; INLINE;
      FUNCTION al_load_bitmap (CONST filename: STRING): ALLEGRO_BITMAPptr; INLINE;
    
    IMPLEMENTATION
    
      FUNCTION _al_get_allegro_version_: cuint32; CDECL;
      EXTERNAL ALLEGRO_LIB_NAME 'al_get_allegro_version';
    
      FUNCTION al_get_allegro_version: LONGWORD;
      BEGIN
        al_get_allegro_version := _al_get_allegro_version_;
      END;
    
      FUNCTION _al_load_bitmap_ (CONST filename: pcchar): ALLEGRO_BITMAPptr; CDECL;
      EXTERNAL ALLEGRO_LIB_NAME 'al_load_bitmap';
    
      FUNCTION al_load_bitmap (CONST filename: STRING): ALLEGRO_BITMAPptr;
      VAR
        TheString: pccar;
      BEGIN
        TheString := StrAlloc (Length (filename));
        StrPCopy (TheString, filename);
        TRY
          al_load_bitmap := _al_load_bitmap_ (TheString);
        FINALLY
          StrDispose (TheString);
        END;
      END;
    In some cases it's mandatory, as with STRING, but what about the other cases? It's a good idea?

    And has Delphi the "ctypes" unit too?
    No signature provided yet.

  2. #2
    yes i have also heard about ctypes and it can perfectly work for it.

  3. #3
    I was thinking about it (note this thread is from 2012!!!) and finally I defined my own types. As I said, Delphi don't had ctype (or don't have it in some of the most used versions) so that was the best solution.

    You can see the final solution here (for Allegro 5, but for Allegro 4 is the same).
    No signature provided yet.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL