Parameters to CreateFile

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).
 
H

Herzl Regev

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?
 
D

David Lowndes

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
 
H

Herzl Regev

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.)
 
D

David Lowndes

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
 
H

Herzl Regev

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 .
 
D

David Lowndes

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
 
H

Herzl Regev

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 .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top