Announcement

Collapse
No announcement yet.

function pointer translation - help needed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • function pointer translation - help needed

    hi,
    i tried to search for this translation problem, but couldn’t find anything.
    maybe some one can tell me how the following code is translated to powerbasic.
    i would need to know, how the function pointers are handled in powerbasic
    in a translated structure and in a translated function call.

    btw, is there a tool that will translate C headers to powerbasic include files?

    thank you for any help

    hans


    typedef signed short ISC_SHORT;
    typedef unsigned short ISC_USHORT;
    typedef unsigned char ISC_UCHAR;
    typedef char ISC_SCHAR;
    typedef signed long ISC_LONG;
    typedef unsigned long ISC_ULONG;

    typedef void (* isc_callback) ();
    typedef ISC_LONG isc_resv_handle;
    typedef void (*ISC_PRINT_CALLBACK) (void*, ISC_SHORT, const char*);
    typedef void (*ISC_VERSION_CALLBACK)(void*, const char*);
    typedef void (*ISC_EVENT_CALLBACK) (void*, ISC_USHORT, const ISC_UCHAR*);

    ISC_STATUS ISC_EXPORT isc_print_blr(const ISC_SCHAR*,
    ISC_PRINT_CALLBACK,
    void*,
    short);
    typedef struct blobcallback {
    short (*blob_get_segment) (void* hnd, ISC_UCHAR* buffer, ISC_USHORT buf_size, ISC_USHORT* result_len);
    void* blob_handle;
    ISC_LONG blob_number_segments;
    ISC_LONG blob_max_segment;
    ISC_LONG blob_total_length;
    void (*blob_put_segment)(void* hnd, const ISC_UCHAR* buffer, ISC_USHORT buf_size);
    ISC_LONG (*blob_lseek)(void* hnd, ISC_USHORT mode, ISC_LONG offset);
    } *BLOBCALLBACK;

  • #2
    Code:
    FUNCTION isc_callback() AS DWORD
    END FUNCTION
    
    FUNCTION isc_resv_handle() AS LONG
    END FUNCTION
    
    FUNCTION ISC_PRINT_CALLBACK(BYVAL p1 AS DWORD, BYVAL p2 AS INTEGER, BYREF p3 AS ASCIIZ) AS DWORD
    END FUNCTION
    
    FUNCTION ISC_VERSION_CALLBACK(BYVAL p1 AS DWORD, BYREF p2 AS ASCIIZ) AS DWORD
    END FUNCTION
    
    FUNCTION ISC_EVENT_CALLBACK(BYVAL p1 AS DWORD, BYVAL p2 AS WORD, BYREF p3 AS ASCIIZ) AS DWORD
    END FUNCTION
    
    DECLARE FUNCTION isc_print_blr LIB "<name of the dll>" ALIAS "isc_print_blr" ( _
       BYREF p1 AS ASCIIZ, BYVAL p2 AS DWORD, BYVAL p3 AS DWORD, BYVAL p4 AS WORD) AS LONG
    
    TYPE BLOBCALLBACK
       fn_blob_get_segment AS DWORD
       fn_blob_handle AS DWORD
       fn_blob_number_segments AS DWORD
       fn_blob_max_segment AS DWORD
       fn_blob_total_length AS DWORD
       fn_blob_put_segment AS DWORD
       fn_blob_lseek AS DWORD
    END TYPE
    Last edited by José Roca; 2 Dec 2008, 11:41 AM.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      thank you very much for your help and advice!

      hans

      Comment


      • #4
        If you have to use the pointers in the BLOBCALLBACK structure to call a function, then you can do it this way.

        Declare a prototype for the function, e.g.

        Code:
        ' ISC_LONG blob_number_segments;
        DECLARE FUNCTION blob_number_segments() AS LONG
        Use CALL DWORD with the pointer stored in the structure.

        Code:
        DIM nSegments AS LONG
        CALL DWORD <name of the udt dimed AS BLOBCALLBACK>.fn_blob_number_segments USING blob_number_segments TO nSegments
        Last edited by José Roca; 2 Dec 2008, 01:45 PM.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          thank you.
          yes i think i need to use it as pointers. is there any tool that will translate, for example the firebird headers, atleast semi automatic? this is a lot of work for somebody new that is to PB.

          btw, i applied for you board.

          thanks again

          hans

          Comment


          • #6
            None that does a good job. It is very difficult because C uses many typedefs, macros and weird syntaxes.

            Your account has been approved. Sorry for the delay.
            Forum: http://www.jose.it-berater.org/smfforum/index.php

            Comment


            • #7
              thank you!!

              hans

              Comment

              Working...
              X