Hi,
I'm trying to do something like this: I lock file, so no other process can read from it, then I modify its contents, save it and release lock.

This is Borland C++ Builder 6

Code:
HANDLE hFile = CreateFile("c:\\prjSettings.xml", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);

if (hFile == INVALID_HANDLE_VALUE)
    {
    //error
    }

OVERLAPPED o;
memset(&o, 0, sizeof(o));

bool isLocked = LockFileEx(hFile, 0, 0, 999999, 999999, &o);

_di_IXMLDocument prjSettDoc = LoadXMLDocument((WideString)"c:\\prjSettings.xml");
//do something with prjSettDoc and save it
prjSettDoc->SaveToFile((WideString)"c:\\prjSettings.xml");

UnlockFileEx(hFile, 0, 999999, 999999, &o);
CloseHandle(hFile);
LoadXMLDocument gives me exception: "Project Project1.exe raised exception class EOleException with message 'The process cannot access the file because it is beeing used by another process'. Use Step or Run to continue."

Why is this happening? Is there other way to lock access to file while it is beeing modified?