`
ychw365
  • 浏览: 53118 次
  • 性别: Icon_minigender_1
  • 来自: 长春
最近访客 更多访客>>
社区版块
存档分类
最新评论

RAPI

 
阅读更多

#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;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics