Answer the question
In order to leave comments, you need to log in
WinAPI: Write Access Violation. How to fix?
Task:
1. Check if the current directory contains the file Example1.txt /
2. if so, copy it to the file Mycopy.txt before copying, check that there is space on the disk for this file.
3. Display this file in portions of 2-4Kb, considering this file as a text file.
My clumsy code:
#include "windows.h"
#include <iostream>
using namespace std;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
setlocale(LC_ALL, "Russian");
char buffer[100];
HANDLE myfile;
bool isSucceed;
myfile = CreateFile(L"myfile.txt", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
isSucceed = ReadFile(myfile, buffer, 10, 0, NULL);
CloseHandle(myfile);
if (!isSucceed) {
return NULL;
}
else {
HANDLE copy;
copy = CreateFile(L"copy.txt", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(copy, buffer, 100, 0, NULL);
}
system("pause");
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question