IPlatformFile (Windows) OpenWrite/OpenRead Access Errors


I am trying to use the IFileHandle for my own personal extension to our game. My project file structure requires both and Write access, and I noticed in the code that it is only using “Shared” Write/ access therefore causing both…

[2015.08.19-00.08.15:481][461]UdbLog:Warning: ReadFile failed: Count=0 BufferCount=188 Error=Access is denied.
I had a FLUSH error saying Access Denied as well.

So is there a way to Open a File for both " and Write"? AKA /Write Access (NOT Shared Access) as that isn’t helping the issue…

The only work around I thought of was to just have to File Handles of the same file, now I don’t like this idea because one file handle may have different size positioning while the other has another, so therefore I have to keep track of the file handling in a different way, hopefully a solution to this problem will be fixed for a long term solution.

Hey Ravenal-

Could you elaborate on what you mean by shared /write access? Looking at the source files I see the functions for () and Write(), both of which are pure virtual and would need to be overriden in a child class to use. How are you implementing these functions in your case?



Instead of writing a comment I decided to answer this question as a work around but it is something I didn’t want to do but maybe you guys can implement that might not just help me and others in the future.

I ran into problems with my attempted first work-around, and had to create my own customized FileHandle interface that goes off of IFileHandle. Then I had to create our own support of window calls.

There are a few things that I really needed that wasn’t provided that I think for pure customization of file systems. Right now I am working on using Binary Tree structure much like how a database works. But instead of using “SQL” which is something that I don’t want to do, it is more of an Index/Data Block Database that allows me to access data in real time between file/IO etc. We are using this for the purpose of real time caching and allowing the reduction of using so much ram for our game.

Windows based of course is SetEndOfFile which basically allows me to truncate the entire file and reset the position/length to be 0 byte size without having to close the handle. In C# this is called by the SetLength function which allows me to Set the Length to and then position offset the Seek to a new position in the file.

The other problem I had was with the FArchive was I could NOT seek beyond a position within a /write environment. I had to create a new handle therefore making it so that when a new file is created I extended it to be (adjusted above to show you what I had to do).

So this is what I had to do:

I added my own “OpenFile” method that is static part of my FileHandle that I overrided, I basically did something along the line below:

class IMyFileHandle : public IFileHandle {
	virtual bool SetLength(int64 offset = 0) = 0;

To extend for SetLength function

Then I added the OpenFile static function which looks like this:

FORCEINLINE static IUdbFileHandle* OpenFile(const TCHAR* Filename) {
		uint32  Access = GENERIC_READ | GENERIC_WRITE;
		uint32  WinFlags = FILE_SHARE_READ;
		uint32  Create = OPEN_ALWAYS;
		HANDLE H = CreateFileW(*NormalizeFilename(Filename), Access, WinFlags, NULL, Create, FILE_ATTRIBUTE_NORMAL, NULL);
			return new MyFileHandle(H);
		return nullptr;

As you can see it looks exactly like the one within the IPlatformFile OpenWrite and OpenRead. Only difference is I used the OpenWrite directly , and made it so that it OPEN_ALWAYS. ALong with GENERIC_READ | GENERIC_WRITE which allows me to Write/ on the same Handle where as OpenRead only has GENERIC_READ and OpenWrite has only GENERIC_WRITE which caused me to have cannot or cannot write exceptions.

Doing this worked fine for me, but I would really prefer to be able to control this much better. If you have questions just please don’t hesitate to ask me I wouldn’t mind.