Announcement

Collapse
No announcement yet.

translate C enum to PowerBasic

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

  • translate C enum to PowerBasic

    How would one translate this C code below to PowerBasic? I guess I should convert them to constants but I'm not sure if and with what value.


    typedef enum {
    CRYPT_SESSION_NONE, /* No session type */
    CRYPT_SESSION_SSH, /* SSH */
    CRYPT_SESSION_SSH_SERVER, /* SSH server */
    CRYPT_SESSION_SSL, /* SSL/TLS */
    CRYPT_SESSION_SSL_SERVER, /* SSL/TLS server */
    CRYPT_SESSION_OCSP, /* OCSP */
    CRYPT_SESSION_OCSP_SERVER, /* OCSP server */
    CRYPT_SESSION_TSP, /* TSP */
    CRYPT_SESSION_TSP_SERVER, /* TSP server */
    CRYPT_SESSION_CMP, /* PKIX CMP */
    CRYPT_SESSION_CMP_SERVER, /* PKIX CMP server */
    CRYPT_SESSION_LAST /* Last possible */
    } CRYPT_SESSION_TYPE;

  • #2
    Maurice,

    The baseline for a C/C++ enum is zero(0) unless otherwise
    specified. Thus, the first constant is = 0, next = 1 and so
    forth.

    Cheers,
    Cecil

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

    Comment


    • #3
      Thanks for the quick relpy.
      So I did that right, but still the call to a DLL gives a GPF.


      Originally the function is declared as:
      int cryptCreateSession(* int,
      const int,
      const CRYPT_SESSION_TYPE
      );

      and I translated this to

      DECLARE FUNCTION cryptCreateSession LIB "CL32.DLL" _
      ALIAS "cryptCreateSession"(Crypt_Session AS INTEGER, _
      BYVAL cryptUser AS INTEGER, BYVAL formatType AS INTEGER) AS INTEGER

      Do you think this is correct?
      Should the enum be passes as an integer?


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

      Comment


      • #4
        C integers should convert to longs.

        DECLARE FUNCTION cryptCreateSession CDECL LIB "CL32.DLL" _
        ALIAS "cryptCreateSession"(Crypt_Session AS LONG, _
        BYVAL cryptUser AS LONG, BYVAL formatType AS LONG) AS LONG

        The CDECL is needed if the C code uses C calling convention....
        (In case of don't know, try both)



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

        Comment


        • #5
          Thanks! It's working now!

          Now I can start porting the enums to constants, a hell of a job :-(

          I see that several enums are defined as follows:
          typedef enum {
          CRYPT_ATTRIBUTE_NONE,
          CRYPT_PROPERTY_FIRST,
          CRYPT_PROPERTY_HIGHSECURITY,
          CRYPT_OPTION_FIRST = 100,
          CRYPT_OPTION_INFO_DESCRIPTION,
          } CRYPT_ATTRIBUTE_TYPE;

          It it correct to translate this to:
          %CRYPT_ATTRIBUTE_NONE = 0
          %CRYPT_PROPERTY_FIRST = 1
          %CRYPT_PROPERTY_HIGHSECURITY = 2
          %CRYPT_OPTION_FIRST = 100
          %CRYPT_OPTION_INFO_DESCRIPTION = 101


          ?



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

          Comment


          • #6
            Looks right to me.

            Just a thought, but to translate a lot of these enum blocks, it would probably be faster to write a small app that parses the file and does the conversion for you.

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

            Comment


            • #7
              I was thinking about that too Lance.

              But here's my RFC for a next update: introduce a enum type in powerbasic :-)

              Comment

              Working...
              X