I am simply after in one process being able to prevent someone else opening a file whilst I am reading it. I do not have control over the opening of the file as this is done within the Xerces library. The file is an xml file hence the use of xerces. Once I have completed the read I want to sometimes delete the file.
Ideally I would have like to in my process
Check I have exclusive rights to the file
Read it using xerces
A Simple work around to your problem would be use your original code to get the exclusive access to file,
Read the file and create a temporary file which you can pass it to Xerces.. later delete the temp file.. and if you want delete even the source/original file.
Other alternatives could be to check if xerces takes text(some temp buffer) as input instead of file name.. so you can read the file in buffer and pass it to xerces.
I do not have control over the opening of the file as this is done within the Xerces library.
In that case there is nothing you can do to gain exclusive access to it. I have no experience of the Xerces library, but are you sure there is no option to pass the handle of a previously opened file into it?
One of these days I'm going to think of a really clever signature.