I ran into a difference between MemoryBlock and Ptr today, so I figured it'd make for a nice blog posting.
dim w, w2 as WString
dim mb as MemoryBlock = somePtr
w = mb.WString( 0 )
w2 = somePtr.WString( 0 )
You'd think that w and w2 would be the same WString, but alas, they are not. Ptr.WString takes the memory location at the offset given, dereferences it, and starts grabbing UTF-16 data until it hits a null character. MemoryBlock.WString uses the memory block's start adress plus the offset given and starts grabbing UTF-16 data until it hits a null character. The main difference is that Ptr treats WString as a pointer to UTF-16 data, and MemoryBlock treats WString as an offset to the UTF-16 data (no dereferencing needed).
Watch out for that one!
Leave a comment