惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
月光博客
月光博客
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
U
Unit 42
腾讯CDC
爱范儿
爱范儿
J
Java Code Geeks
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
B
Blog
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - wolflion

《UNIX-Shell编程24学时教程》读书笔记Chap3,4 文件,目录操作 《UNIX-Shell编程24学时教程》读书笔记Chap1,2 Shell基础,脚本基础 《UNIX-Shell编程24学时教程》读书笔记chap7 变量 《软件调试的艺术》读书笔记 ubuntu环境准备 ftp的实现 icmp的程序(ping的实现) cp命令 who命令 苦逼IT才能看懂的笑话 debug和release版区别 i5处理器的台式机[百度知道] 关于轮胎尺寸问题 常见内核数据结构.doc windows 系统编程 Chap7 线程和调度 EVRYTHNG.H Windows系统编程chap6 Windows系统编程 chap5 booklist 转
windows code
wolflion · 2013-05-03 · via 博客园 - wolflion

#include <Windows.h>
#include <stdio.h>
#define BUF_SIZE 256

int main(int argc, LPTSTR argv[])
{
HANDLE hIn, hOut;
DWORD dIn, dOut;
CHAR Buffer[BUF_SIZE];

if (argc != 3)
{
printf("Usage: cpW file1 file2\n");
return 1;
}

hIn = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hIn == INVALID_HANDLE_VALUE)
{
printf("Cannot open input file. Error:%x\n", GetLastError());
return 2;
}

hOut = CreateFile(argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

if (hOut == INVALID_HANDLE_VALUE)
{
printf("Cannot open output file. Error:%x\n", GetLastError());
return 3;
}

while(ReadFile(hIn, Buffer, BUF_SIZE, &hIn, NULL) && hIn > 0)
{
WriteFile(hOut, Buffer, hIn, &hOut, NULL);
if (hIn != hOut)
{
printf("Fatal write error: %x\n", GetLastError() );
return 4;
}
}
CloseHandle(hIn);
CloseHandle(hOut);
return 0;
}