#include<Windows.h>
#include<stdio.h>
#include<stdlib.h>
#define BUFFER_SIZE 1024
int main(int argc,LPTSTR argv[]) {
handle_t hRead, hWrite;
DWORD readLength, writeLength;
CHAR buffer[BUFFER_SIZE];
if (argc != 3) {
printf("*****************HELP****************\n");
printf("(1)\n");
printf("\t *.exe file1 file2\n");
return 1;
}
hRead = CreateFile(argv[1],
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hRead == INVALID_HANDLE_VALUE) {
printf("Read File1 Error:%x\n",GetLastError());
return 2;
}
hWrite = CreateFile(argv[2],
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hWrite == INVALID_HANDLE_VALUE) {
printf("Read File2 Error:%x\n", GetLastError());
return 3;
}
while (ReadFile(hRead, buffer, BUFFER_SIZE,&readLength,NULL) && readLength> 0) {
WriteFile(hWrite, buffer, readLength, &writeLength, NULL);
if (readLength != writeLength) {
printf("File size does not match:%x\n", GetLastError());
return 4;
}
}
printf("Success\n");
return 0;
}
《Windows API》文件的复制
最新推荐文章于 2024-05-08 09:00:00 发布