// OpenFile.cpp : Defines the entry point for the console application. // #include #include #include #include #include int _tmain(int argc, _TCHAR* argv[]) { HANDLE h; h = CreateFile ( "C:\\work\\abc.dat", // pointer to name of the file GENERIC_READ | GENERIC_WRITE, // access (read-write) mode 0, // share mode NULL, // pointer to security attributes CREATE_ALWAYS, // how to create FILE_ATTRIBUTE_NORMAL, // file attributes NULL // handle to file with attributes to copy ); if (h == INVALID_HANDLE_VALUE) { std::cout << "Chyba pri otvirani" << std::endl; } else { std::cout << "Soubor otevren" << std::endl; // char buf [] = "Nejaky text"; // DWORD size = strlen (buf); DWORD size = 1024 * 1024; void * buf = calloc (1, size); DWORD answer; BOOL ok; // ok = ReadFile (h, buf, size, &answer, NULL); // answer = read (h, buf, size); /// ok = WriteFile (h, buf, size, &answer, NULL); char * local_buf = (char *) buf; answer = 0; ok = TRUE; while (ok && answer < size) { DWORD local_size = size - answer; DWORD local_answer = 0; ok = WriteFile (h, local_buf, local_size, &local_answer, NULL); if (ok) { std::cout << "Cast zapsana " << local_answer << std::endl; answer += local_answer; local_buf += local_answer; } } if (ok && answer == size) std::cout << "Data zapsana" << std::endl; else std::cout << "Chyba pri zapisu" << std::endl; CloseHandle (h); } char * str = new char [11]; std::cin.getline(str, 10); return 0; }