I'm trying currently to test inter process communication by using filemaps. My first program, which i shall call the producer, doesn't error on the following code which createsa file map and writes to it, as follows:
hEvent = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
256, // maximum object size (low-order DWORD)
TEXT("hEvent"));
if (hEvent == NULL)
{
MessageBox(NULL, TEXT("error: cannot create file map"), TEXT("gotit"), MB_OK);
_tprintf(TEXT("Could not create file mapping object (%d).\n"),
GetLastError());
return 1;
}
mapBuffer = (LPTSTR) MapViewOfFile(hEvent, FILE_MAP_ALL_ACCESS, NULL, NULL, 256);
if (mapBuffer == NULL)
{
MessageBox(NULL, TEXT("error: cannot view map"), TEXT("gotit"), MB_OK);
_tprintf(TEXT("Could not map view of file (%d).\n"),
GetLastError());
CloseHandle(hEvent);
return 1;
}
CopyMemory((PVOID)mapBuffer, teststring, 256);
_getch();
UnmapViewOfFile(mapBuffer);
CloseHandle(hEvent);
However, my second program, which is imitating the second process and i shall name the consumer, errors upon trying to re-open this filemap, using the following code:
hEvent = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, TEXT("hEvent"));
if (hEvent == NULL)
{
MessageBox(NULL, TEXT("error opening filemap"), TEXT("gotit"), MB_OK);
GetLastError();
return 1;
}
Can anyone see anything obvious i'm missing?, as it's going straight over my head.