I got a strange problem.
When my program starts, it reads a file, loads it and closes it again. when i want to open the file with WRITE_ACCESS later again, i get ERROR_SHARING_VIOLATION. if i try to delete the file, i get ERROR_ACCESS_DENIED. but i am 100% SURE that i did close the file handle when i opened it real quick at the beginning of the program to load it. so at the beginning i open a file, close its handle, later i try to open the file again, but i get these errors above. what is this? i can open the file with read only, but if i try to get write access, i get these errors.

At the beginning i use
Later i use
(since i will rewrite the whole file, i use CREATE_ALWAYS).

Does anybody have an idea whats going on there? i've tested this on win95 and win98. it didn't work on both.
Posted on 2002-02-07 08:24:55 by darester
What version of windows are you using?
Are you really sure that you've closed the file?
Posted on 2002-02-07 11:06:32 by bitRAKE
Do you have this part of your code CloseHandle (HandleToTheFile)?
Posted on 2002-02-07 12:20:47 by stryker
Are you sure what our opening can be written to, you can open and read from the local executable but not write to it.
Posted on 2002-02-07 15:13:46 by Quantum
oh well, i just found out, that CloseHandle() always fails when i try to close the file after reading it at the beginning.
but i have no idea why it fails. i read some parts of the file, then i pass the file handle to a function BY VALUE, not BY REFERENCE, so that this function can read some information from the current position of the file pointer. when the function returns, the file handle should be closed, but CloseHandle fails. the file handle isn't changed in any way by the called function. it is the same as it was before. so why does CloseHandle() fail? I get ERROR_INVALID_HANDLE. but the handle shouldn't become invalid because it isn't changed.

I also found out, that, if i close the file handle immediately after the last ReadFile Operation, it works. but i don't want to immediately close the file handle after the last ReadOperation.
Posted on 2002-02-08 05:03:20 by darester
Post a small snippet of code that illustrates your problem.
Posted on 2002-02-08 12:46:16 by f0dder