Skip to content

Commit ec4ba5d

Browse files
authored
Merge pull request #139 from fafalone/main
vbNullPtr section missing ByVal req; minor re-org
2 parents 1d00078 + 4fd4d7d commit ec4ba5d

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

docs/Features/Language/Pointers.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ twinBASIC provides several enhancements for working with pointers.
1111

1212
## ByVal Nothing
1313

14-
Additionally, while not strictly new syntax, twinBASIC also adds support for `ByVal Nothing`, to override a `ByRef <interface>` argument and pass a null pointer there.
14+
While not strictly new syntax, twinBASIC also adds support for `ByVal Nothing`, to override a `ByRef <interface>` argument and pass a null pointer there.
1515

16-
## vbNullPtr
16+
## ByVal vbNullPtr
1717

1818
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.
1919

@@ -26,10 +26,24 @@ End Type
2626
Public Declare PtrSafe Function MyFunc Lib "MyDLL" (pFoo As Foo) As Long
2727
2828
Private Sub CallMyFunc()
29-
Dim ret As Long = MyFunc(vbNullPtr)
29+
Dim ret As Long = MyFunc(ByVal vbNullPtr)
3030
End Sub
3131
```
3232

33+
## Substitute Pointers for UDTs
34+
35+
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:
36+
37+
```tb
38+
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
39+
40+
hFile = CreateFileW(StrPtr("name"), 0, 0, ByVal vbNullPtr, '...)
41+
'---or---
42+
Dim pSec As SECURITY_ATTRIBUTES
43+
Dim lPtr As LongPtr = VarPtr(pSec)
44+
hFile = CreateFileW(StrPtr("name"), 0, 0, ByVal lPtr, '...)
45+
```
46+
3347
## CType(Of \<type\>)
3448

3549
The `CType(Of <type>)` 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
105119

106120
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.
107121

108-
## Substitute Pointers for UDTs
109-
110-
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:
111-
112-
```tb
113-
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
114-
115-
hFile = CreateFileW(StrPtr("name"), 0, 0, ByVal vbNullPtr, '...)
116-
'---or---
117-
Dim pSec As SECURITY_ATTRIBUTES
118-
Dim lPtr As LongPtr = VarPtr(pSec)
119-
hFile = CreateFileW(StrPtr("name"), 0, 0, ByVal lPtr, '...)
120-
```
121-
122122
## Len/LenB(Of \<type\>) Support
123123

124124
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)`.

docs/Features/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ twinBASIC[^1] has a centralized package repository, called TWINSERV. Users can p
6868

6969
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.
7070

71-
[^1]: A service of TWINBASIC LLC offered to the user community.
71+
[^1]: A service of TWINBASIC LTD offered to the user community.
7272

7373
### [Advanced Features](Advanced/)
7474

0 commit comments

Comments
 (0)