// 파일 두개를 합쳐서 하나의 파일에 복사
#include <Windows.h>
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
int _tmain (int argc, LPCTSTR argv[])
{
HANDLE hIn1, hIn2 , hOut;
DWORD nIn1, nIn2, nOut;
TCHAR buffer[256];
_tsetlocale(LC_ALL , _T("korean"));
if(argc != 4)
{
_tprintf(_T("error1"));
return 1;
}
hIn1 = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hIn1 == INVALID_HANDLE_VALUE)
{
_tprintf(_T("error2"));
CloseHandle(hIn1);
return 2;
}
hIn2 = CreateFile(argv[2], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hIn2 == INVALID_HANDLE_VALUE)
{
_tprintf(_T("error3"));
CloseHandle(hIn1);
CloseHandle(hIn2);
return 2;
}
hOut = CreateFile(argv[3], GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hOut == INVALID_HANDLE_VALUE)
{
_tprintf(_T("error4"));
CloseHandle(hIn1);
CloseHandle(hIn2);
CloseHandle(hOut);
return 3;
}
while(ReadFile(hIn1,buffer, 256, &nIn1,NULL)&& nIn1 >0)
{
WriteFile(hOut, buffer, nIn1, &nOut,NULL);
if(nIn1 != nOut)
{
_tprintf(_T("error5"));
CloseHandle(hIn1);
CloseHandle(hOut);
return 4;
}
}
while(ReadFile(hIn2,buffer, 256, &nIn2,NULL)&& nIn2 >0)
{
WriteFile(hOut, buffer, nIn2, &nOut,NULL);
if(nIn2 != nOut)
{
_tprintf(_T("error6"));
CloseHandle(hIn1);
CloseHandle(hIn2);
CloseHandle(hOut);
return 5;
}
}
_tprintf(_T("굿\n"));
CloseHandle(hIn1);
CloseHandle(hIn2);
CloseHandle(hOut);
return 6;
}
'Programming > Windows&C#' 카테고리의 다른 글
[Windows/WinAPI] Polymorphic 자료형 (0) | 2013.10.03 |
---|---|
[Windows/WinAPI] FindFirstFile , FileTimeToSustemTime, FindNextFile (실습3) (0) | 2013.09.27 |
[Windows/WinAPI] 윈도우 시스탬 프로그래밍 실습 01 (0) | 2013.09.06 |
[Windows/WDM] 드라이버 스택 코드 이해 (0) | 2013.07.30 |
[Windows/WDM] 드라이버 (0) | 2013.07.28 |