OFFSET: Difference between revisions
Jump to navigation
Jump to search
Code by Galleon
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
* The type suffix for _OFFSET is '''%&''' which designates the integer value's flexible size. | * 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 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. | * 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. | * 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: _OFFSET values cannot be cast to other variable type values reliably.''' |
Revision as of 20:27, 26 January 2024
The _OFFSET variable type stores the location of a value in memory. The byte size varies as required by the system.
Syntax
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.
DECLARE CUSTOMTYPE LIBRARY FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$) END DECLARE _TITLE "Super Window" hwnd& = FindWindow(0, "Super Window" + CHR$(0)) TYPE BROWSEINFO 'typedef struct _browseinfo '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 DYNAMIC LIBRARY "shell32" FUNCTION SHBrowseForFolder%& (x AS BROWSEINFO) 'Microsoft MSDN SUB SHGetPathFromIDList (BYVAL lpItem AS _OFFSET, BYVAL szDir AS _OFFSET) 'Microsoft MSDN END DECLARE DIM b AS BROWSEINFO b.hwndOwner = hwnd DIM s AS STRING * 1024 b.pszDisplayName = _OFFSET(s$) a$ = "Choose a folder!!!" + CHR$(0) b.lpszTitle = _OFFSET(a$) DIM o AS _OFFSET o = SHBrowseForFolder(b) IF o THEN PRINT LEFT$(s$, INSTR(s$, CHR$(0)) - 1) DIM s2 AS STRING * 1024 SHGetPathFromIDList o, _OFFSET(s2$) PRINT LEFT$(s2$, INSTR(s2$, CHR$(0)) - 1) ELSE PRINT "Cancel?" END IF |
See also
- _WINDOWHANDLE
- Using _OFFSET
- _OFFSET (function), _MEM
- DECLARE LIBRARY
- DECLARE DYNAMIC LIBRARY
- Variable Types