Pointers in VB (Unsafe).
There is a lot said about it on a lot of places and Microsoft’s answer has always been: NO.
But it is needed for a lot of API’s - so needed to get everything working in Mercury.
In VB we can not work with * or ^ - that’s not VB at all.
So I propose the following syntax:
Edited:
Ptr(Of type) like Ptr(Of Integer), Ptr(Of Object)
For functionPointers: SubPtr and FunctionPtr
Assignment:
Dim o As New Object
Dim p As Ptr(Of Object) = AddressOf o 'Use the AddresOf to get the memory location of object o
Get the memory Address (convert to IntPtr):
Dim i As IntPtr = DirectCast(p, IntPtr)
Or convert an IntPtr to a typed pointer:
Dim tp As ptr(Of Object)= DirectCast(i, Ptr(Of Object))
Dereferencing:
Dim o2 as Object = DirectCast(p, Object)
Calling a method using a functionpointer:
Call fp(param1, param2) 'no return value
Dim x = fp(param1, param2) 'with return value
Syntax for unsafe methods:
Public Unsafe Sub MyUnsafeSub()
End Sub
Same unsafe keyword for classes, structs, properties and fields