_OFFSET - mkilgore/QB64pe GitHub Wiki

The _OFFSET variable type stores the location of a value in memory. The byte size varies as required by the system.

Syntax

DIM variable AS _OFFSET

Description

  • _OFFSET types can be created as signed or _UNSIGNED at the programmer's discretion.
  • The type suffix for _OFFSET is %& which designates the integer value's flexible size.
  • Offset values are only useful when used in conjunction with _MEM or DECLARE LIBRARY procedures.
  • OFFSET values are used as a part of the _MEM variable type in QB64. Variable.OFFSET returns or sets the current position in memory.
  • API LIBRARY parameter or type names may include lp, ptr or p which designates them as a pointer type.
  • Warning: _OFFSET values cannot be cast to other variable type values reliably.
  • Warning: Variable length STRING values can move about in memory at any time. If you get the _OFFSET of a variable length sting on one code line and use it on the next it may not be there anymore. To be safe, move variable length strings into fixed length strings first.

Examples

Example: The SHBrowseForFolder function receives information about the folder selected by the user in Windows XP and 7.

_TITLE "Super Window"
hwnd& = FindWindow(0, "Super Window" + CHR$(0))

TYPE BROWSEINFO  'typedef struct _browseinfo '[http://msdn.microsoft.com/en-us/library/bb773205%28v=vs.85%29.aspx Microsoft MSDN]
  hwndOwner AS LONG '              '  HWND 
  pidlRoot AS _OFFSET '            '  PCIDLIST_ABSOLUTE
  pszDisplayName AS _OFFSET '      '  LPTSTR 
  lpszTitle AS _OFFSET '           '  LPCTSTR       
  ulFlags AS _UNSIGNED LONG        '  UINT   
  lpfn AS _OFFSET '                '  BFFCALLBACK  
  lParam AS _OFFSET '              '  LPARAM  
  iImage AS LONG '                 '  int  
END TYPE  'BROWSEINFO, *PBROWSEINFO, *LPBROWSEINFO;

DECLARE LIBRARY "shell32"
  FUNCTION SHBrowseForFolder%& (x AS BROWSEINFO) '[http://msdn.microsoft.com/en-us/library/bb762115%28v=vs.85%29.aspx Microsoft MSDN]
  SUB SHGetPathFromIDList (BYVAL lpItem AS _OFFSET, BYVAL szDir AS _OFFSET) '[http://msdn.microsoft.com/en-us/library/bb762194%28VS.85%29.aspx Microsoft MSDN]
DECLARE LIBRARY

DIM b AS BROWSEINFO
b.hwndOwner = hwnd
DIM s AS STRING * 1024
b.pszDisplayName = _OFFSET (function)(s$)
a$ = "Choose a folder!!!" + CHR$(0)
b.lpszTitle = _OFFSET (function)(a$)
DIM o AS _OFFSET
o = SHBrowseForFolder(b)
IF...THEN o THEN
    PRINT LEFT$(s$, INSTR(s$, CHR$(0)) - 1)
    DIM s2 AS STRING * 1024
    SHGetPathFromIDList o, _OFFSET (function)(s2$)
    PRINT LEFT$(s2$, INSTR(s2$, CHR$(0)) - 1)
ELSE
    PRINT "Cancel?"
END IF '' ''
Code by Galleon

See also


Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
⚠️ **GitHub.com Fallback** ⚠️