Chinaunix首页 | 论坛 | 博客
  • 博客访问: 515057
  • 博文数量: 158
  • 博客积分: 4015
  • 博客等级: 上校
  • 技术积分: 1711
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-27 14:00
文章分类

全部博文(158)

文章存档

2010年(71)

2009年(87)

我的朋友

分类: WINDOWS

2009-10-14 21:14:25

我刚看的时候很晕:
《windows系统编程》这本书需要巨量的google...
 

#include <windows.h>
#include <stdio.h>
#define BUF_SIZE 256
int main(int argc, LPTSTR argv[]) {
  HANDLE hIn, hOut;
  DWORD nIn, nOut;
  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, &nIn, NULL) && nIn > 0) {
    WriteFile(hOut, Buffer, nIn, &nOut, NULL);
    if(nIn != nOut) {
      printf("Fatal write error: %x\n", GetLastError());
      return 4;
    }
  }

  CloseHandle(hIn);
  CloseHandle(hOut);
  return 0;
}


阅读(699) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~