␉// Open the source␍␊ |
␉// A little RAII␍␊ |
␉{␍␊ |
␉FileWrapper src(args[1], GENERIC_READ, OPEN_EXISTING);␍␊ |
␉if (GetLastError() == ERROR_FILE_NOT_FOUND)␍␊ |
␉{␍␊ |
␉␉WriteStr("Could not find file!");␍␊ |
␉␉return 0;␍␊ |
␉}␍␊ |
␉␉FileWrapper src(args[1], GENERIC_READ, OPEN_EXISTING);␍␊ |
␉␉if (GetLastError() == ERROR_FILE_NOT_FOUND)␍␊ |
␉␉{␍␊ |
␉␉␉WriteStr("Could not find file!");␍␊ |
␉␉␉return 0;␍␊ |
␉␉}␍␊ |
␍␊ |
␉// Open destination file␍␊ |
␉FileWrapper dst(args[2], GENERIC_WRITE, CREATE_ALWAYS);␍␊ |
␉␍␊ |
␉DWORD numberofbytesread;␍␊ |
␉DWORD numberofbyteswritten;␍␊ |
␉char buffer[20];␍␊ |
␉␉// Open destination file␍␊ |
␉␉FileWrapper dst(args[2], GENERIC_WRITE, CREATE_ALWAYS);␍␊ |
␉␉␍␊ |
␉␉DWORD numberofbytesread;␍␊ |
␉␉DWORD numberofbyteswritten;␍␊ |
␉␉char buffer[20];␍␊ |
␍␊ |
␉// Stream the file instead of reading it into memory␍␊ |
␉while(true)␍␊ |
␉{␍␊ |
␉␉// The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array␍␊ |
␉␉// http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx␍␊ |
␉␉ReadFile(src.getHandle(), buffer, 20, &numberofbytesread, NULL); // http://stackoverflow.com/questions/12655120/readfile-function-from-win32-api␍␊ |
␉␉if (numberofbytesread == 0)␍␊ |
␉␉␉break;␍␊ |
␉␉WriteFile(dst.getHandle(), buffer, numberofbytesread, &numberofbyteswritten, NULL);␍␊ |
␉}␍␊ |
␉␉// Stream the file instead of reading it into memory␍␊ |
␉␉while(true)␍␊ |
␉␉{␍␊ |
␉␉␉// The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array␍␊ |
␉␉␉// http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx␍␊ |
␉␉␉ReadFile(src.getHandle(), buffer, 20, &numberofbytesread, NULL); // http://stackoverflow.com/questions/12655120/readfile-function-from-win32-api␍␊ |
␉␉␉if (numberofbytesread == 0)␍␊ |
␉␉␉␉break;␍␊ |
␉␉␉WriteFile(dst.getHandle(), buffer, numberofbytesread, &numberofbyteswritten, NULL);␍␊ |
␉␉}␍␊ |
␉}␍␊ |
␉␍␊ |
␉std::vector<wchar_t> wstr;␍␊ |