TransferBuffer issue with ComboBox hint

2006-10-18 10:36:56 AM
I have always had a problem with transfer buffers and OWLNext under
MSVC. I always had to put ComboBoxData structures before all others
I found the cause of my woes. Hopefully this might help others.
It's a structure packing/alignment problem. The VC compiler by default
aligns things on 8 byte boundaries. If some TEdit text data falls first
in the TransferBuffer structure then it will be aligned by the compiler
then if some ComboBoxData falls later it will not align properly when
the transfer method accesses it because it performs pointer arithmetic
based on the sizes returned from each control - ignoring structure
member alignment (sometimes called padding).
To make sure your Transfer Buffer struct's work enclose them in
#pragma's that turn of padding (ie., alignment = 1 byte).
// Turn off struct padding
#pragma pack(1)
// define structure
struct TB
WORD SDKVersion10;
WORD SDKVersion11;
WORD SDKVersion12;
WORD SDKVersion13;
WORD optimize;
WORD executeInParentDirectory;
WORD promptBeforeClosingRun;
WORD redirectOutputAndDisplayCompile;
char compileCommand[OCOLEN+1];
char runCommand[RUNCOMMANDLEN+1];
} *tranBuf;
// Switch back to default padding
#pragma pack()