There is a code

void LetMeMapFlie(){ // Создаем файлы FMP.writefile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 255, MFName_w); FMP.readfile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READONLY, 0, 255, MFName_r); // Открываем файлы FMP.write = MapViewOfFile(FMP.writefile, FILE_MAP_WRITE, 0,0,0); FMP.read = MapViewOfFile(FMP.readfile, FILE_MAP_READ, 0,0,0); } 

Further, there are functions left for me to work with pipes.

 void WriteChar_SlimRG(unsigned char key){ WriteFile(pipe1Write, &key, sizeof(unsigned char), &out_pipe_b, NULL) } 

Can I stupidly replace pipe1Write with a file handle

Or is there some special approach to writing bytes or INTs in the Map File?

PS in English lang not very good sharyu (Google translate) - so do not think that I did not attend off. site of microsoft. But I did not understand this moment.

  • MapViewOfFile returns the address of the memory location to which a file or part of it is mapped. To work with addresses, and not to use file operations. - MBo
  • @MBo i.e. not through ReadFile and WriteFile? And you can an example how to write byte through MapViewOfFile. Not really imagine how to do it - SlimRG pm

1 answer 1

MapViewOfFile returns the address of the memory location to which a file or part of it is mapped. To work with addresses, and not to use file operations.

The resulting pointer can be converted to the desired type - for example, char* and accessed as an array.

 char* data = (char*)MapViewOfFile(... data[3] = 42; 

ReadFile and WriteFile have nothing to do with it

  • And changes, if, for example, my client reads, and the server writes, are they immediately processed? - SlimRG
  • Or after UnMap - SlimRG
  • If both programs access the same object — the changes will be immediately, this is one of the basic IPC (interprogram interaction) methods. It is only necessary to provide synchronization so as not to read the unfinished. - MBo