There is a code in C:

#include <stdio.h> #include <stdlib.h> #define COPY_BLOCK_SIZE 64 #define PROGRAM_NAME argv[0] #define INPUT_FILE_NAME argv[1] #define OUTPUT_FILE_NAME argv[2] int main(int argc, char ** argv) { unsigned char buf[COPY_BLOCK_SIZE]; FILE * fin, * fout; size_t bytes; if ( argc < 3 ) { fprintf(stderr, "Usage: %s input_file output_file\n", PROGRAM_NAME); getchar(); exit(1); } if ( ! ( fin = fopen(INPUT_FILE_NAME, "rb") ) ) { fprintf(stderr, "%s: can't open %s for input!\n", PROGRAM_NAME, INPUT_FILE_NAME); getchar(); exit(1); } if ( ! ( fout = fopen(OUTPUT_FILE_NAME, "wb") ) ) { fprintf(stderr, "%s: can't open %s for output!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); if ( fclose(fin) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, INPUT_FILE_NAME); getchar(); exit(1); } while ( ( bytes = fread(buf, sizeof(char), COPY_BLOCK_SIZE, fin) ) != (size_t)EOF && bytes > 0 ) { if ( fwrite(buf, sizeof(char), bytes, fout) != bytes ) { fprintf(stderr, "%s: can't write to %s!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); if ( fclose(fin) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, INPUT_FILE_NAME); if ( fclose(fout) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); getchar(); exit(1); } } if ( ferror(fin) ) { fprintf(stderr, "%s: can't readf rom %s!\n", PROGRAM_NAME, INPUT_FILE_NAME); if ( fclose(fin) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, INPUT_FILE_NAME); if ( fclose(fout) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); getchar(); exit(1); } if ( fclose(fin) ) { fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, INPUT_FILE_NAME); if ( fclose(fout) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); getchar(); exit(1); } if ( fclose(fout) ) { fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); getchar(); exit(1); } fprintf(stderr, "Done.\n"); getchar(); exit(0); } 

Please help me redo it so that the features of the Win32 API are used. That is, in order for the variables to be WINAPI-shnyh types (DWORD, CHAR, etc.), analogs of functions from windows.h of the type CreateFile, WriteFile (Only not CopyFile :) must be used manually) were used. And then in Vinapi neither boom boom, but urgently needed. Thank.

  • @Izobara, According to the rules of the forum, questions should not be limited to solving or completing student assignments. Please clarify what you have done yourself and what did not work out. - Nicolas Chabanovsky
  • @Expert, oddly enough, the code must be written in two ways - plain C and Win32 API. The first as if, the second - I do not know how. - Bringoff
  • @Izobara, HashCode is not a freelance exchange or a place to help with training tasks. If you have a specific question, ask. What you publish is not a question, it is a work for the author. - Nicolas Chabanovsky
  • @Expert, yes ... you can't sit by yourself - nobody will help. gist.github.com/e7f91eb7c4134e4c5050.git And you just had to change functions and types in a couple of places in comparison. - Bringoff

1 answer 1

In short, here, I picked it myself:

 #include <stdio.h> #include <stdlib.h> #include <windows.h> #define COPY_BLOCK_SIZE 64 #define PROGRAM_NAME argv[0] #define INPUT_FILE_NAME argv[1] #define OUTPUT_FILE_NAME argv[2] int main(int argc, LPTSTR argv []) { CHAR buf[COPY_BLOCK_SIZE]; HANDLE hin, hout; DWORD bytes; if ( argc < 3 ) { fprintf(stderr, "Usage: %s input_file output_file\n", PROGRAM_NAME); getchar(); exit(1); } if ( ( hin = CreateFile (argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL )) == INVALID_HANDLE_VALUE ) { fprintf(stderr, "%s: can't open %s for input!\n Error: %x\n", PROGRAM_NAME, INPUT_FILE_NAME, GetLastError()); getchar(); exit(1); } if ( ( hout = CreateFile (argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL )) == INVALID_HANDLE_VALUE ) { fprintf(stderr, "%s: can't open %s for output!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); if ( ! CloseHandle(hin) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, INPUT_FILE_NAME); getchar(); exit(1); } while ( ReadFile(hin, buf, COPY_BLOCK_SIZE, &bytes, NULL ) && bytes > 0 ) { if ( ! WriteFile ( hout, buf, bytes, &bytes, NULL )) { fprintf(stderr, "%s: can't write to %s!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); if ( ! CloseHandle(hin) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, INPUT_FILE_NAME); if ( ! CloseHandle(hout) ) fprintf(stderr, "%s: can't properly close %s!\n", PROGRAM_NAME, OUTPUT_FILE_NAME); getchar(); exit(1); } } fprintf(stderr, "Done.\n"); getchar(); exit(0); }