Click here to Skip to main content
15,662,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,
I'm using MapViewOfFile to map a file and try to edit its data and save it on the file.
The problem I have extra data to the file required to expand its size.
So, how to append data to the end of memory mapped file using CreateFileMapping and MapViewOfFile?
Santhosh G_ 24-May-13 16:27pm    
Do you want to change the file contents, by appending some data at the end of mapped file, right ?
Rasool Ahmed 24-May-13 23:18pm    
Yes, I want to edit the middle of the content and append additional data to the end of the file, this will expand its size.

1 solution

Try to use the below method it create file mapping with large size and update the contents.
DWORD nSize = GetFileSize( hFile, &nSizeH );
    int nRequiredSize = nSize + nAddedSize;// New size is calculated for file mapping.
    HANDLE hMapping = CreateFileMapping( hFile, 0, PAGE_READWRITE, 0,nRequiredSize,0 );
    CHAR* pData = (CHAR*)MapViewOfFile( hMapping, FILE_MAP_ALL_ACCESS, 0,0, 0 );
    // Append data to pData
Share this answer
Rasool Ahmed 25-May-13 1:28am    
Thanx, I will try it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900