[[memmap]]
 
 
#include "stdafx.h"
#include <windows.h>
 
int _tmain (int argc, _TCHAR* argv[])
{
	HANDLE f = CreateFile 
		         ("C:\\temp\\abc.txt",
		          GENERIC_READ | GENERIC_WRITE,
			  0, // no sharing
			  NULL, // no security attributes
			  OPEN_ALWAYS,
			  FILE_ATTRIBUTE_NORMAL,
			  NULL // no template
			  );
 
	if (f != INVALID_HANDLE_VALUE)
	{
		printf ("Soubor otevren \n");
 
		HANDLE m = CreateFileMapping
			       (f, // file handle
 			        NULL, // no security attributes
				PAGE_READWRITE,
				0, // high
				16*1024, // low
				NULL // name
				);
 
		if (m != NULL)
		{
   		     printf ("Zobrazeni souboru vytvoreno \n");
 
 		     void * p = MapViewOfFile 
			        (m, 
			         FILE_MAP_READ | FILE_MAP_WRITE,
				 0, // pos high
				 0, // pos low
				 12*1024 // length
				 );
 
			 if (p != NULL)
			 {
      		                 printf ("Cast souboru zobrazena do pameti \n");
 
				 char * c = (char *) p;
				 c[0] = 'A';
				 c[1] = 'B';
				 c[2] = 'C';
				 // printf ("Druhe pismeno je %c \n", c[1]);
 
				 UnmapViewOfFile (p);
			 }
 
 
			 CloseHandle (m);
		}
 
		CloseHandle (f);
	}
 
 
 
	printf ("konec");
	char s [80];
	scanf_s ("%s", s);
	return 0;
}
 
memmap.txt · Last modified: 2014/04/30 14:49 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki