I have a shared memory with this structure (see codesnippet 1), all values are hex values:
Position 00: 55; // memory overall, byte 00 to 03;
Position 01: 00;
Position 02: 00;
Position 03: 00;
Position 04: 47; // memory for header information, byte 04 to 07;
Position 05: 00
Position 06: 00;
Position 07: 00;
Position 08: 00; // version, byte 08, 09;
Position 09: 00;
Position 0A: 64; // rate of refreshing memory between processes
Position 0B: 00;
Position 0C: 00;
Position 0D: 00;
Position 0E: 00;
Position 0F: 4L;
...
As you can see in the comments I know which byte represents what information. Anyway I cast the memory in a struct (see codesnippet 2). The properties in this struct are currently integer-values. The values 55 and 47 are stored in the first two properties. As it seems, '00' will be neglected and I am not able to read the whole memory byte by byte. How can I read the memory bytewise?
codesnippet 2:
struct Shm {
int memorySize; // size of memory space; min 4 bytes, Position 00 - 03; ie 55 is a hex value and means 84
int headerSize; // size of header space; min 4 bytes, Position 04 - 07; ie 47 (hex), so 71 (dec) same number as config-dialog
int byte3; // version number
int byte4; // refreshing interval in msec
...
Moroever there are some areas in the memory, which contain some chars - how to cast those byte-values to chars and create words of them, currently I am only able to cast to int-values (see codesnippet 3)
int main(void){
std::cout << "*** Start SharedMemory ***\n";
HANDLE hMapFile;
...
Shm * pBuf = (Shm *) MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE);
std::cout << " Debug memorySize " << ": " << dec << pBuf->memorySize << " (dec); " << hex << pBuf->memorySize << " (hex); " << &pBuf->memorySize << " (Adresse);\n"; // 84 Bytes
std::cout << " Debug headerSize " << ": " << dec << pBuf->headerSize << " (dec); << hex << pBuf->headerSize << " (hex);\n"; // 71 Bytes
std::cout << " Debug byte3 " << ": " << dec << pBuf->byte3 << " (dec); " << hex << pBuf->byte3 << " (hex);\n";
...