标题:求教程序功能
取消只看楼主
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
结帖率:79.17%
 问题点数:0 回复次数:0 
求教程序功能
void CPe::ModifyPe(CString strFileName,CString strMsg)
{
    CString strErrMsg;

    HANDLE hFile, hMapping;
    void *basepointer;
    
    // 打开要修改的文件.
    if ((hFile = CreateFile(strFileName, GENERIC_READ|GENERIC_WRITE,
        FILE_SHARE_READ|FILE_SHARE_WRITE, 0,
        OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0)) == INVALID_HANDLE_VALUE)
    {
        AfxMessageBox("Could not open file.");
        return;
    }

    // 创建一个映射文件.
    if (!(hMapping = CreateFileMapping(hFile, 0, PAGE_READONLY | SEC_COMMIT, 0, 0, 0)))
    {
        AfxMessageBox("Mapping failed.");
        CloseHandle(hFile);
        return;
    }

    // 把文件头映象存入baseointer.
    if (!(basepointer = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0)))
    {
        AfxMessageBox("View failed.");
        CloseHandle(hMapping);
        CloseHandle(hFile);
        return;
    }

    CloseHandle(hMapping);
    CloseHandle(hFile);

    CalcAddress(basepointer); // 得到相关地址.
    UnmapViewOfFile(basepointer);
    
    if(dwSpace<50)
    {
        AfxMessageBox("No room to write the data!");
    }
    else
    {
        WriteFile(strFileName,strMsg); // 写文件.
    }
    
    if ((hFile = CreateFile(strFileName, GENERIC_READ|GENERIC_WRITE,
        FILE_SHARE_READ|FILE_SHARE_WRITE, 0,
        OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0)) == INVALID_HANDLE_VALUE)
    {
        AfxMessageBox("Could not open file.");
        return;
    }
    
    CloseHandle(hFile);

}
上述红色部分代码由什么作用呀??
怎么 刚刚打开一个文件,什么也没有操作,则又将其关闭了 ??
搜索更多相关主题的帖子: CreateFile CloseHandle CreateFileMapping 
2008-10-14 01:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-238109-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.313202 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved