#include #define buf_size 256
tchar szname[] = text("global\\myfilemappingobject");
tchar szmsg[] = text("message from first process.");
int _tmain()
{
handle hmapfile;
lpctstr pbuf;
hmapfile = createfilemapping(
invalid_handle_value, // use paging file
null, // default security
page_readwrite, // read/write access
0, // maximum object size (high-order dword)
buf_size, // maximum object size (low-order dword)
szname); // name of mapping object
if (hmapfile == null)
{
_tprintf(text("could not create file mapping object (%d).\n"),
getlasterror());
return 1;
}
pbuf = (lptstr)mapviewoffile(hmapfile, // handle to map object
file_map_all_access, // read/write permission
0,
0,
buf_size);
if (pbuf == null)
{
_tprintf(text("could not map view of file (%d).\n"),
getlasterror());
closehandle(hmapfile);
return 1;
}
copymemory((pvoid)pbuf, szmsg, (_tcslen(szmsg) * sizeof(tchar)));
_getch();
unmapviewoffile(pbuf);
closehandle(hmapfile);
return 0;
}