From 452bf6a64e4734990f7e9f56061a6f11113bc2d5 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 17 May 2026 04:38:37 -0400 Subject: [PATCH 1/2] vbNullPtr section missing ByVal req; minor re-org The section on vbNullPtr was out of date, not reflecting that ByVal is now required. Article opened with ref to moved previous section. Moved general case ptr/udt section to below vbNullPtr and changed wording to reflect concept flow. --- docs/Features/Language/Pointers.md | 34 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/Features/Language/Pointers.md b/docs/Features/Language/Pointers.md index fe32e3c6..ad9e3181 100644 --- a/docs/Features/Language/Pointers.md +++ b/docs/Features/Language/Pointers.md @@ -11,9 +11,9 @@ twinBASIC provides several enhancements for working with pointers. ## ByVal Nothing -Additionally, while not strictly new syntax, twinBASIC also adds support for `ByVal Nothing`, to override a `ByRef ` argument and pass a null pointer there. +While not strictly new syntax, twinBASIC also adds support for `ByVal Nothing`, to override a `ByRef ` argument and pass a null pointer there. -## vbNullPtr +## ByVal vbNullPtr Allows passing null pointers to UDT members of APIs/interfaces. The equivalent behavior in VBx is to declare them `As Any` and then pass `ByVal 0` at call sites. @@ -26,10 +26,24 @@ End Type Public Declare PtrSafe Function MyFunc Lib "MyDLL" (pFoo As Foo) As Long Private Sub CallMyFunc() - Dim ret As Long = MyFunc(vbNullPtr) + Dim ret As Long = MyFunc(ByVal vbNullPtr) End Sub ``` +## Substitute Pointers for UDTs + +More generally, in both APIs and local methods, any argument taking a user-defined type can instead be passed a `ByVal LongPtr`, with the new special constant `vbNullPtr` used for a null pointer: + +```tb +Public Declare PtrSafe Function CreateFileW Lib "kernel32" (ByVal lpFileName As LongPtr, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As LongPtr) As LongPtr + +hFile = CreateFileW(StrPtr("name"), 0, 0, ByVal vbNullPtr, '...) +'---or--- +Dim pSec As SECURITY_ATTRIBUTES +Dim lPtr As LongPtr = VarPtr(pSec) +hFile = CreateFileW(StrPtr("name"), 0, 0, ByVal lPtr, '...) +``` + ## CType(Of \) The `CType(Of )` operator specifies an explicit intent to cast one type to another. This can be used for casting `LongPtr` (or `Long` on 32bit/`LongLong` on 64bit) to a custom user-defined type, with or without making a copy of it, depending on the usage. This allows not just for casting directly without a `CopyMemory` call, but also, setting the members of a UDT represented only by a pointer, without copying memory back and forth. @@ -105,20 +119,6 @@ End Sub This will print `4`. Free standing use and nesting is also allowed; the above will print `4`. While the examples here are local code only, this is particularly useful for APIs, where you're forced to work with pointers extensively. -## Substitute Pointers for UDTs - -In both APIs and local methods, any argument taking a user-defined type can instead be passed a `ByVal LongPtr`, with the new special constant `vbNullPtr` used for a null pointer: - -```tb -Public Declare PtrSafe Function CreateFileW Lib "kernel32" (ByVal lpFileName As LongPtr, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As LongPtr) As LongPtr - -hFile = CreateFileW(StrPtr("name"), 0, 0, ByVal vbNullPtr, '...) -'---or--- -Dim pSec As SECURITY_ATTRIBUTES -Dim lPtr As LongPtr = VarPtr(pSec) -hFile = CreateFileW(StrPtr("name"), 0, 0, ByVal lPtr, '...) -``` - ## Len/LenB(Of \) Support The classic `Len` and `LenB` functions can now be used to directly get the length/size of a type, both intrinsic and user-defined, without needing have declared a variable of that type. For instance, to know the pointer size, you can use `LenB(Of LongPtr)`. From 4fd4d7d621e17728705b473f8048ebbcdaf79de5 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 17 May 2026 04:44:30 -0400 Subject: [PATCH 2/2] Fix LLC/LTD typo --- docs/Features/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Features/index.md b/docs/Features/index.md index 344ec1fa..5278614d 100644 --- a/docs/Features/index.md +++ b/docs/Features/index.md @@ -68,7 +68,7 @@ twinBASIC[^1] has a centralized package repository, called TWINSERV. Users can p Packages are collections of components that can be referenced from another twinBASIC project. They are distributed as TWINPACK files that contains everything needed by the components in that package. -[^1]: A service of TWINBASIC LLC offered to the user community. +[^1]: A service of TWINBASIC LTD offered to the user community. ### [Advanced Features](Advanced/)