/* Handle.cpp */
#undef UNICODE
#include <windows.h> // CreateFile, ...
#include <stdio.h> // printf, scanf
int main (int argc, char * argv [])
{
HANDLE h =
CreateFile
("abc.TXT", // pointer to 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 (h == INVALID_HANDLE_VALUE)
{
int n = GetLastError ();
printf ("CHYBA %d", n);
}
else
{
char pole [] = "ABCD";
DWORD delka = 4;
DWORD odpoved;
BOOL b = WriteFile (h, pole, delka, &odpoved, NULL);
if (! b || odpoved != delka)
printf ("CHYBA PRI ZAPISU \n");
else
printf ("POVEDLO SE TO \n");
CloseHandle (h);
}
/*
ReadFile
WriteFile
FileSeek
CloseHandle
CreateFileMapping
*/
printf ("Stiskni enter \n");
char c;
scanf_s ("%c", &c);
return 0;
}
small.vcproj