Liberty BASIC Help Online

STRUCT name, field1 as type1 [, field2 as type2, ... ]
This statement builds an single instance of a specified structure thatis required when making some kinds of API/DLL calls.  This does not declare a type of structure, but it creates a single structure.
Here is an example STRUCT statement that builds a Windows rect structure, used in many Windows API calls:
    'create the structure winRect
    struct winRect, _
        orgX as long, _
        orgY as long, _
        extentX as long, _
        extentY as long
A value is assigned to a field of a structure in a similar way to variable assignements. The name of the struct is used first. followed by a dot, then by the name of the field being accessed, then by another dot, and last by the word "struct."  This example assigns a value of "100" to the "orgX" field of the struct "winRect":
    winRect.orgX.struct = 100
The structure's fields may be used in the same manner as any other variable:
    print winRect.orgX.struct
   newOriginX = offsetX + winRect.orgX.struct
Some API calls require the size of a struct to be passed as a parameter.  Determine the length (size) of a struct with the LEN() function.
      sizeStruct = len(winRect.struct)
When passing a structure in a CALLDLL statement, specify type "as struct", as is done in this example:
  'WINRECT.BAS - show how to get window position and size
  'and demonstrate how to use the struct statement
  struct winRect, _
      orgX as long, _
      orgY as long, _
      crnrX as long, _
      crnrY as long
  open "test me" for window as #win
  open "user32.dll" for dll as #user
  hndl =  hwnd(#win)
  calldll #user, "GetWindowRect", _
      hndl as ulong, _
      winRect as struct, _
      result as long
  print "Upper Left x, y of 'test me': "
  print winRect.orgX.struct; ", "; winRect.orgY.struct
  print "Lower Right x, y of 'test me': "
  print winRect.crnrX.struct; ", "; winRect.crnrY.struct
  close #user
  close #win
See also:  CALLDLL, Using Types with STRUCT, Understanding Syntax

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -