Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. int main(int argc, LPTSTR argv[])
  2. {
  3. using std::cin;
  4. using std::cout;
  5.  
  6. HANDLE hIn, hOut;
  7. DWORD nIn, nOut;
  8. CHAR Buffer[BUF_SIZE];
  9.  
  10. if (argc != 3) {
  11. cout << "Using: cpW file1 file2n";
  12. return 1;
  13. }
  14.  
  15. hIn = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
  16. if (hIn == INVALID_HANDLE_VALUE) {
  17. cout << "Can't open source file. Error: ";
  18. cout << GetLastError();
  19.  
  20. return 2;
  21. }
  22. hOut = CreateFile(argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  23. if (hOut == INVALID_HANDLE_VALUE) {
  24. cout << "Can't open destination file. Error: ";
  25. cout << GetLastError();
  26.  
  27. return 3;
  28. }
  29. else cout << "nDONE!";
  30.  
  31. while (ReadFile(hIn, Buffer, BUF_SIZE, &nIn, NULL)) {
  32. WriteFile(hOut, Buffer, nIn, &nOut, NULL);
  33. if (nIn != nOut) {
  34. cout << "Error" << GetLastError();
  35. return 4;
  36. }
  37. }
  38.  
  39. CloseHandle(hIn);
  40. CloseHandle(hOut);
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement