Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2007

Tip: Looking for answers? Try searching our database.

Parameters to CreateFile

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Herzl Regev - 27 Nov 2007 14:56 GMT
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).
David Lowndes - 27 Nov 2007 16:44 GMT
>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.

You can only do that if the "other place" has also allowed sharing.

I have a simple test application for the CreateFile API that I use for
checking such scenarios:
http://www.jddesign.f2s.com/freeware_programs.htm#CFTest

Dave
Herzl Regev - 27 Nov 2007 23:49 GMT
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?

> I have a simple test application for the CreateFile API that I use for
> checking such scenarios:
> http://www.jddesign.f2s.com/freeware_programs.htm#CFTest
>
> Dave
David Lowndes - 28 Nov 2007 07:58 GMT
>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
Herzl Regev - 28 Nov 2007 11:01 GMT
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.)

> You have to specify FILE_FLAG_BACKUP_SEMANTICS to open a directory,
> the test doesn't do that.
>
> Dave
David Lowndes - 28 Nov 2007 11:20 GMT
>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
Herzl Regev - 28 Nov 2007 13:37 GMT
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 don't understand what you're telling me there.
David Lowndes - 28 Nov 2007 15:17 GMT
>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
Herzl Regev - 28 Nov 2007 15:46 GMT
> >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?
None. The same call, except that I added FILE_FLAG_BACKUP_SEMANTICS .

> >The other process is Visual Studio and the file is <project>.ncb .
>
> 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 .
David Lowndes - 28 Nov 2007 16:51 GMT
>> >The other process is Visual Studio and the file is <project>.ncb .
>>
>> What are you trying to do?
>Check the size of the file

No need to open it then, just use FindFirstFile, FindClose.

Dave

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.