473,388 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Parameters to CreateFile

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).
Nov 27 '07 #1
9 1398
>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...ams.htm#CFTest

Dave
Nov 27 '07 #2
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?

"David Lowndes" wrote:
I have a simple test application for the CreateFile API that I use for
checking such scenarios:
http://www.jddesign.f2s.com/freeware...ams.htm#CFTest

Dave
Nov 27 '07 #3
>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
Nov 28 '07 #4
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.)

"David Lowndes" wrote:
You have to specify FILE_FLAG_BACKUP_SEMANTICS to open a directory,
the test doesn't do that.

Dave
Nov 28 '07 #5
>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
Nov 28 '07 #6
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 .

"David Lowndes" wrote:
I don't understand what you're telling me there.
Nov 28 '07 #7
>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
Nov 28 '07 #8


"David Lowndes" wrote:
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-fi...r-windows.html .
Nov 28 '07 #9
>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
Nov 28 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chuck Rittersdorf | last post by:
Hi There I am having a problem using the win32 API from VB6. I am trying to send a command string to a printer(zebra TLP 2742) on LPT1 using the folowing API functions CreateFile and...
3
by: Antoine | last post by:
Hello, I'm writing a program to send requests to my wlan pocket pc device (UIO1: driver) in C#. Here how I import CreateFile functions from coredll.dll with DllImport: public static extern...
4
by: JLW | last post by:
I'm having alot of difficulty with this one. I have seen no less than 20 different ways to use this function with a named pipe. I'm trying to use \\.\TAPE0 (TapeDrive). Here's my decleration: ...
5
by: Andrew Clark | last post by:
Hello, Thanks for all replies on this subject. I still cannot get CreateFile to retun a good value though. I went to PInvoke.net and saw the VB.NET declaration of this function: ...
5
by: Fla | last post by:
Hy! I'm a newbie to VB 2005 and I have to connect my program to a driver previously developed for a custom ISA card. With my old VB 6 code I used the routine CreateFileA exported from kernel32...
7
by: Asfar | last post by:
I have a MFC dll in which one of the parameters is of LPSTR. The declaration of my MFC dll looks like extern "C" __declspec(dllexport) int WINAPI EXPORT TestPInvokeFunc(LPSTR szFileName, LPSTR...
8
by: news.microsoft.com | last post by:
Hello, i'm having problems to call a api dll in vb dot net. I absolutely want to use this api call and none of the frame calls. This is my declaration: ***************** Public Structure...
3
by: Scott Bell | last post by:
Hello all, What is the equivalent in the .NET Framework for accessing a device at the block/sector level such as one would when using CreateFile on a device like "\\.\D:"? Attempting to create...
2
by: Jim Flanagan | last post by:
Hi... I am using VB.net Express to experiment with the Win32 API functions that are available. The current project is an application that will read the raw sectors of a logical drive so that a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.