[[mmap]]
 
 
// ConsoleApplication5.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
 
#undef UNICODE
#include "windows.h"
 
#include <iostream>
#include <string>
using namespace std;
 
int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE h = CreateFile 
               ("C:\\temp\\abc.txt", // lpFileName,
                GENERIC_READ | GENERIC_WRITE, // dwDesiredAccess,
                0, // dwShareMode,
                NULL, // lpSecurityAttributes,
                CREATE_ALWAYS, //  dwCreationDisposition,
                FILE_ATTRIBUTE_NORMAL, //   dwFlagsAndAttributes,
                NULL); // _In_opt_ HANDLE                hTemplateFile
 
    if (h != INVALID_HANDLE_VALUE)
    {
         cout << "Otevreno" << endl;
 
         HANDLE m = CreateFileMapping (h,
                                       NULL, // security attr
                                       PAGE_READWRITE,
                                       0, // size (high)
                                       16*1024, // size (low)
                                       NULL); // name
 
         if (m != NULL)
         {
            cout << "Temer zobrazeno" << endl;
 
            void * p = MapViewOfFile (m, 
                                      FILE_MAP_READ | FILE_MAP_WRITE,
                                      0, // position (high)
                                      0, // position (low)
                                      4*1024); // size
            if (p != NULL)
            {
               cout << "Zobrazeno" << endl;
 
               char * c = (char *) p;
               c[0] = 'A';
               c[1] = 'B';
               c[2] = 'C';
 
               UnmapViewOfFile (p);
            }
 
            CloseHandle (m);
         }
 
 
         CloseHandle (h);
    }
 
    cout << "Stop" << endl;
 
    char s [2];
    cin.getline (s, sizeof (s));
    return 0;
}
 
mmap.txt · Last modified: 2017/05/05 11:07 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