CMirrorFile - An undocumented MFC tale.

转载 2008年10月01日 05:00:00

Did you ever heard about CMirrorFile? No chance. Because its an undocumented MFC class. It’s also used for file operations. We can write, delete do anything to a file by using CMirrorFile. But if you wish you can rollback the changes at any point before committing. Seems interesting?

In CMirrorFile, you can open a file like CFile and you can do as may operations. All the changes will be committed only if you call CMirrorFile::Close(). If you want to rollback the changes, then call CMirrorFile::Abort(). See the code snippet. Its self explanatory.

#include "afxpriv.h"
CMirrorFile MirrorFile;
MirrorFile.Open( _T("C://Database.txt"),
CFile::modeCreate | CFile::modeReadWrite );

// Do as many operations as you want.
// Truncate current file.
MirrorFile.SetLength( 0 );

// Write the file content.
CString FileContent = _T("File modified by using CMirrorFile.");
MirrorFile.Write( (LPCTSTR)FileContent, FileContent.GetLength());

// Decide whether to abort or not.
bool bAbort = false;

if( bAbort )
// Abort the changes.
// The source file will be the same.
// Close and commit the changes.

Actually when we open a file using CMirrorFile, Its really creating a temporary file. All the further changes that you apply is updated to the temporary file copy. When you call Close(), CMirrorFile, updates the temporary file copy, then replaces the master file with temporary file by using api - ReplaceFile(). When you call Abort(), CMirrorFile just deletes that temporary copy of file.

Cool! You can use CMirrorFile, if you want to do several operations without damaging the main file and can commit only if you need or else you are free to rollback at any point.

Targeted Audience - Intermediate.

RNNs in Tensorflow, a Practical Guide and Undocumented Features

In a previous tutorial series I went over some of the theory behind Recurrent Neural Networks (RNN...
  • omnispace
  • omnispace
  • 2017年10月10日 01:34
  • 173

VS2010-Incremental Linker File增量连接文件和Program Debuge Dtatbase程序调试信息库文件

一个project采用release/debuge来生成,是很有差别的,我试了一下采用debuge并选择“Use MFC shared DLL”产生的exe文件大小为161KB,采用release并选...
  • pcliuguangtao
  • pcliuguangtao
  • 2010年10月04日 12:16
  • 3955

关于windows 核心的经典书籍

前两天,在网上找关于window内核的书籍,,发现这个地方不错,有好几本,据说都是经典,据说而已:)本人对这些书都没有看过:(,,不过先放出来,,希望像我一样找得这么辛苦的朋友能够看到,呵呵。。。。 ...
  • bshawk
  • bshawk
  • 2006年04月28日 15:05
  • 2107

code force. Anton and fairy tale.

题目: C. Anton and Fairy Tale time limit per test 1 second memory limit per test 256 mega...
  • Nice_punch
  • Nice_punch
  • 2017年03月22日 23:39
  • 87

Undocumented Extended and Stored Procedures

    Undocumented Extended and Stored ProceduresBy Timothy A Wiseman, 2008/05/09 IntroductionThere ar...
  • grandtree
  • grandtree
  • 2009年04月20日 19:39
  • 554

Undocumented System Stored Procedures

System stored proceduresThis document contains information on undocumented stored procedures in Micr...
  • sunshine_anycall
  • sunshine_anycall
  • 2008年08月07日 13:35
  • 379

Undocumented MessageBoxTimeOut function

From: There are lots of neat little things that ...
  • fisher_jiang
  • fisher_jiang
  • 2009年07月02日 21:26
  • 1086

WebLogic undocumented hacking

During an external pentest – what a surprise – I found a WebLogic server with no interesting content...
  • cnbird2008
  • cnbird2008
  • 2014年11月10日 14:25
  • 728

WCE7- New and Undocumented Features

The following features are new or undocumented for this release. Browser New Features New user inter...
  • jw212
  • jw212
  • 2010年09月09日 14:46
  • 1523

Oracdebug ( Undocumented Utility )

Oracdebug ( Undocumented Utility ) 改天读~  September 11th, 2008 | Author: adminReading time: 4 - 6 mi...
  • tech2011
  • tech2011
  • 2010年10月26日 18:03
  • 226
您举报文章:CMirrorFile - An undocumented MFC tale.