Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <Windows.h>
- #include <strsafe.h>
- #include <tchar.h>
- #define _UNICODE
- #define UNICODE
- int _tmain(int argc, TCHAR *argv[])
- {
- char *buffer;
- if (argc == 4)
- {
- char *p;
- int number_of_bytes = strtol(argv[3], &p, 10);
- printf("Number of bytes to read is %d", number_of_bytes);
- printf("\n%s\n%s", argv[1], argv[2]);
- DWORD dwBytesWritten = 0;
- buffer = (char*)malloc(number_of_bytes * sizeof(char));
- HANDLE h = CreateFile(argv[1], // file to open
- GENERIC_READ, // open for reading
- 0, // share for reading
- NULL, // default security
- OPEN_EXISTING, // existing file only
- FILE_ATTRIBUTE_NORMAL, // normal file
- NULL); // no attr. template
- //DWORD a = GetLastError();
- //if (a) { printf("\nWriting to the File error is: %d", a); }
- ReadFile(h, buffer, number_of_bytes, NULL, NULL);
- DWORD c = GetLastError();
- if (c) { printf("\nReading to the File error is: %d", c); }
- CloseHandle(h);
- DWORD dwBytesToWrite = (DWORD)strlen(buffer);
- //printf("%s\n\n", buffer);
- //printf("The size of the buffer is %d", sizeof(buffer));
- HANDLE file_write = CreateFile(argv[2], GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- DWORD last_error = GetLastError();
- if (last_error){ printf("\nFile to write error is: %d", last_error); }
- WriteFile(file_write, buffer, dwBytesToWrite, &dwBytesWritten, NULL);
- DWORD b = GetLastError();
- if(b){ printf("\nWriting to the File error is: %d", b); }
- CloseHandle(file_write);
- scanf("%d");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement