Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, LPTSTR argv[])
- {
- using std::cin;
- using std::cout;
- HANDLE hIn, hOut;
- DWORD nIn, nOut;
- CHAR Buffer[BUF_SIZE];
- if (argc != 3) {
- cout << "Using: cpW file1 file2n";
- return 1;
- }
- hIn = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
- if (hIn == INVALID_HANDLE_VALUE) {
- cout << "Can't open source file. Error: ";
- cout << GetLastError();
- return 2;
- }
- hOut = CreateFile(argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hOut == INVALID_HANDLE_VALUE) {
- cout << "Can't open destination file. Error: ";
- cout << GetLastError();
- return 3;
- }
- else cout << "nDONE!";
- while (ReadFile(hIn, Buffer, BUF_SIZE, &nIn, NULL)) {
- WriteFile(hOut, Buffer, nIn, &nOut, NULL);
- if (nIn != nOut) {
- cout << "Error" << GetLastError();
- return 4;
- }
- }
- CloseHandle(hIn);
- CloseHandle(hOut);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement