Announcement

Collapse
No announcement yet.

a C to PB type conversion

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

  • a C to PB type conversion

    I am working on trying to make a Eudora plug-in. I'm still not familiar with C at all. here is a structure that I think I have figured out after doing some research.

    C++ Type
    Code:
    /* ----- MIME Params ---------------------------- */
    typedef struct emsMIMEparamS FAR*emsMIMEParamP;
    typedef struct emsMIMEparamS {
        long			size;
        LPSTR			name;			/* Mime parameter name (e.g., charset) */
        LPSTR			value;			/* param value (e.g. us-ascii) */
        emsMIMEParamP  	next;			/* Linked list of parameters */
    } emsMIMEparam;
    I believe this translates to:

    Code:
    TYPE emsMIMEparamS DWORD 
         lSize AS LONG
         apName AS ASCIIZ PTR
         apValue AS ASCIIZ PTR
         emsMIMEParamP AS emsMIMEparamS
    END TYPE
    But I am probably wrong. Can anyone kind of tell me what the C structure is saying?

    TIA

    Steve

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




    [This message has been edited by Steve Smith (edited April 05, 2004).]

  • #2
    As translated above, the last member would create a circular reference.

    In the Eudora doc's the last member appears to be a pointer, so the best translation of that member would likely be a DWORD:
    Code:
    TYPE emsMIMEparamS DWORD      
      lSize         AS LONG     
      apName        AS ASCIIZ PTR     
      apValue       AS ASCIIZ PTR     
      emsMIMEParamP AS DWORD
    END TYPE
    BTW, this structure is naturally DWORD-aligned, so you could omit the explicit DWORD alignment.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      >As translated above, the last member would create a circular reference

      And...????

      Code:
      ' circular.bas
      '
      TYPE  MyType
         Member1 AS LONG
         Member2 AS LONG
         pNext   AS myType PTR
      END TYPE
      
      FUNCTION PBMAIN () AS LONG
          LOCAL M() AS MyType, Z AS LONG
          
          REDIM M(5)
          
          FOR Z = 0 TO 5
             m(Z).member1 = Z
             IF Z <> 5 THEN
                 M(Z).pNext   =  VARPTR(m(Z+1))
             END IF
          NEXT
          
          LOCAL s AS STRING
          FOR Z = 0 TO 5
              s = S & USING$("Member ## Member1= ####  NextMember Member1 is ##", Z, M(Z).Member1,_
                  IIF (M(Z).pNext, m(Z)[email protected], 0)) & $CRLF
          NEXT
          
          MSGBOX S,,"Circular Reference Demo"
          
          
      END FUNCTION
      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        What Lance was trying to say is, you can't nest a UDT within itself,
        as the original example attempted. Of course, the final member should
        be a PTR to the UDT, here-- which is perfectly acceptable.

        By the way, Steve, the alignment should probably be DWORD FILL.

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

        Comment


        • #5
          Ok, I think I got it now. Maybe I should ask this first: has anyone ported any of the eudora sdk examples or includee file from c++ to PB? Just wanted to know before i spend some time trying to do it myself.

          steve

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

          Comment


          • #6
            I think I saw the "p" in the casting of the 'c' struct member 'next' and assumed it was a pointer to the next structure.. like a linked list.

            That's the way I'd convert it, anyway.. if I had to do it 'in a vacuum'

            MCM

            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment

            Working...
            X