Advertisement
piffy

MapOfFile_reader

Aug 31st, 2014
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. /** Se cercate il codice Writer, il link è https://pastebin.com/95E8DkzL (errore sul libro) */
  2.  
  3. #include <windows.h>
  4. #include <assert.h>
  5. #include <stdio.h>
  6.  
  7.  
  8. static const LONG BufferSize=100;
  9. static const char MemoryName[]="NomeZonaMemoria";
  10. static char (*Memory)[BufferSize];
  11. static HANDLE hMemory;
  12.  
  13. int main(void)    {
  14.     hMemory=CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0
  15.         ,sizeof(char [BufferSize]),MemoryName);
  16.     assert(hMemory!=NULL);
  17.  
  18.     Memory=(char (*)[BufferSize])MapViewOfFile(hMemory
  19.         ,FILE_MAP_WRITE,0,0,sizeof(char [BufferSize]));
  20.     assert(Memory!=NULL);
  21.    
  22.     wsprintf((*Memory),"0");// Setto il primo byte al carattere '0'.
  23.     while((*Memory)[0]=='0') //Attendo sinché il primo byte non cambia
  24.        {Sleep(1000); printf("Attendo...\n"); }
  25.     printf("Leggo messaggio:\n");
  26.     puts((*Memory)); // Leggo i dati
  27.  
  28.     UnmapViewOfFile(Memory);
  29.     return 0;
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement