08-20-2023, 06:04 PM
(08-20-2023, 05:47 PM)TerryRitchie Wrote:(08-20-2023, 12:01 AM)a740g Wrote: Here. This should work on 64-bit compilers.
Yes it does, thank you! This example should be added to the Windows Library examples in the Wiki.
Could you explain the changes you made and why they needed to be done so I can get a better understanding of your code and why 64-bit needs to be approached differently please?
The issue lies in data alignment and type packing. In 32 bit OSes, data is packed on a 4 byte alignment. In 64-bit OSes, it's packed on 8-byte alignments.
For example:
TYPE Foo
x AS INTEGER
y AS LONG
z AS STRING *3
END TYPE
The above type (as a windows type) would align on 4-byte break points. It'd actually use 12-bytes per record in memory as:
TRANSLATED TYPE Foo32
x AS INTEGER
buffer AS STRING *2 'complete that 4 byte block
y AS LONG 'already 4 bytes; no buffer is needed
z AS STRING * 3
buffer2 AS STRING * 1 'complete the other 4 byte block
END TYPE
On a 64-bit type, the breakpoints are 8-bytes, for 16-bytes per record in memory.
TRANSLATED TYPE Foo64
x AS INTEGER
y AS LONG
buffer AS STRING * 2 'complete the 8-byte block
z AS STRING * 3
buffer2 AS STRING * 5 'complete the second 8-byte block
END TYPE
For 32-bit windows API types, data is aligned in 4-byte segments. For 64-bit window API types, it's in 8-byte segments.