Originally Posted by
wal_sug
3.Here comes the probelm: I only want to output the 8 bytes' info from the shared memory.
But the "readFrom" program outputed all the message from the shared memory.
printf will keep on printing until it either finds a null character, or throws an access violation from trying to reading memory you don't have read access to. Since you are not null-terminating the string or using exception handling you're basically just waiting for a crash to happen
Code:
char *szMsg = "Hello shared memory.";
CopyMemory(pVoid, szMsg, strlen(szMsg));
strlen returns the length of a string without counting the terminating 0. Use strlen(szMsg)+1 instead.
Originally Posted by
wal_sug
4.If I only want to output the 8 bytes' info from the shared memory, what should I do?
You can either copy 8 chars to a new string, or if you don't care about corrupting the original data just insert a NULL at the 9th position.