Announcement

Collapse
No announcement yet.

Porting questions..

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

  • Porting questions..

    I have a C++ header file I am porting over, I finally found the time to do this.

    It's a HLLAPI type conversion, designed to be used to speak through an emulator to a host...

    So my questions are these typedef's, I am coming across some minor errors and not sure I am porting this correctly:


    Code:
    typedef struct tagATMSystem {
        WORD    wHLLAPIVersionNumber;
        WORD    wHLLAPILevelNumber;
        }       ATMSYSTEM, NEAR * NPATMSYSTEM, FAR * LPATMSYSTEM;
    
    typedef struct tagStartIntercept {
        char    cPSID;
        WORD    wKeyFilter;
        WORD    wQueueLength;
        BOOL    bWindowsMessage;
        }       STARTINTERCEPT, NEAR * NPSTARTINTERCEPT, FAR * LPSTARTINTERCEPT;
    
    
    PORTED:
    
    Type tagATMSystem
        wHLLAPIVersionNumber As Word
        wHLLAPILevelNumber As Word
    '     ATMSYSTEM, NEAR * NPATMSYSTEM, FAR * LPATMSYSTEM;
    End Type
    
    Type tagStartIntercept
        cPSID As String * 1
        wKeyFilter As Word
        wQueueLength As Word
        bWindowsMessage As Integer
    '       STARTINTERCEPT, NEAR * NPSTARTINTERCEPT, FAR * LPSTARTINTERCEPT;
    End Type                      
    
    ============================================================================================================
    Example 2
    
    typedef struct tagHLLParams {
        BYTE    byAttribute;        /*  ATTRB or NOATTRB    */
        BYTE    byAutoReset;        /*  AUTORESET or NOAUTORESET    */
        BYTE    byConnectType;      /*  CONLOG or CONPHYS   */
        BYTE    byEAB;              /*  EAB or NOEAB    */
        char    cEscape;            /*  default '@' */
        BYTE    byPause;            /*  IPAUSE or FPAUSE    */
        BYTE    bySearchOrigin;     /*  SRCHALL or SRCHFROM */
        BYTE    bySearchDirection;  /*  SRCHFORWARD or SRCHBKWD */
        WORD    wTimeOut;           /*  0..64k          */
        BYTE    byTrace;            /*  TRON or TROFF   */
        BYTE    byWait;             /*  TWAIT, LWAIT, NWAIT */
        BYTE    byXlate;            /*  ASCII<->3270DC translation or not   */
        }       HLLPARAMS, NEAR * NPHLLPARAMS, FAR * LPHLLPARAMS;
    
    
    PORTED:
    
    Type tagHLLParams
        byAttribute As Byte        '/*  ATTRB or NOATTRB    */
        byAutoReset As Byte        '/*  AUTORESET or NOAUTORESET    */
        byConnectType As Byte      '/*  CONLOG or CONPHYS   */
        byEAB As Byte              '/*  EAB or NOEAB    */
        cEscape As String * 1         '/*  default '@' */
        byPause As Byte            '/*  IPAUSE or FPAUSE    */
        bySearchOrigin As Byte     '/*  SRCHALL or SRCHFROM */
        bySearchDirection As Byte  '/*  SRCHFORWARD or SRCHBKWD */
        wTimeOut As Word           '/*  0..64k          */
        byTrace As Byte            '/*  TRON or TROFF   */
        byWait As Byte             '/*  TWAIT, LWAIT, NWAIT */
        byXlate As Byte            '/*  ASCII<->3270DC translation or not   */
    '    HLLPARAMS, NEAR * NPHLLPARAMS, FAR * LPHLLPARAMS;
    End Type  
    
    And then HOW does one Port this??
    
    typedef struct tagSessions {
        char    cPSID;
        char    szLongName [8];
        Byte    byState;
                /******************************************
                Bit 0:  configured?         Bit 1:  opened?
                Bit 2:  powered?
                *******************************************/
        Word    wPSSize;
        }       SESSIONS, NEAR * NPSESSIONS, FAR * LPSESSIONS;
    
    typedef struct tagSessionStatus {
        char    cPSID;  /*  session short Name  */
        char    szLongName [8];
        Word    bType;   /*  FALSE = CUT;    TRUE = DFT   */
        Byte    byCharacteristics;
                /*****************************************************
                Bit 0: EABs? Y/N        Bit 1: Programmed Symbols Y/N
                *****************************************************/
        Byte    byUsage;
                /****************************************************
                Bit 0: Configured? Y/N  Bit 1: Opened? Y/N
                Bit 2: Powered? Y/N     Bit 3: AutoPowered? Y/N
                Bit 4: Emulated? Y/N    Bit 5: HLLAPI-Connected? Y/N
                Bit 6: FileTrans? Y/N
                ****************************************************/
                /******************************************************************
                note that Bit 5, HLLAPI-Connected, may be either HLLWin connection,
                HLLWin keystroke interception, Or HLLWin-initiated file transfer
                *******************************************************************/
    
        Word    wRows;
        Word    wColumns;
        }       SESSIONSTATUS, NEAR * NPSESSIONSTATUS, FAR * LPSESSIONSTATUS;

    -------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    Scott,

    I am by no means a "C" expert but the char type caught my eye.

    From Developer help file:

    Type char
    The char type is used to store the integer value of a member of the representable character set. That integer value is the ASCII code corresponding to the specified character.

    Microsoft Specific —>

    Character values of type unsigned char have a range from 0 to 0xFF hexadecimal. A signed char has range 0x80 to 0x7F. These ranges translate to 0 to 255 decimal, and –128 to +127 decimal, respectively. The /J compiler option changes the default from signed to unsigned.

    END Microsoft Specific

    Next:

    BOOL Boolean variable (should be TRUE or FALSE). IE for PB this should be a LONG.

    Next:
    Type for String Literals
    String literals have type array of char (that is, char[ ]). (Wide-character strings have type array of wchar_t (that is, wchar_t[ ]).) This means that a string is an array with elements of type char. The number of elements in the array is equal to the number of characters in the string plus one for the terminating null character.

    Hope this helps some.

    Cecil


    ------------------


    [This message has been edited by Cecil Williams (edited April 12, 2000).]

    Comment


    • #3
      So for PB Sake, signed or unsigned a LONG should take care of it since I am going to be considering 0 - 255????
      I would logically assume so, but I could be wrong.
      And to get the char from it, I would chr$(value)...


      Or is it that simple?


      Scott

      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        Scott,

        Sounds like a plan to me. I presume that these structures are filled by a corresponding function call. See the last edit to my previous post for asciiz array of "char" type for strings.

        You could just use the ascii value direct!!!!!!

        Cecil

        ------------------

        Comment


        • #5
          An important thing to remember is that the structures must line up exactly.

          BOOL is a 2 byte INTEGER.

          A single char could be changed with a BYTE, but its better to use a STRING * 1

          char szLongName [8];
          This would be an 8 byte ASCIIZ with only 7 spaces available to use. Again, you could use: szLongName(1 to 8) as BYTE



          ------------------

          Comment


          • #6
            About type names-- When you see something in C like this:
            Code:
            typedef struct tagATMSystem {
            ...
            } ATMSYSTEM;
            the best translation into a PB type is like this:
            Code:
            TYPE ATMSYSTEM
            ...
            END TYPE
            I'm not sure what that byplay was about a LONG being ok for a value from 0-255. If you mean, is it ok to translate a "char" to a "LONG", no-- these are different-size values. A "char" should translate as either a "STRING * 1" or as a "BYTE", depending on whether you want to consider it as a string or a numeric value.

            Enoch, BOOL is not a 2-byte integer, unless you're porting from 16-bit C code. With 32-bit C, the "integer" and "BOOL" types translate to a PowerBASIC "LONG" (a 4-byte integer type).

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

            Comment


            • #7
              Tom, you are correct. Sortof. Looks like we're both off
              In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int. In Visual C++ 5.0 and later, bool is implemented as a built-in type with a size of 1 byte. That means that for Visual C++ 4.2, a call of sizeof(bool) yields 4, while in Visual C++ 5.0 and later, the same call yields 1. This can cause memory corruption problems if you have defined structure members of type bool in Visual C++ 4.2 and are mixing object files (OBJ) and/or DLLs built with the 4.2 and 5.0 or later compilers.
              VC6: sizeof(bool) returns 1


              ------------------

              Comment


              • #8
                Tom, that name rings a bell...
                Years ago you wrote an ANSI emulation piece?
                Perhaps it was related to ULTRA Shell, I forget...

                A char in C is ONE character, a Char[22] is asciiz * 22 or is it a String * 22

                Tags are all removed


                Thanks for everyone's input, hopefully I can get this thing converted....

                Scott

                ------------------
                Scott
                mailto:[email protected][email protected]</A>

                [This message has been edited by Scott Turchin (edited April 12, 2000).]
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment


                • #9
                  Enoch:
                  It's important to keep in mind that C is case sensitive. The BOOL type employed by the Windows APIs is a typedef for a long integer. The "bool" type that's intrinsic to some versions of Microsoft C is a completely different type!

                  Scott:
                  Yes, I wrote the ZANSI device driver, and a number of ANSI emulators for various BASICs and other languages. UltraShell isn't one of mine, but I did write PBWiz which, like UltraShell, is now sold by Information Management Systems.

                  The interpretation of char[22] is best made according to how the value is used. If it's a C string buffer, the typical translation would be ASCIIZ * 22. It's not uncommon to see character buffers that aren't "full" C strings, in the sense that they're not NUL-terminated. In that case, the translation would be better as STRING * 22. Finally, sometimes char[xx] is just used to specify a block of some number of bytes, in which case it might be suitable to translate it as vbl(0 TO 21) AS BYTE.

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

                  Comment


                  • #10
                    Uh..oops


                    ------------------

                    Comment


                    • #11
                      Now I remember, Information Systems has it, but they also have Ultra-Shell I think...
                      I recall learning from that example, and even found a minor bug in it and fixed it *Grin*, that was egads, YEARS ago...
                      Actually I ported it over to PB/CC and wrote a viewer for ansi files, but since the internet is here, nobody uses them anymore


                      Anyway, I understand where we're at on the porting, which is what I did and it works !! ;0


                      Thanks everyone!

                      Scott

                      ------------------
                      Scott
                      mailto:[email protected][email protected]</A>
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment

                      Working...
                      X