HANDLE hFile = CreateFile ( "abc.txt", // name of the file GENERIC_READ | GENERIC_WRITE, // access (read-write) mode 0, // share mode NULL, // pointer to security attributes OPEN_ALWAYS, // how to create FILE_ATTRIBUTE_NORMAL, // file attributes NULL // handle to file with attributes to copy ); if (hFile != INVALID_HANDLE_VALUE) { Button1->Caption = "Open"; HANDLE hMap = CreateFileMapping (hFile, // handle to file to map NULL, // optional security attributes PAGE_READWRITE, // protection for mapping object 0, // high-order 32 bits of object size 1024, // low-order 32 bits of object size NULL // name of file-mapping object ); if (hMap != NULL) { Button1->Caption = "Mapped"; void * p = MapViewOfFile (hMap, // file-mapping object to map into address space FILE_MAP_WRITE, // access mode 0, // high-order 32 bits of file offset 0, // low-order 32 bits of file offset 512 // number of bytes to map ); if (p != NULL) { Button1->Caption = "View Mapped"; char * c = (char *) p; c[0] = 'A'; c[1] = 'B'; c[2] = 'C'; c[3] = 0; UnmapViewOfFile (hMap); } CloseHandle (hMap); } else { Button1->Caption = "Error"; } CloseHandle (hFile); }