Announcement

Collapse
No announcement yet.

What does this mean in C?

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

  • #41
    Other one:

    Code:
    static struct linebag {
      LINEDEV ldev;       /* GlobalCall API line device handle */
      CRN     crn;        /* GlobalCall API call handle */
      int     blocked;    /* channel blocked/unblocked */
      int     networkh;   /* network handle */
      int     voiceh;     /* voice handle */
    } port[20];
    As I understand correctly this defines a type named ' linebag ', and also creates a Global array named port (sized 20) of the Type linebag?
    (or am I wrong?)

    What is the (void *) doing before the parameter &port below?
    Code:
    if (gc_OpenEx(&port[port_index].ldev, devname, EV_SYNC, (void *)&port[port_index]) != GC_SUCCESS) {
    Regards,
    Peter

    Comment


    • #42
      Originally posted by Peter Lameijn View Post
      Other one:

      Code:
      static struct linebag {
      LINEDEV ldev; /* GlobalCall API line device handle */
      CRN crn; /* GlobalCall API call handle */
      int blocked; /* channel blocked/unblocked */
      int networkh; /* network handle */
      int voiceh; /* voice handle */
      } port[20];
      As I understand correctly this defines a type named ' linebag ', and also creates a Global array named port (sized 20) of the Type linebag?
      (or am I wrong?)

      What is the (void *) doing before the parameter &port below?
      Code:
      if (gc_OpenEx(&port[port_index].ldev, devname, EV_SYNC, (void *)&port[port_index]) != GC_SUCCESS) {
      A pointer of type void.
      Specifically, a specific cast to type void.
      port[port_index] is a member of an array.
      The ampersand identifies it as a reference, and the preceding parenthesis casts it to type.
      The world is strange and wonderful.*
      I reserve the right to be horrifically wrong.
      Please maintain a safe following distance.
      *wonderful sold separately.

      Comment


      • #43
        Thanks,

        How should a pointer to a pointer as parameter for a function be translated in PB. Something like this?:

        Code:
         int gc_AlarmName(METAEVENT *metaeventp, char **alarm_name)
        Code:
         Declare Function gc_AlarmName Lib "LibGC.dll" Cdecl Alias "gc_AlarmName" (metaeventp As METAEVENT, alarm_name As Dword ) As Long
        Regards,
        Peter

        Comment


        • #44
          Let say alarm_name is an asciiz ...
          LOCAL alarm_name AS ASCIIZ POINTER
          And access it with double "@", aka @@alarm_name

          Comment


          • #45
            It's a Dialogic DLL, so I have no influence in how it's handled internally...
            Regards,
            Peter

            Comment


            • #46
              Can you elaborate your thought?

              If you get a pointer to a pointer, @@ will do...

              Code:
               
              DECLARE FUNCTION gc_AlarmName(BYREF metaeventp AS LONG, BYREF ppz AS DWORD)AS DWORD
              
              '_____________________________________________________________________________
              
              FUNCTION gc_AlarmName(BYREF metaeventp AS LONG, BYREF ppz AS DWORD)AS DWORD
               STATIC z  AS ASCIIZ * 4
               STATIC pz AS DWORD
              
               z   = "ABC"
               pz  = VARPTR(z)
               ppz = VARPTR(pz)
              
              END FUNCTION
              '_____________________________________________________________________________
              
              FUNCTION PBMAIN() AS LONG
               LOCAL ppValue AS ASCIIZ POINTER
              
               gc_AlarmName(0, ppValue)
               ? "0x" & HEX$(ppValue)
               ? "0x" & HEX$(PEEK(DWORD, ppValue))
               ? @@ppValue
              
              END FUNCTION
              '_____________________________________________________________________________
              '

              Comment


              • #47
                gc_alarmname is a function inside a third party 'C' dll ...
                Regards,
                Peter

                Comment


                • #48
                  Yes I know... Intel Dialogic.
                  Based on the example above, did you try...

                  Code:
                  DECLARE FUNCTION gc_AlarmName LIB "LibGC.dll" CDECL ALIAS "gc_AlarmName"(BYREF metaeventp AS METAEVENT, BYREF alarm_name AS DWORD) AS LONG
                  
                  LOCAL RetVal     AS LONG
                  LOCAL metaeventp AS METAEVENT
                  LOCAL alarm_name AS ASCIIZ POINTER
                  
                  RetVal = gc_AlarmName(metaeventp, alarm_name)
                  ? @@alarm_name

                  Comment


                  • #49
                    Reading the original definition from Intel again, I think that this will be better...

                    Code:
                    DECLARE FUNCTION gc_AlarmName LIB "LibGC.dll" CDECL ALIAS "gc_AlarmName"(BYREF metaeventp AS METAEVENT, BYREF alarm_name AS DWORD) AS LONG
                    
                    LOCAL RetVal     AS LONG
                    LOCAL metaeventp AS METAEVENT
                    LOCAL alarm_name AS ASCIIZ POINTER
                    
                    RetVal = gc_AlarmName(metaeventp, alarm_name)
                    ? @alarm_name

                    Comment


                    • #50
                      So that's the same as my original post...
                      (I always omit ByRef to keep things short, a lot of varname and equates are horribly long, and the default passing is ByRef)
                      Example of a crazy long equate they used:
                      Code:
                      %IPEC_Q931Cause70OnlyRestrictedDigitalInformationBearerCapabilityIsAvailable = 3070
                      I thought that equates were there to make things easier, not harder...
                      Regards,
                      Peter

                      Comment


                      • #51
                        What does this mean? (why the brackets around the structure name?)

                        Code:
                            gclib_makecallp = (GCLIB_MAKECALL_BLKP)
                        Regards,
                        Peter

                        Comment


                        • #52
                          Solved that... But another question.
                          In the code below, both Util_Insert functions need a double pointer (**); the other 2 functions need a 'normal' pointer to the same data.
                          How should I translate that? (are the function declares correct?)

                          Code:
                          C Declares:
                          
                          int  GC_CDECL gc_util_insert_parm_ref(GC_PARM_BLKP *parm_blkpp, unsigned short setID, unsigned short parmID, unsigned char data_size, void *datap);
                          int  GC_CDECL gc_util_insert_parm_val(GC_PARM_BLKP *parm_blkpp, unsigned short setID, unsigned short parmID, unsigned char data_size, unsigned long data);
                          int  GC_CDECL gc_SetUserInfo(int target_type, long target_id, GC_PARM_BLKP infoparmblkp, int duration);
                          void GC_CDECL gc_util_delete_parm_blk(GC_PARM_BLKP parm_blk);
                          
                          '--------------------------------------------------------------------------------------------------------------------------------
                          C Code:
                          
                              int                        scope;
                              IP_CAPABILITY            ipcap;
                              GC_PARM_BLK                *parmblkp = NULL;
                              char                    str[MAX_STRING_SIZE];
                          
                              /* append the GC_PARM_BLK with the respective TX codec */
                              gc_util_insert_parm_ref(&parmblkp, GCSET_CHAN_CAPABILITY, IPPARM_LOCAL_CAPABILITY, sizeof(IP_CAPABILITY), &ipcap);
                          
                              /* append the GC_PARM_BLK with the respective RX codec */
                              gc_util_insert_parm_ref(&parmblkp, GCSET_CHAN_CAPABILITY, IPPARM_LOCAL_CAPABILITY, sizeof(IP_CAPABILITY), &ipcap);
                          
                              scope = GC_SINGLECALL;
                              gc_SetUserInfo(GCTGT_GCLIB_CHAN, port[index].ldev, parmblkp, scope)
                          
                               gc_util_delete_parm_blk(parmblkp);
                          
                          '--------------------------------------------------------------------------------------------------------------------------------
                          Basic declares:
                          
                          Declare Function gc_util_insert_parm_ref Lib "LibGC.dll" Cdecl Alias "gc_util_insert_parm_ref" (parm_blkp As DWord, Byval setID As Word, Byval parmID As Word, Byval data_size As Byte, datap As Any) As Long
                          Declare Function gc_util_insert_parm_val Lib "LibGC.dll" Cdecl Alias "gc_util_insert_parm_val" (parm_blkp As DWord, Byval setID As Word, Byval parmID As Word, Byval data_size As Byte, Byval pdData As long ) As Long
                          Declare Function gc_SetUserInfo Lib "LibGC.dll" Cdecl Alias "gc_SetUserInfo" (Byval target_type As long, Byval target_id As Long, infoparmblkp As Any, Byval duration As Long) As Long
                          Declare Sub      gc_util_delete_parm_blk Lib "LibGC.dll" Cdecl Alias "gc_util_delete_parm_blk" (parm_blk As Any)
                          Regards,
                          Peter

                          Comment


                          • #53
                            Found that after long search:
                            gc_setuserinfo() needed infoparmblkp passed as @infoparmblkp to work...

                            Other question, are these the same?: (both giving 0x3001 as result?)
                            Code:
                            %DXXEV_BASE = 0x3000 'Beginning base value
                            
                            %TDX_RESET           (DXXEV_BASE | = 0x01)
                            %TDX_RESET           (DXXEV_BASE | 0x01)
                            and what does this do?:
                            Code:
                            #define dl_devmodel(i)  ((i) & = &h000FF)
                            Regards,
                            Peter

                            Comment


                            • #54
                              Originally posted by Peter Lameijn View Post
                              Found that after long search:
                              gc_setuserinfo() needed infoparmblkp passed as @infoparmblkp to work...

                              Other question, are these the same?: (both giving 0x3001 as result?)
                              Code:
                              %DXXEV_BASE = 0x3000 'Beginning base value
                              
                              %TDX_RESET (DXXEV_BASE | = 0x01)
                              %TDX_RESET (DXXEV_BASE | 0x01)
                              and what does this do?:
                              Code:
                              #define dl_devmodel(i) ((i) & = &h000FF)
                              The | means OR.
                              As to the other, "In the C Programming Language, the #define directive allows the definition of macros within your source code."
                              So, it is a macro to perform a logical AND 255.
                              Code:
                              MACRO dl_devmodel(i)= i AND= &h000FF
                              The world is strange and wonderful.*
                              I reserve the right to be horrifically wrong.
                              Please maintain a safe following distance.
                              *wonderful sold separately.

                              Comment


                              • #55
                                Thanks,

                                I knew that "|" is "Or", but what does the extra "=" do? (is "|" the same as "|=" ? _
                                Regards,
                                Peter

                                Comment


                                • #56
                                  Originally posted by Peter Lameijn View Post
                                  Thanks,

                                  I knew that "|" is "Or", but what does the extra "=" do? (is "|" the same as "|=" ? _
                                  |= is similar to +=

                                  x +=3 is the same as x = x +3

                                  Similarly, X |= 8 in PB would be X OR= 8 which is the same as X = X OR 8

                                  Comment


                                  • #57
                                    Another one...

                                    Code:
                                    if ( gc_util_copy_parm_blk( &my_blkp, (GC_PARM_BLKP)(metaevent.extevtdatap))!= GC_SUCCESS)
                                    It's a call to gc_util_copy_parm_blk() and tests for GC_SUCCES, that's clear to me.
                                    The function takes 2 parameters: what does the second one mean?
                                    Code:
                                    (GC_PARM_BLKP)(metaevent.extevtdatap)
                                    Two variables as one parameter? (GC_PARM_BLKP and metaevent.extevtdatap are both pointers...)

                                    Regards,
                                    Peter

                                    Comment


                                    • #58
                                      There is only one parameter,
                                      GC_PARM_BLKP is a pointer to a GC_PARM_BLK structure
                                      gc_util_copy_parm_blk expect this type as second parameter and in the code,
                                      it is feeded with a METAEVENT element as metaevent.extevtdatap.
                                      So to avoid the compiler to complain about a bad type, you cast it,
                                      telling the compiler to treat etaevent.extevtdatap as if it where a GC_PARM_BLKP type variable.

                                      Comment


                                      • #59
                                        Originally posted by Pierre Bellisle View Post
                                        There is only one parameter,
                                        GC_PARM_BLKP is a pointer to a GC_PARM_BLK structure
                                        gc_util_copy_parm_blk expect this type as second parameter and in the code,
                                        it is feeded with a METAEVENT element as metaevent.extevtdatap.
                                        So to avoid the compiler to complain about a bad type, you cast it,
                                        telling the compiler to treat etaevent.extevtdatap as if it where a GC_PARM_BLKP type variable.
                                        Yup. Explicit cast to type.
                                        The world is strange and wonderful.*
                                        I reserve the right to be horrifically wrong.
                                        Please maintain a safe following distance.
                                        *wonderful sold separately.

                                        Comment


                                        • #60
                                          I'm now troubled by this IP_VIRTBOARD structure. Is my translation correct? (the E_xxx members are ENUM's, I translated them to Longs)
                                          The function receiving the structure fails, if the length of the structure is incorrect, I can understand it...

                                          Code:
                                          '--------------------------------------------------------------------------------------------------
                                          TYPE MIME_MEM
                                            Version           AS WORD         'library use only. do not change value
                                            Size              AS DWORD        'size of MIME buffer
                                            Number            AS DWORD        'number of MIME buffer
                                          END TYPE
                                          
                                              typedef struct
                                              {
                                                 unsigned short  version;              /* library use only. do not change value */
                                                 unsigned int    size;                 /* size of MIME buffer */
                                                 unsigned int    number;               /* number of MIME buffer */
                                              } MIME_MEM;
                                          
                                          '--------------------------------------------------------------------------------------------------
                                          UNION U_IPADDR
                                            IpV4      AS DWORD
                                            IpV6(3)   AS DWORD
                                          END UNION
                                          
                                          TYPE IP_ADDR
                                            ip_ver            AS BYTE
                                            U_IPADDR
                                          END TYPE
                                          
                                              typedef struct
                                              {
                                                  unsigned char ip_ver;
                                                  union
                                                  {
                                                      unsigned int ipv4;
                                                      unsigned int ipv6[4];
                                                  } u_ipaddr;
                                              } IP_ADDR, *IP_ADDRP;
                                          
                                          '--------------------------------------------------------------------------------------------------
                                          TYPE IP_VIRTBOARD
                                            Version                               AS WORD                     'library use only. don't change
                                            Total_max_calls                       AS DWORD
                                            h323_max_calls                        AS DWORD
                                            sip_max_calls                         AS DWORD
                                            localIP                               AS IP_ADDR
                                            h323_signaling_port                   AS WORD
                                            sip_signaling_port                    AS WORD
                                            reserved                              AS DWORD                    'library use only. don't change
                                            size                                  AS WORD                     'library use only. don't change
                                            sip_msginfo_mask                      AS DWORD                    'added in version 0x0101
                                            sup_serv_mask                         AS DWORD                    'added in version 0x0102
                                            h323_msginfo_mask                     AS DWORD                    'added in version 0x0103
                                            sip_mime_mem                          AS MIME_MEM                 'added in version 0x0104
                                            terminal_type                         AS WORD                     'added in version 0x0104
                                            outbound_proxy_IP                     AS IP_ADDR                  'added in version 0x0105
                                            outbound_proxy_port                   AS WORD                     'added in version 0x0105
                                            outbound_proxy_hostname               AS Asciiz PTR               'added in version 0x0105
                                            E_SIP_tcpenabled                      AS LONG                     'EnumSIP_Enabled
                                            E_SIP_OutboundProxyTransport          AS LONG                     'EnumSIP_TransportProtocol
                                            E_SIP_Persistence                     AS LONG                     'EnumSIP_Persistence
                                            SIP_maxUDPmsgLen                      AS WORD
                                            E_SIP_DefaultTransport                AS LONG                     'EnumSIP_TransportProtocol
                                            E_SIP_RequestRetry                    AS LONG                     'EnumSIP_RequestRetry
                                            E_SIP_OPTIONS_Access                  AS LONG                     'EnumSIP_Enabled
                                            SIP_registrar_registrations           AS LONG
                                            sip_tls_engine                        AS SIP_TLS_ENGINE PTR
                                            E_SIP_PrackEnabled                    AS LONG                     'EnumSIP_Enabled
                                            E_SIP_SessionTimer_Enabled            AS LONG                     'EnumSIP_Enabled
                                            SIP_SessionTimer_SessionExpires       AS DWORD
                                            SIP_SessionTimer_MinSE                AS DWORD
                                            sip_stack_cfg                         AS SIP_STACK_CFG PTR
                                            E_SIP_UPDATE_Access                   AS LONG                    
                                            E_SIP_dynamic_outbound_proxy_enabled  AS LONG                    
                                            E_SIP_IPv6                            AS LONG                    
                                            localIPv6                             AS IP_ADDR                  
                                            localIPv6_iface_name                  AS Asciiz PTR               'Local IP address (IPv6 Only)
                                            sip_max_subscription                  AS DWORD
                                            E_SIP_MESSAGE_Access                  AS LONG                    
                                            E_SIP_OOD_NOTIFY_Access               AS LONG                    
                                            E_SIP_Add_rport_to_Via_Header         AS LONG                    
                                            E_SIP_PreConditions_Enabled           AS LONG                    
                                            E_SIP_Overlapped_INFO_Enabled         AS LONG                    
                                            E_SIP_GetUnregisteredHdrs_Enabled     AS LONG                    
                                          END TYPE
                                          
                                              typedef struct {
                                                  unsigned short              version;                    /* library use only. don't change*/
                                                  unsigned int                total_max_calls;
                                                  unsigned int                h323_max_calls;
                                                  unsigned int                sip_max_calls;
                                                  IP_ADDR                     localIP;
                                                  unsigned short              h323_signaling_port;
                                                  unsigned short              sip_signaling_port;
                                                  void                        *reserved;                  /* library use only.do not change*/
                                                  unsigned short              size;                       /* library use only.do not change*/
                                                  unsigned int                sip_msginfo_mask;           /* added in version 0x0101       */
                                                  unsigned int                sup_serv_mask;              /* added in version 0x0102       */
                                                  unsigned int                h323_msginfo_mask;          /* added in version 0x0103       */
                                                  MIME_MEM                    sip_mime_mem;               /* added in version 0x0104       */
                                                  unsigned short              terminal_type;              /* added in version 0x0104       */
                                                  IP_ADDR                     outbound_proxy_IP;          /* added in version 0x0105 */
                                                  unsigned short              outbound_proxy_port;        /* added in version 0x0105 */
                                                  char*                       outbound_proxy_hostname;    /* added in version 0x0105 */
                                                  EnumSIP_Enabled             E_SIP_tcpenabled;
                                                  EnumSIP_TransportProtocol   E_SIP_OutboundProxyTransport;
                                                  EnumSIP_Persistence         E_SIP_Persistence;
                                                  unsigned short              SIP_maxUDPmsgLen;
                                                  EnumSIP_TransportProtocol   E_SIP_DefaultTransport;
                                                  EnumSIP_RequestRetry        E_SIP_RequestRetry;
                                                  EnumSIP_Enabled             E_SIP_OPTIONS_Access;
                                                  int                         SIP_registrar_registrations;
                                                  SIP_TLS_ENGINE              *sip_tls_engine;
                                                  EnumSIP_Enabled             E_SIP_PrackEnabled;
                                                  EnumSIP_Enabled             E_SIP_SessionTimer_Enabled;
                                                  unsigned int                SIP_SessionTimer_SessionExpires;
                                                  unsigned int                SIP_SessionTimer_MinSE;
                                                  SIP_STACK_CFG               *sip_stack_cfg;
                                                  EnumSIP_Enabled             E_SIP_UPDATE_Access;
                                                  EnumSIP_Enabled             E_SIP_dynamic_outbound_proxy_enabled;
                                                  EnumSIP_Enabled             E_SIP_IPv6;                 /* Enable IPv6 Support */
                                                  IP_ADDR                     localIPv6;                  /* Local IP Address for IPv6 */
                                                  char*                       localIPv6_iface_name;       /* Name local IP address  */
                                                  unsigned int                sip_max_subscription;
                                                  EnumSIP_Enabled             E_SIP_MESSAGE_Access;       /* FR6192 SIP MSG  support */
                                                  EnumSIP_Enabled             E_SIP_OOD_NOTIFY_Access;    /* FR6280 SIP out of dlg support */
                                                  EnumSIP_Enabled             E_SIP_Add_rport_to_Via_Header;      /* FR6234 - rport support*/
                                                  EnumSIP_Enabled             E_SIP_PreConditions_Enabled;        /* XMS-1773 */
                                                  EnumSIP_Enabled             E_SIP_Overlapped_INFO_Enabled;      /* XMS-3174 */
                                                  EnumSIP_Enabled             E_SIP_GetUnregisteredHdrs_Enabled;  /* XMS-3858 */
                                              } IP_VIRTBOARD;
                                          
                                          '--------------------------------------------------------------------------------------------------
                                          Regards,
                                          Peter

                                          Comment

                                          Working...
                                          X