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
(Created page with "{{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 '''%&''' which designates the integer value's flexible size. * Offset values are only useful when used in conjunction with _ME...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
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.''' | ||
Line 19: | Line 19: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' The SHBrowseForFolder function receives information about the folder selected by the user in Windows XP and 7. | ''Example:'' The SHBrowseForFolder function receives information about the folder selected by the user in Windows XP and 7. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|DECLARE | {{Cl|DECLARE LIBRARY|DECLARE CUSTOMTYPE LIBRARY}} | ||
{{Cl|FUNCTION}} FindWindow& ({{Cl|BYVAL}} ClassName AS {{Cl|_OFFSET}}, WindowName$) | {{Cl|FUNCTION}} FindWindow& ({{Cl|BYVAL}} ClassName AS {{Cl|_OFFSET}}, WindowName$) | ||
{{Cl|END}} {{Cl|DECLARE LIBRARY|DECLARE}} | {{Cl|END}} {{Cl|DECLARE LIBRARY|DECLARE}} | ||
Line 28: | Line 28: | ||
{{Cl|TYPE}} BROWSEINFO 'typedef struct _browseinfo '[http://msdn.microsoft.com/en-us/library/bb773205%28v=vs.85%29.aspx Microsoft MSDN] | {{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 | hwndOwner {{Cl|AS}} {{Cl|LONG}} ' ' HWND | ||
pidlRoot {{Cl|AS}} {{Cl|_OFFSET}} ' ' PCIDLIST_ABSOLUTE | pidlRoot {{Cl|AS}} {{Cl|_OFFSET}} ' ' PCIDLIST_ABSOLUTE | ||
pszDisplayName {{Cl|AS}} {{Cl|_OFFSET}} ' ' LPTSTR | pszDisplayName {{Cl|AS}} {{Cl|_OFFSET}} ' ' LPTSTR | ||
lpszTitle {{Cl|AS}} {{Cl|_OFFSET}} ' ' LPCTSTR | lpszTitle {{Cl|AS}} {{Cl|_OFFSET}} ' ' LPCTSTR | ||
ulFlags {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|LONG}} ' UINT | ulFlags {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|LONG}} ' UINT | ||
lpfn {{Cl|AS}} {{Cl|_OFFSET}} ' ' BFFCALLBACK | lpfn {{Cl|AS}} {{Cl|_OFFSET}} ' ' BFFCALLBACK | ||
lParam {{Cl|AS}} {{Cl|_OFFSET}} ' ' LPARAM | lParam {{Cl|AS}} {{Cl|_OFFSET}} ' ' LPARAM | ||
iImage {{Cl|AS}} {{Cl|LONG}} ' ' int | iImage {{Cl|AS}} {{Cl|LONG}} ' ' int | ||
{{Cl|END}} {{Cl|TYPE}} 'BROWSEINFO, *PBROWSEINFO, *LPBROWSEINFO; | {{Cl|END}} {{Cl|TYPE}} 'BROWSEINFO, *PBROWSEINFO, *LPBROWSEINFO; | ||
Line 58: | Line 58: | ||
{{Cl|ELSE}} | {{Cl|ELSE}} | ||
{{Cl|PRINT}} "Cancel?" | {{Cl|PRINT}} "Cancel?" | ||
{{Cl|END IF}} | {{Cl|END IF}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{ | {{Small|Code by Galleon}} | ||
Line 68: | Line 68: | ||
* [[_OFFSET (function)]], [[_MEM]] | * [[_OFFSET (function)]], [[_MEM]] | ||
* [[DECLARE LIBRARY]] | * [[DECLARE LIBRARY]] | ||
* [[DECLARE | * [[DECLARE LIBRARY]] | ||
* [[Variable Types]] | * [[Variable Types]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 23:01, 27 February 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