Yeah, you can get pointers into VB and move them around, but doing something with them is generally the problematic part.
Dim xxx as Object gets you a pointer too
Passing ByRef is usually good enough. What if it''s a handle (a pointer-pointer)?
So in Zipster''s case here, how would take your VB string of the serialized data stream and suck a word (a VB int) out of it? and then a VB byte?
Winsock with Visual Basic
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
What I usually use is CopyMemory:
Then, it is a simple matter of bitshifting and adding to get the Integer.
Alternatively, most of the time I would instead accept a pointer to an array of bytes and work straight from that.
Again alternatively, you could use the Asc function and the Mid$ function to get the byte value of a character.
Object references are slightly different to pointers. Main problem is that they are slow. And can only "point" to VB classes (which are also slow). Then, manipulating them isn''t very nice either.
CopyMemory to the rescue:
will output 5.
Trying is the first step towards failure.
Declare Sub CopyMemory... can''t remember callSub DoStuff(InputStream As String, MyFunBytes() As Byte) Dim Length As Long Length = Len(InputStream) ReDim MyFunBytes(Length - 1) CopyMemory InputStream, MyFunBytes, LengthEnd Sub
Then, it is a simple matter of bitshifting and adding to get the Integer.
Alternatively, most of the time I would instead accept a pointer to an array of bytes and work straight from that.
Again alternatively, you could use the Asc function and the Mid$ function to get the byte value of a character.
quote:
Dim xxx as Object gets you a pointer too
Object references are slightly different to pointers. Main problem is that they are slow. And can only "point" to VB classes (which are also slow). Then, manipulating them isn''t very nice either.
quote:
Yeah, you can get pointers into VB and move them around, but doing something with them is generally the problematic part.
CopyMemory to the rescue:
Function GetLongFromPointer(ByVal Pointer As Long) As Long CopyMemory GetLongFromPointer, ByVal Pointer, 4End FunctionSub DoStuff() Dim MyArray(10) As Long MyArray(5) = 6 Debug.Print GetLongFromPointer(VarPtr(MyArray(4) + 4)End Sub
will output 5.
Trying is the first step towards failure.
Trying is the first step towards failure.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement