I'm still very new to C++ development, please keep this in mind during the scope of my questions. I have a legacy Delphi application which sends a message to my C++ window using SendMessage()
with WM_COPYDATA
. The application is using a record to transmit a blob of data:
TUser = record
LastName: String[28];
FirstName: String[28];
ID: String[20];
DateOfBirth: String[10];
Sex: Boolean;
Size: Word;
Weight: Word;
end;
In my C++ application, I have setup the following struct to read out the transmitted information:
typedef struct {
char LastName[29];
char FirstName[29];
char ID[21];
char DateOfBirth[11];
bool Sex;
unsigned short Size;
unsigned short Weight;
} Legacy_TUser;
According to the Delphi documentation, a fixed String with e.g. the length of 40 will occupy 40 + 1 bytes. However, once I receive the data, I perform a size comparison of the received data and my struct setup:
Logger::Log("Size of data: %i", pcds->cbData);
Logger::Log("Size of struct: %i", sizeof(Legacy_TUser));
This results in an output of:
Size of data: 95
Size of struct: 96
Which brings me to my final question. I can't seem to find any reason why the size of my struct is one byte too large. The string length seems to be correct, the data which I read in is shifted by exactly one byte. What am I missing here?