Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - -> indirect structure member operator (binary) http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ->                  Indirect structure member operator (binary)
------------------------------------------------------------------------------
 Syntax
   pStruct->member

 Arguments
   pStruct is a pointer to a structure.

   member is a member name of the structure.

 Description
   The -> operator allows to indirectly reference a member of a
   structure, whose pointer is contained in the pStruct variable.
   The structure in question must have been declared in a typedef struct
   block, and the pStruct variable must be declared as of type
   ptr< <struct> ), where <struct> is the declared name of the structure
   type.

 Example
   #define EXAMPLE_OPERATOR
   #include example.hdr

   proc _VECTOR ptr
   
   typedef struct _PSP
      uint           int20
      uint           memend
      byte           reserved1
      byte           doscall[ 5 ]
      ptr( _VECTOR ) int22         // do not attempt to call these function
      ptr( _VECTOR ) int23         // pointers from ordinary code!
      ptr( _VECTOR ) int24
      uint           reserved2[ 11 ]
      uint           envseg
      // further members of the PSP structure are not declared here
   enddef
   
   /*
   The PSPPointer() function returns a pointer to the structure called
   the Program Segment Prefix (PSP). The PSP is allocated by DOS for
   each program at startup. It contains some data that can be useful to
   access in applications.
   
   A function returning a structure pointer must be declared as
   returning type ptr( ptr ). The caller can assign the return value
   to the proper type of structure pointer, and use the -> operator
   for referring to members.
   */
   
   func ptr( ptr ) PSPPointer
   vardef
      ptr( _PSP ) pPSP
   enddef
   // use the segment address stored in the __psp system variable to
   // generate a 32-bit pointer to the PSP, using makeptr()
   pPSP := makeptr( __psp, 0 )
   return( pPSP )
   endfunc
   
   // list all environment variables on screen
   proc ListEnvironment
   vardef
      ptr( char ) pString
      ptr( _PSP ) pPSP
   enddef
   pPSP := PSPPointer()
   // generate a pointer to the program environment
   pString := makeptr( pPSP->envseg, 0 )
   do while ! isempty( *pString )    // traverse all strings
      ? *pString                     // display
      pString += len( *pString ) + 1 // point to next environment string
   enddo
   endproc
   
   // A variant of the Force library function getexec()
   func char GetExec2
   vardef
      ptr( char ) pString
      ptr( _PSP ) pPSP
   enddef
   pPSP := PSPPointer()
   pString := makeptr( pPSP->envseg, 0 )
   do while ! isempty( *pString )        // skip environment strings
      pString += len( *pString ) + 1
   enddo
   pString += 3       // point behind the last environment string, and
   return( *pString ) // return the string found at this location,
   endfunc            // which is the full path name of the executing program
   
   proc Test_1591
   ListEnvironment()
   wait
   ? "Executable is", GetExec2()
   endproc
   

   proc main
   Test_1591()
   endproc

See Also: .

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson