Parameters to CreateFile

  • Thread starter Thread starter Herzl Regev
  • Start date Start date
H

Herzl Regev

What arguments do I need to give CreateFile? I want to open a file or folder
for reading, even if it is already opened from another place. I'm trying:
CreateFile (argv[1], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
but this fails to open folders ("Access is Denied") or files that are
already used (as far as I understand).
 
Thanks. The test opens successfully the file that is supposed to be used
already, and fails to open any directory that I try it on claiming 5: "Access
is denied". What does that mean?
 
Thanks. The test opens successfully the file that is supposed to be used
already, and fails to open any directory that I try it on claiming 5: "Access
is denied". What does that mean?

You have to specify FILE_FLAG_BACKUP_SEMANTICS to open a directory,
the test doesn't do that.

Dave
 
Indeed. It goes in the parameter before last in CreateFile.
(However, the "used" file is still opened by the test but not by my function
call.)
 
Indeed. It goes in the parameter before last in CreateFile.
(However, the "used" file is still opened by the test but not by my function
call.)

I don't understand what you're telling me there.

My test program doesn't use the FILE_FLAG_BACKUP_SEMANTICS option, so
it's not useful for testing opening directories.

Dave
 
I have a file that the test opens successfully, but my CreateFile syscall
fails on it claiming that it's opened by another process. The other process
is Visual Studio and the file is <project>.ncb .
 
I have a file that the test opens successfully, but my CreateFile syscall
fails on it claiming that it's opened by another process.

So what options are you using differently?
The other process is Visual Studio and the file is <project>.ncb .

What are you trying to do?

I would expect VS to open the NCB file exclusively - it's not the sort
of thing that it'd want to be opened by another process.

Dave
 
David Lowndes said:
So what options are you using differently?
None. The same call, except that I added FILE_FLAG_BACKUP_SEMANTICS .
What are you trying to do?
Check the size of the file
I would expect VS to open the NCB file exclusively - it's not the sort
of thing that it'd want to be opened by another process.
So I guess that this solves the problem: What I'm trying to do can't be done
with opening the file. I found that it can probably be done with
GetFileAttributesEx - see
http://blog.kowalczyk.info/kb/get-file-size-under-windows.html .
 
Back
Top