随笔 - 74, 文章 - 0, 评论 - 26, 引用 - 0
数据加载中……

(转)Rapi 使用

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


posted on 2007-11-20 08:46 井泉 阅读(1267) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理