[求助]内存映射文件操作
我是个初学者,像询问一下:在创建内存映射文件对象,然后将该对象映射到进程的地址空间中,对文件进行读写调用什么函数操作?
希望能给我写两句例句,非常感谢你的热心帮助!
HANDLE hFile = CreateFile(pszPathName,GENERIC_WRITE|GENERIC_READ,0,NULL
,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
printf("File could not be opened.");
return FALSE;
}
DWORD dwFileSize = GetFileSize(hFile,NULL);
HANDLE hFileMap = CreateFileMapping(hFile,NULL,PAGE_READWRITE,0,
dwFileSize+sizeof(char),NULL);
if(hFileMap == NULL){
CloseHandle(hFile);
return FALSE;
}
PVOID pvFile = MapViewOfFile(hFileMap,FILE_MAP_WRITE,0,0,0);
if(pvFile == NULL){
CloseHandle(hFileMap);
CloseHandle(hFile);
return FALSE;
}
PWSTR pchUnicode = (PWSTR) pvFile;