// MapFile.cpp : Defines the entry point for the console application.<br />//http://msdn.microsoft.com/en-us/library/ms810613.aspx<br />#include "stdafx.h"<br />#include <stdio.h><br />#include <stdlib.h><br />#include <windows.h><br />int _tmain(int argc, _TCHAR* argv[])<br />{<br />OFSTRUCT opBuf;<br />HANDLE hMapfile;<br />HANDLE hMapview;<br />BYTE *recv;<br />HANDLE hFile = CreateFile(L".//map.test", FILE_GENERIC_READ|FILE_GENERIC_WRITE, /<br />FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, NULL, NULL);<br />if (hFile == NULL)<br />{<br />printf("create file failed!/n");<br />return 1;<br />}<br />//if hFile is 0xffffffff, it is for process share<br />hMapfile=CreateFileMapping((HANDLE)hFile,NULL,PAGE_READWRITE,0,0x01400000,L"MapTest"); //0x4000000 0x01400000<br />/*<br />10 can not be 0, or you can not CreateFileMap successfully<br />another thing: if you know that the hFile size is not zero(there are chars in the file), then 10 can be set 0<br />*/<br />if(hMapfile==NULL)<br />{<br />printf("create mapping file failed!/n");<br />printf("%d/n", GetLastError());<br />return 1;<br />}<br />CloseHandle((HANDLE)hFile);<br />hFile=0;<br />hMapview=MapViewOfFile(hMapfile,FILE_MAP_WRITE,0,0,0);<br />if(hMapview==NULL)<br />{<br />printf("mapping view failed!/n");<br />return 1;<br />}<br />recv=(BYTE *)hMapview;<br />printf("Mapping view's content is :%.10s /n",recv);<br />recv[0]='I';recv[1]=' ';recv[2]='l';recv[3]='o';recv[4]='v';<br />recv[5]='e';recv[6]=' ';recv[7]='y';recv[8]='o';recv[9]='u';<br />//_tcscpy((wchar_t *)recv, L"I love you!");<br />printf("Mapping view's content is :%.10s /n",recv);<br />UnmapViewOfFile(hMapview);<br />return 0;<br />}</p><p>