{{DISPLAYTITLE:_OFFSET}}
The [[_OFFSET]] variable type stores the location of a value in memory. The byte size varies as required by the system.


{{PageSyntax}}
: [[DIM]] variable [[AS]] '''_OFFSET'''


{{PageDescription}}
* _OFFSET types can be created as signed or [[_UNSIGNED]] at the programmer's discretion.
* The type suffix for _OFFSET is '''%&amp;''' 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 [[Variable Types|type]] in QB64. Variable.OFFSET returns or sets the current position in memory.
* API [[DECLARE LIBRARY|LIBRARY]] parameter or [[TYPE|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.'''


{{PageExamples}}
''Example:'' The SHBrowseForFolder function receives information about the folder selected by the user in Windows XP and 7.
{{CodeStart}} '' ''
{{Cl|DECLARE DYNAMIC LIBRARY|DECLARE CUSTOMTYPE LIBRARY}}
    {{Cl|FUNCTION}} FindWindow&amp; ({{Cl|BYVAL}} ClassName AS {{Cl|_OFFSET}}, WindowName$)
{{Cl|END}} {{Cl|DECLARE LIBRARY|DECLARE}}

{{Cl|_TITLE}} "Super Window"
hwnd&amp; = FindWindow(0, "Super Window" + {{Cl|CHR$}}(0))

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

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

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


{{PageSeeAlso}}
* [[_WINDOWHANDLE]]
* [[Using _OFFSET]]
* [[_OFFSET (function)]], [[_MEM]]
* [[DECLARE LIBRARY]]
* [[DECLARE DYNAMIC LIBRARY]]
* [[Variable Types]]


{{PageNavigation}}
