Page 1 of 1

Done: Allow for custom file sharing modes

Posted: 14 Apr 2014 01:23
by DieOberzicke
I have a file which I have opened in another process. Although my process should allow other processes to open the file with read access, HxD is unable to open the file, and presents me with the "The process cannot access the file because it is being used by another process" message box.

I believe this is due to the way that HxD is calling CreateFile. This page, states the following:
If you specify an access or sharing mode that conflicts with the modes specified in the previous call, CreateFile fails.
In my process, I am calling CreateFile using (GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ. According to the table on the aforementioned page, HxD would need to call CreateFile using GENERIC_READ, (FILE_SHARE_READ | FILE_SHARE_WRITE), rather than its current GENERIC_READ, FILE_SHARE_READ.

Seeing as the parameters HxD would need to use fully rely on those which were supplied to the initial CreateFile call, the best solution would be to add an option which would allow users to specify a custom dwDesiredAccess and dwShareMode with which to open the file.


Related threads:

Re: Allow for custom file sharing modes

Posted: 15 Apr 2014 17:46
by Maël
The reason is that HxD denies write access temporarily to be sure that the read data is not changed during reading. This is to ensure invariants and avoid spurious/random behavior. So FILE_SHARE_WRITE is not granted on purpose, and having an option would not really solve this issue, unfortunately.

Re: Allow for custom file sharing modes

Posted: 06 Feb 2019 15:14
by Maël
As mentioned in the second link in the original post, this has been relaxed to the most possible degree, with lots of internal changes to use caching and reduce locking to a minimum whenever possible.