Announcement

Collapse
No announcement yet.

Code Doesn't Compile - pointer "@" syntax error

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

  • Code Doesn't Compile - pointer "@" syntax error

    I retrieved the following from the Source Code forum and found that it doesn't compile in PBWin 7.04 and later, but does compile in PBDLL 6.1.

    It's some code by Florent Heyworth for DNS Query.
    http://powerbasic.com/support/pbforu...ht=DNS+RECORDS

    The problem code uses pointers and any line containing

    @[email protected]@h_list

    triggers a compiler syntax error at the "@@".

    I have never used pointers and am not familiar with what changes occurred in the allowed syntax for their use. Could someone help me please? I would like to get the code to compile.

    Thanks,

    David
    Last edited by David Gwillim; 16 Oct 2007, 08:59 PM.
    David Gwillim
    Noesis Corporation, NY

    noesisdgatverizondotnet

    GAIA - the Mother of us all
    Isaac Asimov's Gaia

  • #2
    OK I did a bit more digging and it seems that the definition for the structure TYPE hostentStru in wsock32.inc changed from this in PB/DLL 6.1:
    Code:
    TYPE hostentStru
      h_name     AS ASCIIZ PTR
      h_alias    AS ASCIIZ PTR
      h_addr     AS INTEGER
      h_len      AS INTEGER
      h_list     AS LONG PTR
    END TYPE
    to this in PBwin 7.04 and later
    Code:
    TYPE hostentStru
        h_name  AS ASCIIZ PTR   ' official name of host
        h_alias AS DWORD        ' alias list (pointer to ASCIIZ PTR list)
        h_addr  AS INTEGER      ' host address type
        h_len   AS INTEGER      ' length of address
        h_list  AS DWORD        ' list of addresses (pointer to ASCIIZ PTR list)
    END TYPE
    Now how do I restructure the code in Florent's DNS Query program to match the new structure definition?

    David
    David Gwillim
    Noesis Corporation, NY

    noesisdgatverizondotnet

    GAIA - the Mother of us all
    Isaac Asimov's Gaia

    Comment


    • #3
      As an immediate work around I simply created the same hostentStru I found in the wsock32.inc for PB/DLL 6.1 with a change for the name of the structure.

      Code:
      TYPE hostentStru2
        h_name     AS ASCIIZ PTR
        h_alias    AS ASCIIZ PTR
        h_addr     AS INTEGER
        h_len      AS INTEGER
        h_list     AS LONG PTR
      END TYPE
      I then went through the source and replaced hostentStru with hostentStru2 in all the DIMs. Now Florent's DNS Query compiles and runs just fine.

      I do wish though that I understood why the structure in wsock32.inc was changed. I also wish I had more experience with pointers.

      David
      Last edited by David Gwillim; 16 Oct 2007, 11:02 PM.
      David Gwillim
      Noesis Corporation, NY

      noesisdgatverizondotnet

      GAIA - the Mother of us all
      Isaac Asimov's Gaia

      Comment


      • #4
        > do wish though that I understood why the structure in wsock32.inc was changed

        That would be PwerBASIC Inc's Windows' Header Information Management system.

        aka "WHIM"

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

        Comment


        • #5
          Pointer Examples

          Maybe this will help David...

          C To PowerBASIC Pointer Conversions
          http://www.powerbasic.com/support/pb...light=Pointers

          Pointers, Dynamic Memory Allocation, and Instance Data
          http://www.jose.it-berater.org/smffo...p?topic=1292.0

          They include real short programs along with output showing how to get started with pointers.
          Fred
          "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

          Comment


          • #6
            Thanks for the references Fred. I took a brief look and will have to return to them later on a more studied level.

            David
            David Gwillim
            Noesis Corporation, NY

            noesisdgatverizondotnet

            GAIA - the Mother of us all
            Isaac Asimov's Gaia

            Comment


            • #7
              Seem's that the newer HostEntStru definition is more appropriate
              becose h_alias is an array of pointers to aliasses names, in fact it's Microsoft way.

              It would be appreciated if anybody can test the following code
              with a host that have one or many aliasses names and give feedback
              so we can know if code is valid or need corection...

              Code:
              #COMPILE EXE '#Win 8.04# 
              #DIM ALL
              #INCLUDE "WIN32API.INC" '#2005-01-27#
              #INCLUDE "WSOCK32.INC"
               
              TYPE HostEntStru 'PowerBASIC 7+ definition
                h_name  AS ASCIIZ PTR  'Official name of the host
                h_alias AS DWORD       'A NULL-terminated array of alternate names.
                h_addr  AS INTEGER     'The type of address being returned.
                h_len   AS INTEGER     'The length, in bytes, of each address.
                h_list  AS DWORD       'A NULL-terminated list of addresses for the host.
              END TYPE
               
              %MAX_HostName_LEN = 128
              '______________________________________________________________________________
               
              FUNCTION AddrTypeString(AddrType AS INTEGER)AS STRING
               
               SELECT CASE AddrType
                 CASE %AF_UNSPEC       : FUNCTION = "AF_UNSPEC"       ' 0       unspecified
                 CASE %AF_UNIX         : FUNCTION = "AF_UNIX"         ' 1       local to host (pipes, portals)
                 CASE %AF_INET         : FUNCTION = "AF_INET"         ' 2       internetwork: UDP, TCP, etc.
                 CASE %AF_IMPLINK      : FUNCTION = "AF_IMPLINK"      ' 3       arpanet imp addresses
                 CASE %AF_PUP          : FUNCTION = "AF_PUP"          ' 4       pup protocols: e.g. BSP
                 CASE %AF_CHAOS        : FUNCTION = "AF_CHAOS"        ' 5       mit CHAOS protocols
                 CASE %AF_IPX, %AF_NS  : FUNCTION = "F_IPX - AF_NS"   ' 6       IPX and SPX, XEROX NS protocols
                 CASE %AF_ISO, %AF_OSI : FUNCTION = "AF_ISO - AF_OSI" ' 7       ISO protocols
                 CASE %AF_ECMA         : FUNCTION = "AF_ECMA"         ' 8       european computer manufacturers
                 CASE %AF_DATAKIT      : FUNCTION = "AF_DATAKIT"      ' 9       datakit protocols
                 CASE %AF_CCITT        : FUNCTION = "AF_CCITT"        '10       CCITT protocols, X.25 etc
                 CASE %AF_SNA          : FUNCTION = "AF_SNA"          '11       IBM SNA
                 CASE %AF_DECnet       : FUNCTION = "AF_DECnet"       '12       DECnet
                 CASE %AF_DLI          : FUNCTION = "AF_DLI"          '13       Direct data link interface
                 CASE %AF_LAT          : FUNCTION = "AF_LAT"          '14       LAT
                 CASE %AF_HYLINK       : FUNCTION = "AF_HYLINK"       '15       NSC Hyperchannel
                 CASE %AF_APPLETALK    : FUNCTION = "AF_APPLETALK"    '16       AppleTalk
                 CASE %AF_NETBIOS      : FUNCTION = "AF_NETBIOS"      '17       NetBios-style addresses
               END SELECT
               
              END FUNCTION
              '______________________________________________________________________________
               
              FUNCTION PBMAIN()
               LOCAL sBuffer           AS STRING
               LOCAL WinSock           AS WsaData
               LOCAL HostName          AS ASCIIZ * %MAX_HostName_LEN
               LOCAL HostEntry         AS HostEntStru PTR
               LOCAL ipPointer         AS ASCIIZ PTR
               LOCAL AliasPointer      AS ASCIIZ PTR
               LOCAL ListArrayPointer  AS DWORD POINTER
               LOCAL AliasArrayPointer AS DWORD POINTER
               LOCAL RetVal            AS LONG
               
               RetVal = WsaStartup(&H101, WinSock) 'Initiates Windows Sockets
               IF RetVal = %NOERROR THEN
               
                 HOST NAME TO HostName 'Set HostName to your machine name...
                 HostEntry = GetHostByName(HostName) 'Returns a pointer to the hostent structure
               
                 IF HostEntry THEN 'GetHostByName was successfull
               
                   sBuffer = "IP addresses assignement..." & $CRLF  & $CRLF
                   sBuffer = sBuffer & "Host name: " & @[email protected]_name & $CRLF
               
                   AliasArrayPointer = @HostEntry.h_alias 'We'll use AliasArrayPointer instead of .h_alias
                   DO WHILE @AliasArrayPointer 'If pointer is zero then no more data
                     AliasPointer = @AliasArrayPointer
                     sBuffer = sBuffer & "Alias: " & @AliasPointer & $CRLF
                     @AliasArrayPointer = @AliasArrayPointer + 4 '4 is dword lenght
                   LOOP
               
                   sBuffer = sBuffer & "Adress type: " & AddrTypeString(@HostEntry.h_addr) & $CRLF
               
                   sBuffer = sBuffer & "Adress lenght:" & STR$(@HostEntry.h_len) & $CRLF & $CRLF
               
                   ListArrayPointer = @HostEntry.h_list 'We'll use ListArrayPointer instead of .h_list
                   DO WHILE @@ListArrayPointer 'If pointer is zero then no more data
                     ipPointer = inet_ntoa(@@ListArrayPointer) 'Converts network address into a dotted string
                     sBuffer = sBuffer & "ip : " & @ipPointer & $CRLF
                     @ListArrayPointer = @ListArrayPointer + @HostEntry.h_len 'Move to next entry
                   LOOP
               
                   WSACleanup
                   MessageBox %HWND_DESKTOP, BYCOPY sBuffer, "GetHostByName", 64
               
                 END IF
               END IF
               
              END FUNCTION
              '______________________________________________________________________________

              Comment


              • #8
                Pierre,

                Thanks for taking a look at this HostEntStru TYPE change. I am always eager to learn something new.

                Trying "google.com" as the hostname in your code, it generates Google's three IP addresses, the same ones as are reported by the Window's command line utility NSLOOKUP. IP addresses beyond the 3rd are garbage in memory I guess.

                David
                Last edited by David Gwillim; 18 Oct 2007, 06:47 AM.
                David Gwillim
                Noesis Corporation, NY

                noesisdgatverizondotnet

                GAIA - the Mother of us all
                Isaac Asimov's Gaia

                Comment

                Working...
                X