#include "rapi.h"
#pragma comment(lib,"D:\\My Documents\\Visual Studio 2005\\Projects\\copy12\\copy12\\rapi.lib")
//BUFFER_SIZE 1024
void CopyFilePCtoWinCE(CString strFileNamePC, CString strFileNamePPC)
{
CFile oldFile;
oldFile.Open(strFileNamePC, CFile::modeRead |CFile::typeBinary);
int iLen = oldFile.GetLength();
iLen = iLen / BUFFER_SIZE;
BSTR bstr = strFileNamePPC.AllocSysString();
SysFreeString(bstr);
CeRapiInit();
HANDLE h = CeCreateFile(bstr, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
char cTemp[BUFFER_SIZE];
DWORD nbytes;
int iTotBytes = 0;
int iReaded=0;
while((iReaded=oldFile.Read(&cTemp, BUFFER_SIZE)) >= 1)
CeWriteFile(h, &cTemp, (DWORD)iReaded, &nbytes, NULL);
CeCloseHandle(h);
oldFile.Close();
CeRapiUninit();
}
void CopyFileWinCEtoPC(CString strFileNamePPC, CString strFileNamePC)
{
BSTR bstr = strFileNamePPC.AllocSysString();
SysFreeString(bstr);
CeRapiInit();
HANDLE h;
h = CeCreateFile(bstr, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
CFile oldFile;
oldFile.Open(strFileNamePC, CFile::modeCreate | CFile::modeWrite);
char cTemp[BUFFER_SIZE];
DWORD nbytes;
CString s;
while(CeReadFile(h, &cTemp, (DWORD)BUFFER_SIZE, &nbytes, NULL) == TRUE)
{
oldFile.Write(&cTemp, nbytes);
if(nbytes < BUFFER_SIZE)
break;
}
CeCloseHandle(h);
oldFile.Close();
CeRapiUninit();
}
BOOL DeleteFileFromCE(CString strFileNamePPC)
{
BSTR bstr = strFileNamePPC.AllocSysString();
SysFreeString(bstr);
CeRapiInit();
BOOL bRet = CeDeleteFile(bstr);
CeRapiUninit();
return bRet;
}