CreateFileW( L"FileName", GENERIC_READ, FILE_SHARE_WRITE, // Can I use it like this FILE_SHARE_WRITE|FILE_SHARE_READ FOR BOTH READ AND WRITE ACCESS or simply FILE_SHARE_WRITE is sufficient for both read and write access simultaneously? lpSecurityAttributes, // I tried reading msdn but didn't understand it. Please explain me in simple way. OPEN_EXISTING, dwFlagsAndAttributes, // (Why in certain examples it is 0. While 0 is not define in msdn. i.e FILE_ATTRIBUTE_NORMAL == 0x80. But what is 0 stands for.) hTemplateFile // I didn't understand this too. What is templatefile?
7 replies to this topic
#1
Posted 28 October 2011 - 08:05 PM
|
|
|
#2
Posted 28 October 2011 - 10:18 PM
What's your question?
#3
Posted 29 October 2011 - 04:49 AM
Q1 Can I use FILE_SHARE_WRITE|FILE_SHARE_READ FOR BOTH READ AND WRITE ACCESS or simply FILE_SHARE_WRITE is sufficient for both read and write access simultaneously?
Q2 What is lpSecurityAttributes?
Q3 Why in certain examples dwFlagsAndAttributes is set to 0. While 0 is not define in msdn. i.e FILE_ATTRIBUTE_NORMAL == 0x80. But what is 0 stands for?
Q4 What is templatefile?
Q2 What is lpSecurityAttributes?
Q3 Why in certain examples dwFlagsAndAttributes is set to 0. While 0 is not define in msdn. i.e FILE_ATTRIBUTE_NORMAL == 0x80. But what is 0 stands for?
Q4 What is templatefile?
#4
Posted 29 October 2011 - 04:50 AM
>>// I tried reading msdn but didn't understand it. Please explain me in simple way.
Just set it to NULL.
Here is how I normally call that function
Just set it to NULL.
Here is how I normally call that function
CreateFile(L"Hello", GENERIC_READ|GENERIC_WRITE,0, 0,FILE_ATTRIBUTE_NORMAL,0,0);
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#5
Posted 29 October 2011 - 04:52 AM
But what is it actually? And when it is not set to NULL
#6
Posted 29 October 2011 - 12:15 PM
A1: I suppose FILE_SHARE_* just means that you allow other processes (programs) to * your file. And yes, I do believe you have to include all that apply; so for other processes to be able to read the file, you would use FILE_SHARE_READ, while for other processes to have read, write, and delete access to the file, you would use FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
A2: It is the pointer to (memory address of) the SECURITY_ATTRIBUTES structure for the file. I do not know how the SECURITY_ATTRIBUTES structure is used, nor what's it for, except for something about security. It usually works when I use 0 for this parameter.
A3: I don't know. I didn't even know you can leave that as 0. I usually use FILE_ATTRIBUTE_NORMAL.
A4: I am actually not sure what it means. It's been a while since I read the MSDN page about it. Hold on, let me check what it says. Oh, I think it's for using the file's (that you specify the handle of) attributes. So if you open file1.txt, and you are making a new file, file2.txt, then you can specify file1.txt ' s handle here, and so if file1.txt is hidden, for example, then file2.txt would also be hidden. That's from what I understood from reading the description, at least. You can just use 0 for this, if you don't care about that part of it.
A2: It is the pointer to (memory address of) the SECURITY_ATTRIBUTES structure for the file. I do not know how the SECURITY_ATTRIBUTES structure is used, nor what's it for, except for something about security. It usually works when I use 0 for this parameter.
A3: I don't know. I didn't even know you can leave that as 0. I usually use FILE_ATTRIBUTE_NORMAL.
A4: I am actually not sure what it means. It's been a while since I read the MSDN page about it. Hold on, let me check what it says. Oh, I think it's for using the file's (that you specify the handle of) attributes. So if you open file1.txt, and you are making a new file, file2.txt, then you can specify file1.txt ' s handle here, and so if file1.txt is hidden, for example, then file2.txt would also be hidden. That's from what I understood from reading the description, at least. You can just use 0 for this, if you don't care about that part of it.
#7
Posted 29 October 2011 - 12:43 PM
@RhetoricalRuvim : someone told me this. So I'd like to share this with you.
A2) Security Attributes control things like sharing file handles and thread safe access... this can usually be NULL in which case the default security descriptor for the directory you are in is used.
A3) When reading or opening an existing file this is usually 0, which does not change the existing disk attributes of the file.
And are you sure we can use dwShareMode like this too FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ?
I thought just mentioning FILE_SHARE_WRITE will give you read access by default? (I am not sure , I am just guessing)
And If you get any example on how to use hTemplatefile. Please post.
Thank You
A2) Security Attributes control things like sharing file handles and thread safe access... this can usually be NULL in which case the default security descriptor for the directory you are in is used.
A3) When reading or opening an existing file this is usually 0, which does not change the existing disk attributes of the file.
And are you sure we can use dwShareMode like this too FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ?
I thought just mentioning FILE_SHARE_WRITE will give you read access by default? (I am not sure , I am just guessing)
And If you get any example on how to use hTemplatefile. Please post.
Thank You
#8
Posted 29 October 2011 - 01:02 PM
Well, having in mind that FILE_SHARE_READ is 0x01 (0001b), FILE_SHARE_WRITE is 0x02 (0010b), and FILE_SHARE_DELETE is 0x04 (0100b), it would make sense that those three can be ORd, or added, to make 0111b for full sharing access. At least from what I understand, including this page, you do have to explicitly specify all the FILE_SHARE_* values. Or you can use the number 7, which is the same as all three ORd together; that's what I like to use.
As for the hTemplateFile parameter, I never used that before, so I don't think I would be able to provide any good examples; however, maybe there's someone else on this forum who could, I don't know.
With the GENERIC_READ and GENERIC_WRITE and GENERIC_EXECUTE, you have to specify all that apply, also. Though if you want to specify all of them, you can just use GENERIC_ALL .
As for the hTemplateFile parameter, I never used that before, so I don't think I would be able to provide any good examples; however, maybe there's someone else on this forum who could, I don't know.
With the GENERIC_READ and GENERIC_WRITE and GENERIC_EXECUTE, you have to specify all that apply, also. Though if you want to specify all of them, you can just use GENERIC_ALL .
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









