hello,
When I want to use the shared memory, I got a problem.
1.I wrote a server to create a piece of shared memory. Source is below:
// shmsv.cpp
HANDLE hMapFile = NULL;
LPVOID pVoid = NULL;
hMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE,
NULL,
PAGE_READWRITE,
0,
BUF_SIZE, // 1024
SHM_NAME);
pVoid = MapViewOfFile(hMapFile,
FILE_MAP_ALL_ACCESS,
0,
0,
BUF_SIZE);
memset(pVoid, '*', BUF_SIZE);
char *szMsg = "Hello shared memory.";
CopyMemory(pVoid, szMsg, strlen(szMsg));
2.I wrote another program to read message from the shared memory. Source is below:
// readFrom.cpp
HANDLE hFileMap = NULL;
LPVOID pVoid = NULL;
hFileMap = OpenFileMapping(FILE_MAP_READ,
FALSE,
SHM_NAME);
pVoid = MapViewOfFile(hFileMap,
FILE_MAP_READ,
0,
0,
8);
//BUF_SIZE);
printf("message from shared memory is: %s.\n", (char *)pVoid);
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.
4.If I only want to output the 8 bytes' info from the shared memory, what should I do?
regards,
yogo