File Locking
With current versions of Objective Edit, the file is only opened for short bursts during the file read and file write processes and is immediately closed afterward. Since the file is no longer kept open for editing, there are no functions comparable to SECEdit::SetFileLocking() and SECEdit::GetFileLocking() in early versions of Objective Edit. If you want to prevent behavior in which a user opens a file, makes many changes, and then is prevented from saving the changes because some other process locked the file, take a look at the following code.
// This is a CDocument class override.
OnOpenDocument(LPCTSTR lpszPathName)
// Open it for exclusive write until the file is saved.
// Otherwise some other process may open the file for write,
// causing a failure in OnSaveDocument.
// This makes up for SECEdit::SetFileLocking being removed in
// recent versions of Objective Edit.
unsigned int uiErrorMode;
m_hFile = CreateFile(lpszPathName,
OPEN_EXISTING, // existing file only
return m_Edit.ReadFile(lpszPathName);
OnSaveDocument(LPCTSTR lpszPathName)
// ready to write, close saved file handle so OE can reopen the
// file with exclusive write access
m_hFile = NULL;
return m_Edit.SaveFile(lpszPathName);
NOTE >> Consider re-opening (locking) the file after writing and finally releasing the lock in the OnCloseDocument(). This will keep the file locked the entire time it is open for editing. Also, new files that are created will remain locked after they are saved and will be released only after they are closed.