CreateFileMapping(...,name)
MapViewOfFile
handle=OpenFileMapping(...,name)
WriteFile(handle...)
注意文件存取的类型要一致,下面代码是可以的:
HANDLE hf=CreateFile("out.txt",GENERIC_WRITE|GENERIC_READ,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
HANDLE hm=CreateFileMapping(hf,NULL,PAGE_READWRITE,0,2048,"share");
void* pf=MapViewOfFile(hm,FILE_MAP_WRITE,0,0,0);
*((char*) pf)='A';
*((char*)pf+1)='\0';
CloseHandle(hm);
CloseHandle(hf);
FlushViewOfFile就是把内存映射文件中的一段字节直接写到磁盘上去。
20041118 20050809 20051106
MapViewOfFile
handle=OpenFileMapping(...,name)
WriteFile(handle...)
注意文件存取的类型要一致,下面代码是可以的:
HANDLE hf=CreateFile("out.txt",GENERIC_WRITE|GENERIC_READ,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
HANDLE hm=CreateFileMapping(hf,NULL,PAGE_READWRITE,0,2048,"share");
void* pf=MapViewOfFile(hm,FILE_MAP_WRITE,0,0,0);
*((char*) pf)='A';
*((char*)pf+1)='\0';
CloseHandle(hm);
CloseHandle(hf);
FlushViewOfFile就是把内存映射文件中的一段字节直接写到磁盘上去。
20041118 20050809 20051106