Announcement

Collapse
No announcement yet.

C to PB DataType Cross Reference

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

  • C to PB DataType Cross Reference

    I’ve taken on a project to create a DLL for a third-party
    program called TradeStation. I’ve seen all the postings that
    the search engine can retrieve under that word-name and I’ve
    also searched the entire site again looking for references to
    using ‘C Declarations’.

    To a large extent, there is a lot of information in this forum,
    but none of it is in one place and nothing I’ve seen has tried
    to cover all the bases by providing a complete reference.

    In the hope that I’ll be able to change a “C-definitions.h” file
    to the syntax that the PBWIN compiler will understand, I’ve
    created an understanding of what I think I’ve learned from
    working through all those forum messages.

    If someone who is knowledgeable about converting “C” syntax to PB
    syntax could look at the tables listed below and flag where I
    need to make corrections, if any, I’ll edit the posting and the
    forum will have a good cross reference in one place. Once that
    is done, I’ll take on the challenge of trying to convert the
    complete “.h” file and will create a DLL skeleton that I’ll post
    as I get pieces to work so others who will also want to take
    this on for themselves will have a solid reference.

    Code:
    32-bit Windows C data-type Name to PB data-type Name Cross Reference:
    
    Fundamental DATA Types:
    -----------------------
             C/C++ Names:   PB Names:
             ------------   ---------
                BYTE        BYTE  (IF C Bytes are unsigned)
                char        STRING  
                INT         LONG
                WORD        INT
                LONG        LONG
                DWORD       DWORD
                float       SINGLE
                DOUBLE      DOUBLE
                bool        <no clue> (BYTE would seem TO DO the same work, but...)
       
    Variants DATA Types:
    --------------------
             C/C++ Names:   PB Names:
             ------------   ---------
             unsigned LONG  DWORD
             void           %NULL
             
             
    POINTER DATA Types:
    --------------------
             C/C++ Names:   PB Names:
             ------------   ---------
             LPBYTE         BYVAL(DWORD)
             LPINT          BYVAL(DWORD)
             LPWORD         BYVAL(DWORD)
             LPLONG         BYVAL(DWORD)
             LPDWORD        BYVAL(DWORD)
             LPFLOAT        BYVAL(DWORD)
             LPDOUBLE       BYVAL(DWORD)
             LPSTR          BYVAL(DWORD)
    Any advice is appreciated.
    Thanks,

    ------------------
    Roger...
    (Mail to rdrines at SpamCop dot Net)
    Roger...

  • #2
    I'm curious about how to send a large string array from a PB exe to a C dll.

    Comment


    • #3
      Code:
      32-bit Windows C data-type Name to PB data-type Name Cross Reference:
      
      Fundamental DATA Types:
      -----------------------
               C/C++ Names:   PB Names:
               ------------   ---------
                  BYTE        BYTE  
                  char        BYTE or STRING * 1  
                  INT         LONG
                  WORD        WORD
                  LONG        LONG
                  DWORD       DWORD
                  float       SINGLE
                  DOUBLE      DOUBLE
                  bool        LONG
         
              
               
      POINTER DATA Types:
      --------------------
               C/C++ Names:   PB Names:
               ------------   ---------
               LPBYTE         BYREF BYTE 
               LPINT          BYREF LONG 
               LPWORD         BYREF WORD
               LPLONG         BYREF LONG
               LPDWORD        BYREF DWORD
               LPFLOAT        BYREF SINGLE
               LPDOUBLE       BYREF DOUBLE
               LPSTR          BYREF ASCIIZ
      (See helpfile; topic DataTypes -> Comparative DataTypes)

      ------------------
      Peter.
      mailto[email protected][email protected]</A>
      Regards,
      Peter

      Comment


      • #4
        thanks for responding peter.

        okay on the fundamental data types and where they are in the help
        file. i went through a lot of that section, but never got to the
        end. i'll keep the topic displayed on the left side from now on.

        on the pointer types, your response has me scratching my head
        because of the postings lance gave in this message towards the
        bottom of the thread: http://www.powerbasic.com/support/pb...ead.php?t=3565

        in this message, lance is recommending byval, so that influenced my
        decision in my table because i think addresses are being passed.
        however, he accurately ask if the poster knows what is being
        passed and i must say i don't know because the information doesn't
        really say. i do know they don't have an elegant interface and
        don't do much to explain what is happening, but they are good at
        answering pointed questions so i'll send them a message with an
        example to see if i can get a better understanding.

        by the way, lance's example works, but i don't understand why.
        this is part of the the motivation to get things documented so
        i'm forced to understanding things and so others will have a
        reference.

        here is how i had converted a c-declaration in their ".h" file,
        but i'm now wondering about what is being passed.

        Code:
        declare function  findaddress_downticks  lib "c:\program files\omega research\program\elkit32.dll" alias "findaddress_downticks"_
        	                                 (byval lpdownticks as long, byval nofs as long) as long
        'lplong far pascal findaddress_downticks (lplong lpdownticks, int nofs);
        
        
        declare function findaddress_date lib "c:\program files\omega research\program\elkit32.dll" alias "findaddress_date"_
                                            (byval lpdate as long, int nofs) as dword
        'lplong far pascal findaddress_date (lplong lpdate, int nofs);
        
        
        declare function findaddress_time lib "c:\program files\omega research\program\elkit32.dll" alias "findaddress_time"_
                                         (byval lptime as long, byval nofs as long) as dword
        'lpint far pascal findaddress_time (lpint lptime, int nofs);
        
                                           
        declare function  findaddress_var lib "c:\program files\omega research\program\elkit32.dll" alias "findaddress_var"_
                               (byval lpvar as single, byval nofs as long, byval wstartaddr as dword, byval wvarsize as dword) as dword
        'lpfloat far pascal findaddress_var (lpfloat lpvar, int nofs, dword wstartaddr, dword wvarsize);
        ------------------
        roger...
        (mail to rdrines at spamcop dot net)

        [this message has been edited by roger rines (edited april 16, 2003).]
        Roger...

        Comment


        • #5
          PB help file has these ones:

          C/C++

          Type Language Format PowerBASIC

          bool C++ unsigned 8-bit BYTE (2)
          char C/C++ signed 8-bit BYTE (2)
          char* C/C++ ASCIIZ pointer ASCIIZ [PTR] (1)
          double C/C++ 8-byte float DOUBLE
          float C/C++ 4-byte float SINGLE
          int C/C++ signed 32-bit LONG (3)
          long C/C++ signed 32-bit LONG
          short C/C++ signed 16-bit INTEGER

          ------------------
          PB6'er from England!
          ...
          #BLOAT 100000000

          Comment


          • #6
            C passes all values BYVAL. In the case where a C program is passing
            a pointer to a value, then, it may make sense to translate this into
            PowerBASIC in either of two ways: as a BYVAL pointer, or as the actual
            value BYREF. For example, if there's a C parameter "LPDWORD lpd", you
            might reasonably translate this to PB either as "BYVAL lpd AS DWORD PTR"
            or as "BYREF d AS DWORD". It just depends on which is more convenient
            for you.

            ------------------
            Tom Hanlin
            PowerBASIC Staff

            Comment

            Working...
            X