Structure layouts are not necessarily contiguous, and are not necessarily consistent between 32-bit and 64-bit (or between different versions of the same library.) This is because the members are aligned to certain byte offsets for efficiency.
In this case LSA_STRING
appears to use an 8-byte alignment on 64-bit Windows, which means the structure is actually 16 bytes long (not 12), and the Buffer
member is at offset 8 (not 4):
dim LSA_STRING as new MemoryBlock(16)
LSA_STRING.UInt16Value(0) = packageName.Length
LSA_STRING.UInt16Value(2) = packageName.Length + 1
LSA_STRING.ptr(8) = strMb
Xojo can handle these details for you automatically. Insert a Structure into your app and recreate the LSA_STRING
in it, and use that instead of a bare MemoryBlock. You can then alter the alignment using the StructureAlignment attribute: