shareDenyWrite is not enough

I want to prevent writing to a file but allow several processes to
read it simultaneously. The flag shareDenyWrite does the first but not
the second and I'm forced to use shareDenyNone (which works).

Any thoughts?
0
the44secs (141)
7/20/2008 4:00:14 AM
vc.mfc 33608 articles. 0 followers. Follow

27 Replies
1350 Views

Similar Articles

[PageSpeed] 17

"Alexander" <the44secs@yahoo.com> wrote in message 
news:6c435000-7beb-4b49-96c5-c0db4423f89a@u6g2000prc.googlegroups.com...
>I want to prevent writing to a file but allow several processes to
> read it simultaneously. The flag shareDenyWrite does the first but not
> the second and I'm forced to use shareDenyNone (which works).
>


shareDenyWrite should not prohibit multiple processes from reading the file. 
Perhaps one (or more) of the reader processes is opening the file with 
shareDenyRead, thus locking out the other processes?

-- David


0
dc2983 (3206)
7/20/2008 4:56:21 AM
Thank you for the reply.

The answer is no. All process use either shareDenyWrite or nothing.


On Jul 20, 1:56=A0pm, "David Ching" <d...@remove-this.dcsoft.com> wrote:
> "Alexander" <the44s...@yahoo.com> wrote in message
>
> news:6c435000-7beb-4b49-96c5-c0db4423f89a@u6g2000prc.googlegroups.com...
>
> >I want to prevent writing to a file but allow several processes to
> > read it simultaneously. The flag shareDenyWrite does the first but not
> > the second and I'm forced to use shareDenyNone (which works).
>
> shareDenyWrite should not prohibit multiple processes from reading the fi=
le.
> Perhaps one (or more) of the reader processes is opening the file with
> shareDenyRead, thus locking out the other processes?
>
> -- David

0
the44secs (141)
7/20/2008 5:10:55 AM
"Alexander" <the44secs@yahoo.com> wrote in message 
news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.com...
> Thank you for the reply.

> The answer is no. All process use either shareDenyWrite or nothing.

When you say nothing, do you mean ZERO?

If so, that means share exclusive, denying access to any other open.

Anthony Wieser
Wieser Software Ltd

0
7/20/2008 6:39:43 AM
Alexander schrieb:

> The answer is no. All process use either shareDenyWrite or nothing.
                                                              ^^^^^^^

That could be your problem. As far as I remember, not using any shareDeny* flags 
opens the file in compatibility mode, which means exclusive access. All the 
other processes should use explicitly use shareDenyNothing (or shareDenyWrite if 
they care).

Norbert


> On Jul 20, 1:56 pm, "David Ching" <d...@remove-this.dcsoft.com> wrote:
>> "Alexander" <the44s...@yahoo.com> wrote in message
>>
>> news:6c435000-7beb-4b49-96c5-c0db4423f89a@u6g2000prc.googlegroups.com...
>>
>>> I want to prevent writing to a file but allow several processes to
>>> read it simultaneously. The flag shareDenyWrite does the first but not
>>> the second and I'm forced to use shareDenyNone (which works).
>> shareDenyWrite should not prohibit multiple processes from reading the file.
>> Perhaps one (or more) of the reader processes is opening the file with
>> shareDenyRead, thus locking out the other processes?
>>
>> -- David
> 
0
nunterberg (207)
7/20/2008 1:37:41 PM
Is this a file that was just created by the first process and never closed? 
Perhaps that why it doesn't work as expected.

Also, could you show your open code so that we could see if there is 
something else going on.

Tom

"Alexander" <the44secs@yahoo.com> wrote in message 
news:6c435000-7beb-4b49-96c5-c0db4423f89a@u6g2000prc.googlegroups.com...
>I want to prevent writing to a file but allow several processes to
> read it simultaneously. The flag shareDenyWrite does the first but not
> the second and I'm forced to use shareDenyNone (which works).
>
> Any thoughts? 

0
tom.nospam (3240)
7/20/2008 2:21:20 PM
I believe if you pass in a '0' that is the same as opening it in exclusive 
read mode.  That could well be the problem .

Tom

"Norbert Unterberg" <nunterberg@newsgroups.nospam> wrote in message 
news:eqeAK3m6IHA.3652@TK2MSFTNGP04.phx.gbl...
>
> Alexander schrieb:
>
>> The answer is no. All process use either shareDenyWrite or nothing.
>                                                              ^^^^^^^
>
> That could be your problem. As far as I remember, not using any shareDeny* 
> flags opens the file in compatibility mode, which means exclusive access. 
> All the other processes should use explicitly use shareDenyNothing (or 
> shareDenyWrite if they care).
>
> Norbert
>
>
>> On Jul 20, 1:56 pm, "David Ching" <d...@remove-this.dcsoft.com> wrote:
>>> "Alexander" <the44s...@yahoo.com> wrote in message
>>>
>>> news:6c435000-7beb-4b49-96c5-c0db4423f89a@u6g2000prc.googlegroups.com...
>>>
>>>> I want to prevent writing to a file but allow several processes to
>>>> read it simultaneously. The flag shareDenyWrite does the first but not
>>>> the second and I'm forced to use shareDenyNone (which works).
>>> shareDenyWrite should not prohibit multiple processes from reading the 
>>> file.
>>> Perhaps one (or more) of the reader processes is opening the file with
>>> shareDenyRead, thus locking out the other processes?
>>>
>>> -- David
>> 

0
tom.nospam (3240)
7/20/2008 2:32:30 PM
That was my conclusion. No flags implies neither shared read or write
are allowed... which is weird because it means that in order to allow
shared read I need shareDenyNone... unless shareDenyWrite authorizes
shared reading as a side effect which is bizarre.

Ok, guys. I'm confused. Here is the data:

1. The file is not created by these processes (it is guaranteed to
exist beforehand) and it is never updated.
2. I want all processes to be able to read it simultaneously.
3. This is a text file and all processes use the class CStdioFile to
handle it.
4. Which are the flags (or lack of) that allow simultenous read and
lock _everything_ else out?

Thank you all.


On Jul 20, 3:39=A0pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
software.com> wrote:
> "Alexander" <the44s...@yahoo.com> wrote in message
>
> news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.com...
>
> > Thank you for the reply.
> > The answer is no. All process use either shareDenyWrite or nothing.
>
> When you say nothing, do you mean ZERO?
>
> If so, that means share exclusive, denying access to any other open.
>
> Anthony Wieser
> Wieser Software Ltd

0
the44secs (141)
7/20/2008 2:41:23 PM
All processes have to use compatible access masks. Those who read, should 
NOT use DenyWrite, if you want one process to write to the file at the same 
time.



"Alexander" <the44secs@yahoo.com> wrote in message 
news:6c435000-7beb-4b49-96c5-c0db4423f89a@u6g2000prc.googlegroups.com...
>I want to prevent writing to a file but allow several processes to
> read it simultaneously. The flag shareDenyWrite does the first but not
> the second and I'm forced to use shareDenyNone (which works).
>
> Any thoughts? 


0
alegr (1131)
7/20/2008 2:57:19 PM
I bet you need EVERY process trying to access the file to use shareDenyWrite 
and if any of them are opening it in compatibility mode or with any other 
access type (like modeRead) you will run into these problems.

Tom

"Alexander" <the44secs@yahoo.com> wrote in message 
news:3943299e-d6bb-4115-9ea3-974d04dae0eb@x36g2000prg.googlegroups.com...
That was my conclusion. No flags implies neither shared read or write
are allowed... which is weird because it means that in order to allow
shared read I need shareDenyNone... unless shareDenyWrite authorizes
shared reading as a side effect which is bizarre.

Ok, guys. I'm confused. Here is the data:

1. The file is not created by these processes (it is guaranteed to
exist beforehand) and it is never updated.
2. I want all processes to be able to read it simultaneously.
3. This is a text file and all processes use the class CStdioFile to
handle it.
4. Which are the flags (or lack of) that allow simultenous read and
lock _everything_ else out?

Thank you all.


On Jul 20, 3:39 pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
software.com> wrote:
> "Alexander" <the44s...@yahoo.com> wrote in message
>
> news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.com...
>
> > Thank you for the reply.
> > The answer is no. All process use either shareDenyWrite or nothing.
>
> When you say nothing, do you mean ZERO?
>
> If so, that means share exclusive, denying access to any other open.
>
> Anthony Wieser
> Wieser Software Ltd

0
tom.nospam (3240)
7/20/2008 7:55:57 PM
Yep. All processes had those two flags shareDenyWrite and modeRead.

I still don't understand why this is a problem for shared reads.


On Jul 21, 4:55=A0am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> I bet you need EVERY process trying to access the file to use shareDenyWr=
ite
> and if any of them are opening it in compatibility mode or with any other
> access type (like modeRead) you will run into these problems.
>
> Tom
>
> "Alexander" <the44s...@yahoo.com> wrote in message
>
> news:3943299e-d6bb-4115-9ea3-974d04dae0eb@x36g2000prg.googlegroups.com...
> That was my conclusion. No flags implies neither shared read or write
> are allowed... which is weird because it means that in order to allow
> shared read I need shareDenyNone... unless shareDenyWrite authorizes
> shared reading as a side effect which is bizarre.
>
> Ok, guys. I'm confused. Here is the data:
>
> 1. The file is not created by these processes (it is guaranteed to
> exist beforehand) and it is never updated.
> 2. I want all processes to be able to read it simultaneously.
> 3. This is a text file and all processes use the class CStdioFile to
> handle it.
> 4. Which are the flags (or lack of) that allow simultenous read and
> lock _everything_ else out?
>
> Thank you all.
>
> On Jul 20, 3:39 pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
>
>
>
> software.com> wrote:
> > "Alexander" <the44s...@yahoo.com> wrote in message
>
> >news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.com..=
..
>
> > > Thank you for the reply.
> > > The answer is no. All process use either shareDenyWrite or nothing.
>
> > When you say nothing, do you mean ZERO?
>
> > If so, that means share exclusive, denying access to any other open.
>
> > Anthony Wieser
> > Wieser Software Ltd

0
the44secs (141)
7/20/2008 9:50:07 PM
Yeah, that is weird.  I think modeRead is just 0 (zero) so or'ing that in 
with the shareDenyWrite will not likely do anything (except make it more 
readable).

I'm running out of ideas.  I've been able to do this sort of thing before 
with my programs without any problems so I know it is possible.

Tom

"Alexander" <the44secs@yahoo.com> wrote in message 
news:60b38ae2-bd6e-4b3f-b43c-cf243e4eefd4@v21g2000pro.googlegroups.com...
Yep. All processes had those two flags shareDenyWrite and modeRead.

I still don't understand why this is a problem for shared reads.


On Jul 21, 4:55 am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> I bet you need EVERY process trying to access the file to use 
> shareDenyWrite
> and if any of them are opening it in compatibility mode or with any other
> access type (like modeRead) you will run into these problems.
>
> Tom
>


0
tom.nospam (3240)
7/21/2008 3:46:56 PM

"Tom Serface" wrote:

> Yeah, that is weird.  I think modeRead is just 0 (zero) so or'ing that in 
> with the shareDenyWrite will not likely do anything (except make it more 
> readable).
> 
> I'm running out of ideas.  I've been able to do this sort of thing before 
> with my programs without any problems so I know it is possible.
> 
> Tom
> 
> "Alexander" <the44secs@yahoo.com> wrote in message 
> news:60b38ae2-bd6e-4b3f-b43c-cf243e4eefd4@v21g2000pro.googlegroups.com...
> Yep. All processes had those two flags shareDenyWrite and modeRead.
> 
> I still don't understand why this is a problem for shared reads.
> 
> 
> On Jul 21, 4:55 am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> > I bet you need EVERY process trying to access the file to use 
> > shareDenyWrite
> > and if any of them are opening it in compatibility mode or with any other
> > access type (like modeRead) you will run into these problems.
> >
> > Tom
> >
> 
> 
0
Victor (177)
7/21/2008 4:53:02 PM
Could you show your exact code you are using to open this file?
Please, check it in all processes you are currecntly using.

Victor.

"Alexander" wrote:

> Yep. All processes had those two flags shareDenyWrite and modeRead.
> 
> I still don't understand why this is a problem for shared reads.
> 
> 
> On Jul 21, 4:55 am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> > I bet you need EVERY process trying to access the file to use shareDenyWrite
> > and if any of them are opening it in compatibility mode or with any other
> > access type (like modeRead) you will run into these problems.
> >
> > Tom
> >
> > "Alexander" <the44s...@yahoo.com> wrote in message
> >
> > news:3943299e-d6bb-4115-9ea3-974d04dae0eb@x36g2000prg.googlegroups.com...
> > That was my conclusion. No flags implies neither shared read or write
> > are allowed... which is weird because it means that in order to allow
> > shared read I need shareDenyNone... unless shareDenyWrite authorizes
> > shared reading as a side effect which is bizarre.
> >
> > Ok, guys. I'm confused. Here is the data:
> >
> > 1. The file is not created by these processes (it is guaranteed to
> > exist beforehand) and it is never updated.
> > 2. I want all processes to be able to read it simultaneously.
> > 3. This is a text file and all processes use the class CStdioFile to
> > handle it.
> > 4. Which are the flags (or lack of) that allow simultenous read and
> > lock _everything_ else out?
> >
> > Thank you all.
> >
> > On Jul 20, 3:39 pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
> >
> >
> >
> > software.com> wrote:
> > > "Alexander" <the44s...@yahoo.com> wrote in message
> >
> > >news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.com....
> >
> > > > Thank you for the reply.
> > > > The answer is no. All process use either shareDenyWrite or nothing.
> >
> > > When you say nothing, do you mean ZERO?
> >
> > > If so, that means share exclusive, denying access to any other open.
> >
> > > Anthony Wieser
> > > Wieser Software Ltd
> 
> 
0
Victor (177)
7/21/2008 4:57:01 PM
There is very little mystery, I'm afraid. Here it is. All threads use
this same code:

CStdioFile fIn;

if( fIn.Open( csPath, CFile::modeRead | CFile::shareDenyNone ) )
{
=2E..
}

That code works but, naturally, it allows shared write which is what I
want to prevent.

If shareDenyNone is taken out, shared read is not allowed.


On Jul 22, 1:57=A0am, Victor <Vic...@discussions.microsoft.com> wrote:
> Could you show your exact code you are using to open this file?
> Please, check it in all processes you are currecntly using.
>
> Victor.
>
>
>
> "Alexander" wrote:
> > Yep. All processes had those two flags shareDenyWrite and modeRead.
>
> > I still don't understand why this is a problem for shared reads.
>
> > On Jul 21, 4:55 am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> > > I bet you need EVERY process trying to access the file to use shareDe=
nyWrite
> > > and if any of them are opening it in compatibility mode or with any o=
ther
> > > access type (like modeRead) you will run into these problems.
>
> > > Tom
>
> > > "Alexander" <the44s...@yahoo.com> wrote in message
>
> > >news:3943299e-d6bb-4115-9ea3-974d04dae0eb@x36g2000prg.googlegroups.com=
....
> > > That was my conclusion. No flags implies neither shared read or write
> > > are allowed... which is weird because it means that in order to allow
> > > shared read I need shareDenyNone... unless shareDenyWrite authorizes
> > > shared reading as a side effect which is bizarre.
>
> > > Ok, guys. I'm confused. Here is the data:
>
> > > 1. The file is not created by these processes (it is guaranteed to
> > > exist beforehand) and it is never updated.
> > > 2. I want all processes to be able to read it simultaneously.
> > > 3. This is a text file and all processes use the class CStdioFile to
> > > handle it.
> > > 4. Which are the flags (or lack of) that allow simultenous read and
> > > lock _everything_ else out?
>
> > > Thank you all.
>
> > > On Jul 20, 3:39 pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
>
> > > software.com> wrote:
> > > > "Alexander" <the44s...@yahoo.com> wrote in message
>
> > > >news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.c=
om....
>
> > > > > Thank you for the reply.
> > > > > The answer is no. All process use either shareDenyWrite or nothin=
g.
>
> > > > When you say nothing, do you mean ZERO?
>
> > > > If so, that means share exclusive, denying access to any other open=
..
>
> > > > Anthony Wieser
> > > > Wieser Software Ltd

0
the44secs (141)
7/22/2008 8:42:59 AM
And how was this file created? With which flags?
The correct ones should have been: 
modeRead | modeWrite | modeCreate (and modeNoTruncate as optional)
+
shareDenyWrite  

In this case all other Open operations might be successful ONLY with the 
flags    
modeRead | shareDenyNone  

Note also, that if the process created this file exits, then it must set 
attributes of this file as "Read Only", otherwise any other process will be 
able to write to it.

Victor

"Alexander" wrote:

> There is very little mystery, I'm afraid. Here it is. All threads use
> this same code:
> 
> CStdioFile fIn;
> 
> if( fIn.Open( csPath, CFile::modeRead | CFile::shareDenyNone ) )
> {
> ...
> }
> 
> That code works but, naturally, it allows shared write which is what I
> want to prevent.
> 
> If shareDenyNone is taken out, shared read is not allowed.
> 
> 
> On Jul 22, 1:57 am, Victor <Vic...@discussions.microsoft.com> wrote:
> > Could you show your exact code you are using to open this file?
> > Please, check it in all processes you are currecntly using.
> >
> > Victor.
> >
> >
> >
> > "Alexander" wrote:
> > > Yep. All processes had those two flags shareDenyWrite and modeRead.
> >
> > > I still don't understand why this is a problem for shared reads.
> >
> > > On Jul 21, 4:55 am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> > > > I bet you need EVERY process trying to access the file to use shareDenyWrite
> > > > and if any of them are opening it in compatibility mode or with any other
> > > > access type (like modeRead) you will run into these problems.
> >
> > > > Tom
> >
> > > > "Alexander" <the44s...@yahoo.com> wrote in message
> >
> > > >news:3943299e-d6bb-4115-9ea3-974d04dae0eb@x36g2000prg.googlegroups.com....
> > > > That was my conclusion. No flags implies neither shared read or write
> > > > are allowed... which is weird because it means that in order to allow
> > > > shared read I need shareDenyNone... unless shareDenyWrite authorizes
> > > > shared reading as a side effect which is bizarre.
> >
> > > > Ok, guys. I'm confused. Here is the data:
> >
> > > > 1. The file is not created by these processes (it is guaranteed to
> > > > exist beforehand) and it is never updated.
> > > > 2. I want all processes to be able to read it simultaneously.
> > > > 3. This is a text file and all processes use the class CStdioFile to
> > > > handle it.
> > > > 4. Which are the flags (or lack of) that allow simultenous read and
> > > > lock _everything_ else out?
> >
> > > > Thank you all.
> >
> > > > On Jul 20, 3:39 pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
> >
> > > > software.com> wrote:
> > > > > "Alexander" <the44s...@yahoo.com> wrote in message
> >
> > > > >news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.com....
> >
> > > > > > Thank you for the reply.
> > > > > > The answer is no. All process use either shareDenyWrite or nothing.
> >
> > > > > When you say nothing, do you mean ZERO?
> >
> > > > > If so, that means share exclusive, denying access to any other open..
> >
> > > > > Anthony Wieser
> > > > > Wieser Software Ltd
> 
> 
0
Victor (177)
7/22/2008 10:30:02 AM
The file was created with modeWrite and modeCreate. However, this file
is created by another program at a different time and it has no
bearing on the issue at hand.

Consider that the flags I posted (modeRead, shareDenyNone) allow
shared reads while modeRead alone doesn't. Therefore, the problem is
simply how to allow shared reads while disallowing shared writes.

I don't want to disallow shared writes in order to block another
process. None of the process will try to write to this file. I'm just
trying to prevent accidental writing to this file by _unknown_parties_
while my processes are reading it. In short, I'm trying to forsee the
unforseeable and I thought it should be a simple issue of setting the
right flags... it doesn't seem so, though.


On Jul 22, 7:30=A0pm, Victor <Vic...@discussions.microsoft.com> wrote:
> And how was this file created? With which flags?
> The correct ones should have been:
> modeRead | modeWrite | modeCreate (and modeNoTruncate as optional)
> +
> shareDenyWrite =A0
>
> In this case all other Open operations might be successful ONLY with the
> flags =A0 =A0
> modeRead | shareDenyNone =A0
>
> Note also, that if the process created this file exits, then it must set
> attributes of this file as "Read Only", otherwise any other process will =
be
> able to write to it.
>
> Victor
>
>
>
> "Alexander" wrote:
> > There is very little mystery, I'm afraid. Here it is. All threads use
> > this same code:
>
> > CStdioFile fIn;
>
> > if( fIn.Open( csPath, CFile::modeRead | CFile::shareDenyNone ) )
> > {
> > ...
> > }
>
> > That code works but, naturally, it allows shared write which is what I
> > want to prevent.
>
> > If shareDenyNone is taken out, shared read is not allowed.
>
> > On Jul 22, 1:57 am, Victor <Vic...@discussions.microsoft.com> wrote:
> > > Could you show your exact code you are using to open this file?
> > > Please, check it in all processes you are currecntly using.
>
> > > Victor.
>
> > > "Alexander" wrote:
> > > > Yep. All processes had those two flags shareDenyWrite and modeRead.
>
> > > > I still don't understand why this is a problem for shared reads.
>
> > > > On Jul 21, 4:55 am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> > > > > I bet you need EVERY process trying to access the file to use sha=
reDenyWrite
> > > > > and if any of them are opening it in compatibility mode or with a=
ny other
> > > > > access type (like modeRead) you will run into these problems.
>
> > > > > Tom
>
> > > > > "Alexander" <the44s...@yahoo.com> wrote in message
>
> > > > >news:3943299e-d6bb-4115-9ea3-974d04dae0eb@x36g2000prg.googlegroups=
..com....
> > > > > That was my conclusion. No flags implies neither shared read or w=
rite
> > > > > are allowed... which is weird because it means that in order to a=
llow
> > > > > shared read I need shareDenyNone... unless shareDenyWrite authori=
zes
> > > > > shared reading as a side effect which is bizarre.
>
> > > > > Ok, guys. I'm confused. Here is the data:
>
> > > > > 1. The file is not created by these processes (it is guaranteed t=
o
> > > > > exist beforehand) and it is never updated.
> > > > > 2. I want all processes to be able to read it simultaneously.
> > > > > 3. This is a text file and all processes use the class CStdioFile=
 to
> > > > > handle it.
> > > > > 4. Which are the flags (or lack of) that allow simultenous read a=
nd
> > > > > lock _everything_ else out?
>
> > > > > Thank you all.
>
> > > > > On Jul 20, 3:39 pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
>
> > > > > software.com> wrote:
> > > > > > "Alexander" <the44s...@yahoo.com> wrote in message
>
> > > > > >news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegrou=
ps.com....
>
> > > > > > > Thank you for the reply.
> > > > > > > The answer is no. All process use either shareDenyWrite or no=
thing.
>
> > > > > > When you say nothing, do you mean ZERO?
>
> > > > > > If so, that means share exclusive, denying access to any other =
open..
>
> > > > > > Anthony Wieser
> > > > > > Wieser Software Ltd

0
the44secs (141)
7/22/2008 11:25:03 AM
"Alexander" <the44secs@yahoo.com> wrote in message 
news:03400894-db1f-4a7a-af7d-2397a61d4502@m3g2000hsc.googlegroups.com...
> The file was created with modeWrite and modeCreate. However, this file
> is created by another program at a different time and it has no
> bearing on the issue at hand.

The writer program is the one that should do:

    if( fIn.Open( csPath, CFile::modeWrite | CFile::shareDenyWrite ) )
   {
      ...
   }

to make sure it is the only process that can write to the file!  But this 
says nothing about reading, so multiple files can read this file while it is 
being written to.  Isn't this what you want?


Thanks,
David 


0
dc2983 (3206)
7/22/2008 1:26:03 PM
OK. You either allow writes or don't allow shared writes. If you don't allow 
shared writes, only one process will be able to open the file for writing, 
no other process will be able to open the file for writing AND reading. If 
you allow shared writes, all processes will be able to open the file for 
reading AND writing. If you want exclusive write access, use LockFileEx.

There is no way to allow writing to a file based on trusted/untrusted 
process. Only on basis of account-based access control.

ANother way would be to use DuplicateHandle, when a writer opens the file in 
exclusive mode, and then hands the duplicates of the handle (with read-only 
access) to its brethren. The handle would need to be opened in overlapped 
mode, and you cannot use stdio to work with those.

Yet another way would be to use a service to access the file. The client 
processes would request reading and writing to it.

"Alexander" <the44secs@yahoo.com> wrote in message 
news:03400894-db1f-4a7a-af7d-2397a61d4502@m3g2000hsc.googlegroups.com...
The file was created with modeWrite and modeCreate. However, this file
is created by another program at a different time and it has no
bearing on the issue at hand.

Consider that the flags I posted (modeRead, shareDenyNone) allow
shared reads while modeRead alone doesn't. Therefore, the problem is
simply how to allow shared reads while disallowing shared writes.

I don't want to disallow shared writes in order to block another
process. None of the process will try to write to this file. I'm just
trying to prevent accidental writing to this file by _unknown_parties_
while my processes are reading it. In short, I'm trying to forsee the
unforseeable and I thought it should be a simple issue of setting the
right flags... it doesn't seem so, though.


On Jul 22, 7:30 pm, Victor <Vic...@discussions.microsoft.com> wrote:
> And how was this file created? With which flags?
> The correct ones should have been:
> modeRead | modeWrite | modeCreate (and modeNoTruncate as optional)
> +
> shareDenyWrite
>
> In this case all other Open operations might be successful ONLY with the
> flags
> modeRead | shareDenyNone
>
> Note also, that if the process created this file exits, then it must set
> attributes of this file as "Read Only", otherwise any other process will 
> be
> able to write to it.
>
> Victor
>
>
>
> "Alexander" wrote:
> > There is very little mystery, I'm afraid. Here it is. All threads use
> > this same code:
>
> > CStdioFile fIn;
>
> > if( fIn.Open( csPath, CFile::modeRead | CFile::shareDenyNone ) )
> > {
> > ...
> > }
>
> > That code works but, naturally, it allows shared write which is what I
> > want to prevent.
>
> > If shareDenyNone is taken out, shared read is not allowed.
>
> > On Jul 22, 1:57 am, Victor <Vic...@discussions.microsoft.com> wrote:
> > > Could you show your exact code you are using to open this file?
> > > Please, check it in all processes you are currecntly using.
>
> > > Victor.
>
> > > "Alexander" wrote:
> > > > Yep. All processes had those two flags shareDenyWrite and modeRead.
>
> > > > I still don't understand why this is a problem for shared reads.
>
> > > > On Jul 21, 4:55 am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
> > > > > I bet you need EVERY process trying to access the file to use 
> > > > > shareDenyWrite
> > > > > and if any of them are opening it in compatibility mode or with 
> > > > > any other
> > > > > access type (like modeRead) you will run into these problems.
>
> > > > > Tom
>
> > > > > "Alexander" <the44s...@yahoo.com> wrote in message
>
> > > > >news:3943299e-d6bb-4115-9ea3-974d04dae0eb@x36g2000prg.googlegroups.com....
> > > > > That was my conclusion. No flags implies neither shared read or 
> > > > > write
> > > > > are allowed... which is weird because it means that in order to 
> > > > > allow
> > > > > shared read I need shareDenyNone... unless shareDenyWrite 
> > > > > authorizes
> > > > > shared reading as a side effect which is bizarre.
>
> > > > > Ok, guys. I'm confused. Here is the data:
>
> > > > > 1. The file is not created by these processes (it is guaranteed to
> > > > > exist beforehand) and it is never updated.
> > > > > 2. I want all processes to be able to read it simultaneously.
> > > > > 3. This is a text file and all processes use the class CStdioFile 
> > > > > to
> > > > > handle it.
> > > > > 4. Which are the flags (or lack of) that allow simultenous read 
> > > > > and
> > > > > lock _everything_ else out?
>
> > > > > Thank you all.
>
> > > > > On Jul 20, 3:39 pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
>
> > > > > software.com> wrote:
> > > > > > "Alexander" <the44s...@yahoo.com> wrote in message
>
> > > > > >news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.com....
>
> > > > > > > Thank you for the reply.
> > > > > > > The answer is no. All process use either shareDenyWrite or 
> > > > > > > nothing.
>
> > > > > > When you say nothing, do you mean ZERO?
>
> > > > > > If so, that means share exclusive, denying access to any other 
> > > > > > open..
>
> > > > > > Anthony Wieser
> > > > > > Wieser Software Ltd


0
alegr (1131)
7/22/2008 2:04:01 PM
I formulated the idea wrong way.

All readers SHOULD allow shared writes and reads (shareDenyNone). A writer 
should allow shared reads (shareDenyWrite).

"Alexander Grigoriev" <alegr@earthlink.net> wrote in message 
news:uCVOLPA7IHA.2336@TK2MSFTNGP03.phx.gbl...
> OK. You either allow writes or don't allow shared writes. If you don't 
> allow shared writes, only one process will be able to open the file for 
> writing, no other process will be able to open the file for writing AND 
> reading. If you allow shared writes, all processes will be able to open 
> the file for reading AND writing. If you want exclusive write access, use 
> LockFileEx.
>
> There is no way to allow writing to a file based on trusted/untrusted 
> process. Only on basis of account-based access control.
>
> ANother way would be to use DuplicateHandle, when a writer opens the file 
> in exclusive mode, and then hands the duplicates of the handle (with 
> read-only access) to its brethren. The handle would need to be opened in 
> overlapped mode, and you cannot use stdio to work with those.
>
> Yet another way would be to use a service to access the file. The client 
> processes would request reading and writing to it.
>
> "Alexander" <the44secs@yahoo.com> wrote in message 
> news:03400894-db1f-4a7a-af7d-2397a61d4502@m3g2000hsc.googlegroups.com...
> The file was created with modeWrite and modeCreate. However, this file
> is created by another program at a different time and it has no
> bearing on the issue at hand.
>
> Consider that the flags I posted (modeRead, shareDenyNone) allow
> shared reads while modeRead alone doesn't. Therefore, the problem is
> simply how to allow shared reads while disallowing shared writes.
>
> I don't want to disallow shared writes in order to block another
> process. None of the process will try to write to this file. I'm just
> trying to prevent accidental writing to this file by _unknown_parties_
> while my processes are reading it. In short, I'm trying to forsee the
> unforseeable and I thought it should be a simple issue of setting the
> right flags... it doesn't seem so, though.
>
>
> On Jul 22, 7:30 pm, Victor <Vic...@discussions.microsoft.com> wrote:
>> And how was this file created? With which flags?
>> The correct ones should have been:
>> modeRead | modeWrite | modeCreate (and modeNoTruncate as optional)
>> +
>> shareDenyWrite
>>
>> In this case all other Open operations might be successful ONLY with the
>> flags
>> modeRead | shareDenyNone
>>
>> Note also, that if the process created this file exits, then it must set
>> attributes of this file as "Read Only", otherwise any other process will 
>> be
>> able to write to it.
>>
>> Victor
>>
>>
>>
>> "Alexander" wrote:
>> > There is very little mystery, I'm afraid. Here it is. All threads use
>> > this same code:
>>
>> > CStdioFile fIn;
>>
>> > if( fIn.Open( csPath, CFile::modeRead | CFile::shareDenyNone ) )
>> > {
>> > ...
>> > }
>>
>> > That code works but, naturally, it allows shared write which is what I
>> > want to prevent.
>>
>> > If shareDenyNone is taken out, shared read is not allowed.
>>
>> > On Jul 22, 1:57 am, Victor <Vic...@discussions.microsoft.com> wrote:
>> > > Could you show your exact code you are using to open this file?
>> > > Please, check it in all processes you are currecntly using.
>>
>> > > Victor.
>>
>> > > "Alexander" wrote:
>> > > > Yep. All processes had those two flags shareDenyWrite and modeRead.
>>
>> > > > I still don't understand why this is a problem for shared reads.
>>
>> > > > On Jul 21, 4:55 am, "Tom Serface" <tom.nos...@camaswood.com> wrote:
>> > > > > I bet you need EVERY process trying to access the file to use 
>> > > > > shareDenyWrite
>> > > > > and if any of them are opening it in compatibility mode or with 
>> > > > > any other
>> > > > > access type (like modeRead) you will run into these problems.
>>
>> > > > > Tom
>>
>> > > > > "Alexander" <the44s...@yahoo.com> wrote in message
>>
>> > > > >news:3943299e-d6bb-4115-9ea3-974d04dae0eb@x36g2000prg.googlegroups.com....
>> > > > > That was my conclusion. No flags implies neither shared read or 
>> > > > > write
>> > > > > are allowed... which is weird because it means that in order to 
>> > > > > allow
>> > > > > shared read I need shareDenyNone... unless shareDenyWrite 
>> > > > > authorizes
>> > > > > shared reading as a side effect which is bizarre.
>>
>> > > > > Ok, guys. I'm confused. Here is the data:
>>
>> > > > > 1. The file is not created by these processes (it is guaranteed 
>> > > > > to
>> > > > > exist beforehand) and it is never updated.
>> > > > > 2. I want all processes to be able to read it simultaneously.
>> > > > > 3. This is a text file and all processes use the class CStdioFile 
>> > > > > to
>> > > > > handle it.
>> > > > > 4. Which are the flags (or lack of) that allow simultenous read 
>> > > > > and
>> > > > > lock _everything_ else out?
>>
>> > > > > Thank you all.
>>
>> > > > > On Jul 20, 3:39 pm, "Anthony Wieser" <newsgroups-sanss...@wieser-
>>
>> > > > > software.com> wrote:
>> > > > > > "Alexander" <the44s...@yahoo.com> wrote in message
>>
>> > > > > >news:daf6776b-f790-46d2-a071-934348ec5a09@p25g2000pri.googlegroups.com....
>>
>> > > > > > > Thank you for the reply.
>> > > > > > > The answer is no. All process use either shareDenyWrite or 
>> > > > > > > nothing.
>>
>> > > > > > When you say nothing, do you mean ZERO?
>>
>> > > > > > If so, that means share exclusive, denying access to any other 
>> > > > > > open..
>>
>> > > > > > Anthony Wieser
>> > > > > > Wieser Software Ltd
>
> 


0
alegr (1131)
7/22/2008 2:07:42 PM
Ok, guys. I think I'm not getting across.

1. No thread writes to the file. Writing is not an issue.
2. Several threads read the file at the same time.

The problem is that I found that the only way to allow several threads
to read the file is by using shareDenyNone. In particular:

1. If I don't use shareDenyNone, multiple reads are not allowed.
2. If I use shareDenyWrite, multiple reads are not allowed.

Solution? Use shareDenyNone _which_ does not make sense when all you
want is to allow shared reads.


On Jul 22, 10:26=A0pm, "David Ching" <d...@remove-this.dcsoft.com>
wrote:
> "Alexander" <the44s...@yahoo.com> wrote in message
>
> news:03400894-db1f-4a7a-af7d-2397a61d4502@m3g2000hsc.googlegroups.com...
>
> > The file was created with modeWrite and modeCreate. However, this file
> > is created by another program at a different time and it has no
> > bearing on the issue at hand.
>
> The writer program is the one that should do:
>
> =A0 =A0 if( fIn.Open( csPath, CFile::modeWrite | CFile::shareDenyWrite ) =
)
> =A0 =A0{
> =A0 =A0 =A0 ...
> =A0 =A0}
>
> to make sure it is the only process that can write to the file! =A0But th=
is
> says nothing about reading, so multiple files can read this file while it=
 is
> being written to. =A0Isn't this what you want?
>
> Thanks,
> David

0
the44secs (141)
7/22/2008 2:39:30 PM
How are you opening the files for read?

"Alexander" <the44secs@yahoo.com> wrote in message 
news:9eeea132-fdb9-4469-b5c5-7edb4eaca46a@p25g2000hsf.googlegroups.com...
Ok, guys. I think I'm not getting across.

1. No thread writes to the file. Writing is not an issue.
2. Several threads read the file at the same time.

The problem is that I found that the only way to allow several threads
to read the file is by using shareDenyNone. In particular:

1. If I don't use shareDenyNone, multiple reads are not allowed.
2. If I use shareDenyWrite, multiple reads are not allowed.

Solution? Use shareDenyNone _which_ does not make sense when all you
want is to allow shared reads.


On Jul 22, 10:26 pm, "David Ching" <d...@remove-this.dcsoft.com>
wrote:
> "Alexander" <the44s...@yahoo.com> wrote in message
>
> news:03400894-db1f-4a7a-af7d-2397a61d4502@m3g2000hsc.googlegroups.com...
>
> > The file was created with modeWrite and modeCreate. However, this file
> > is created by another program at a different time and it has no
> > bearing on the issue at hand.
>
> The writer program is the one that should do:
>
> if( fIn.Open( csPath, CFile::modeWrite | CFile::shareDenyWrite ) )
> {
> ...
> }
>
> to make sure it is the only process that can write to the file! But this
> says nothing about reading, so multiple files can read this file while it 
> is
> being written to. Isn't this what you want?
>
> Thanks,
> David


0
alegr (1131)
7/22/2008 4:06:19 PM
All threads use this same code:

CStdioFile fIn;

if( fIn.Open( csPath, CFile::modeRead | CFile::shareDenyNone ) )
{
=2E..

}

That code works.

If shareDenyNone is taken out, shared read is not allowed.



On Jul 23, 1:06=A0am, "Alexander Grigoriev" <al...@earthlink.net> wrote:
> How are you opening the files for read?
>
> "Alexander" <the44s...@yahoo.com> wrote in message
>
> news:9eeea132-fdb9-4469-b5c5-7edb4eaca46a@p25g2000hsf.googlegroups.com...
> Ok, guys. I think I'm not getting across.
>
> 1. No thread writes to the file. Writing is not an issue.
> 2. Several threads read the file at the same time.
>
> The problem is that I found that the only way to allow several threads
> to read the file is by using shareDenyNone. In particular:
>
> 1. If I don't use shareDenyNone, multiple reads are not allowed.
> 2. If I use shareDenyWrite, multiple reads are not allowed.
>
> Solution? Use shareDenyNone _which_ does not make sense when all you
> want is to allow shared reads.
>
> On Jul 22, 10:26 pm, "David Ching" <d...@remove-this.dcsoft.com>
> wrote:
>
>
>
> > "Alexander" <the44s...@yahoo.com> wrote in message
>
> >news:03400894-db1f-4a7a-af7d-2397a61d4502@m3g2000hsc.googlegroups.com...
>
> > > The file was created with modeWrite and modeCreate. However, this fil=
e
> > > is created by another program at a different time and it has no
> > > bearing on the issue at hand.
>
> > The writer program is the one that should do:
>
> > if( fIn.Open( csPath, CFile::modeWrite | CFile::shareDenyWrite ) )
> > {
> > ...
> > }
>
> > to make sure it is the only process that can write to the file! But thi=
s
> > says nothing about reading, so multiple files can read this file while =
it
> > is
> > being written to. Isn't this what you want?
>
> > Thanks,
> > David

0
the44secs (141)
7/22/2008 7:25:44 PM
I'm curious why, in all this discussion, nobody has bothered to single-step into the Open
handler and see what the ::CreateFile arguments are!

Note that there IS no option for ::CreateFile to "deny writes".  There is an option to
PERMIT READS (FILE_SHARE_READ), so the issue is, what is this mysterious shareDenyWrite
transformed into in the actual CreateFile call?  Do we even have a clue that the code that
does this is correct?  Since nobody has bothered to answer that question, I don't see why
this has gone on for so long!

The call, at the lowest level, should be

CreateFile(filename, 
                    GENERIC_READ,
                    FILE_SHARE_READ,
	    NULL,
	    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
	    NULL);

Until you know that this is what has happened, arguing about the MFC flags seems
pointless.

And yes, I get what the OP is trying to do: open an existing, inactive file with multiple
readers and blocking any potential writers.  If I wanted to do this, I would use
CreateFile as above, and if CFile::Open didn't behave as expected, the first thing I'd do
is make sure that it is properly translated to the above sequence.  If it is, then there
are issues in the operating system.  If it isn't, there's a bug in MFC.
					joe

On Sat, 19 Jul 2008 21:00:14 -0700 (PDT), Alexander <the44secs@yahoo.com> wrote:

>I want to prevent writing to a file but allow several processes to
>read it simultaneously. The flag shareDenyWrite does the first but not
>the second and I'm forced to use shareDenyNone (which works).
>
>Any thoughts?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
7/22/2008 9:29:08 PM
Yes, this is the right code. Why you want any different?

"Alexander" <the44secs@yahoo.com> wrote in message 
news:db1f608b-bb80-403d-a6f9-dcb2804a2e3a@j22g2000hsf.googlegroups.com...
All threads use this same code:

CStdioFile fIn;

if( fIn.Open( csPath, CFile::modeRead | CFile::shareDenyNone ) )
{
....

}

That code works.

If shareDenyNone is taken out, shared read is not allowed.



On Jul 23, 1:06 am, "Alexander Grigoriev" <al...@earthlink.net> wrote:
> How are you opening the files for read?
>
> "Alexander" <the44s...@yahoo.com> wrote in message
>
> news:9eeea132-fdb9-4469-b5c5-7edb4eaca46a@p25g2000hsf.googlegroups.com...
> Ok, guys. I think I'm not getting across.
>
> 1. No thread writes to the file. Writing is not an issue.
> 2. Several threads read the file at the same time.
>
> The problem is that I found that the only way to allow several threads
> to read the file is by using shareDenyNone. In particular:
>
> 1. If I don't use shareDenyNone, multiple reads are not allowed.
> 2. If I use shareDenyWrite, multiple reads are not allowed.
>
> Solution? Use shareDenyNone _which_ does not make sense when all you
> want is to allow shared reads.
>
> On Jul 22, 10:26 pm, "David Ching" <d...@remove-this.dcsoft.com>
> wrote:
>
>
>
> > "Alexander" <the44s...@yahoo.com> wrote in message
>
> >news:03400894-db1f-4a7a-af7d-2397a61d4502@m3g2000hsc.googlegroups.com...
>
> > > The file was created with modeWrite and modeCreate. However, this file
> > > is created by another program at a different time and it has no
> > > bearing on the issue at hand.
>
> > The writer program is the one that should do:
>
> > if( fIn.Open( csPath, CFile::modeWrite | CFile::shareDenyWrite ) )
> > {
> > ...
> > }
>
> > to make sure it is the only process that can write to the file! But this
> > says nothing about reading, so multiple files can read this file while 
> > it
> > is
> > being written to. Isn't this what you want?
>
> > Thanks,
> > David


0
alegr (1131)
7/23/2008 5:00:00 AM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:arjc84dlsk1mpca1vrp6ur2brul4jdk1n2@4ax.com...
> I'm curious why, in all this discussion, nobody has bothered to 
> single-step into the Open
> handler and see what the ::CreateFile arguments are!
>
> Note that there IS no option for ::CreateFile to "deny writes".  There is 
> an option to
> PERMIT READS (FILE_SHARE_READ), so the issue is, what is this mysterious 
> shareDenyWrite
> transformed into in the actual CreateFile call?  Do we even have a clue 
> that the code that
> does this is correct?  Since nobody has bothered to answer that question, 
> I don't see why
> this has gone on for so long!
>
> The call, at the lowest level, should be
>
> CreateFile(filename,
>                    GENERIC_READ,
>                    FILE_SHARE_READ,
>     NULL,
>     OPEN_EXISTING,
>                    FILE_ATTRIBUTE_NORMAL,
>     NULL);
>
> Until you know that this is what has happened, arguing about the MFC flags 
> seems
> pointless.
>
> And yes, I get what the OP is trying to do: open an existing, inactive 
> file with multiple
> readers and blocking any potential writers.  If I wanted to do this, I 
> would use
> CreateFile as above, and if CFile::Open didn't behave as expected, the 
> first thing I'd do
> is make sure that it is properly translated to the above sequence.  If it 
> is, then there
> are issues in the operating system.  If it isn't, there's a bug in MFC.
> joe
>

That's a good point.  I did trace into the MFC code and found modeRead is 
mapped to GENERIC_READ and modeDenyWrite is mapped to FILE_SHARE_READ.  So 
all is well here.

In fact, I could not repro the original issue.  I wrote a program called 
FileLock (poorly named but still) available at 
http://dcsoft.com/private/filelock.zip (MFC source code included, for 
VC2008) that lets you specify a file path, open mode, and share mode.  I 
specified a file called c:\x.bat on my PC, Read mode, and shareDenyWrite. 
It opened fine.

I then opened another instance of the app and repeated the above.  It was 
also opened fine.  So the original claim that shareDenyWrite prevented 
multiple apps from opening the file did not happen to me.

I also verified that while either only the first, or both the first and 
second instances of my app had the file open, I could not edit and save the 
file in notepad (notepad gave an error and opened File Save dialog for me to 
specify another filename).

So it looks like all is well here.

-- David



0
dc2983 (3206)
7/23/2008 5:08:27 AM
Joseph expressed it better than I have. Apologies to the thread for my
lack of verbal dexterity. His words "open an existing, inactive file
with multiple readers and blocking any potential writers" is precisely
the issue.

David. Thank you for taking the time to put together a test project.
The idea that modeDenyWrite is mapped to FILE_SHARE_READ is strangely
counterintuitive but that was my first thought too. It didn't work for
me but since you have verified that it indeed works, I will take (yet)
another closer look at the code.

Thanks again to everyone that has taken the time to help me out.



On Jul 23, 2:08=A0pm, "David Ching" <d...@remove-this.dcsoft.com> wrote:
> "Joseph M. Newcomer" <newco...@flounder.com> wrote in messagenews:arjc84d=
lsk1mpca1vrp6ur2brul4jdk1n2@4ax.com...
>
>
>
>
>
> > I'm curious why, in all this discussion, nobody has bothered to
> > single-step into the Open
> > handler and see what the ::CreateFile arguments are!
>
> > Note that there IS no option for ::CreateFile to "deny writes". =A0Ther=
e is
> > an option to
> > PERMIT READS (FILE_SHARE_READ), so the issue is, what is this mysteriou=
s
> > shareDenyWrite
> > transformed into in the actual CreateFile call? =A0Do we even have a cl=
ue
> > that the code that
> > does this is correct? =A0Since nobody has bothered to answer that quest=
ion,
> > I don't see why
> > this has gone on for so long!
>
> > The call, at the lowest level, should be
>
> > CreateFile(filename,
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0GENERIC_READ,
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0FILE_SHARE_READ,
> > =A0 =A0 NULL,
> > =A0 =A0 OPEN_EXISTING,
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0FILE_ATTRIBUTE_NORMAL,
> > =A0 =A0 NULL);
>
> > Until you know that this is what has happened, arguing about the MFC fl=
ags
> > seems
> > pointless.
>
> > And yes, I get what the OP is trying to do: open an existing, inactive
> > file with multiple
> > readers and blocking any potential writers. =A0If I wanted to do this, =
I
> > would use
> > CreateFile as above, and if CFile::Open didn't behave as expected, the
> > first thing I'd do
> > is make sure that it is properly translated to the above sequence. =A0I=
f it
> > is, then there
> > are issues in the operating system. =A0If it isn't, there's a bug in MF=
C.
> > joe
>
> That's a good point. =A0I did trace into the MFC code and found modeRead =
is
> mapped to GENERIC_READ and modeDenyWrite is mapped to FILE_SHARE_READ. =
=A0So
> all is well here.
>
> In fact, I could not repro the original issue. =A0I wrote a program calle=
d
> FileLock (poorly named but still) available athttp://dcsoft.com/private/f=
ilelock.zip(MFC source code included, for
> VC2008) that lets you specify a file path, open mode, and share mode. =A0=
I
> specified a file called c:\x.bat on my PC, Read mode, and shareDenyWrite.
> It opened fine.
>
> I then opened another instance of the app and repeated the above. =A0It w=
as
> also opened fine. =A0So the original claim that shareDenyWrite prevented
> multiple apps from opening the file did not happen to me.
>
> I also verified that while either only the first, or both the first and
> second instances of my app had the file open, I could not edit and save t=
he
> file in notepad (notepad gave an error and opened File Save dialog for me=
 to
> specify another filename).
>
> So it looks like all is well here.
>
> -- David

0
the44secs (141)
7/23/2008 6:39:08 AM
I didn't have time to do that, but that was going to be my next attempt...probably today,
since I'm having a major server reconfiguration done here (S2008 and virtual servers, plus
mirrored replication).  I don't even try to do this sort of thing; I hire someone to do it
for me, so I was going to have some dead time.  But since you've already run the test, I
don't have to.  So it looks like the problem lies somewhere else.

I'd suggest the process monitor (www.sysinternals.com) or the more primitive file monitor
and have the OP check that what is claimed is indeed what is happening, and that no one
else has the file open.
					joe

On Tue, 22 Jul 2008 22:08:27 -0700, "David Ching" <dc@remove-this.dcsoft.com> wrote:

>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:arjc84dlsk1mpca1vrp6ur2brul4jdk1n2@4ax.com...
>> I'm curious why, in all this discussion, nobody has bothered to 
>> single-step into the Open
>> handler and see what the ::CreateFile arguments are!
>>
>> Note that there IS no option for ::CreateFile to "deny writes".  There is 
>> an option to
>> PERMIT READS (FILE_SHARE_READ), so the issue is, what is this mysterious 
>> shareDenyWrite
>> transformed into in the actual CreateFile call?  Do we even have a clue 
>> that the code that
>> does this is correct?  Since nobody has bothered to answer that question, 
>> I don't see why
>> this has gone on for so long!
>>
>> The call, at the lowest level, should be
>>
>> CreateFile(filename,
>>                    GENERIC_READ,
>>                    FILE_SHARE_READ,
>>     NULL,
>>     OPEN_EXISTING,
>>                    FILE_ATTRIBUTE_NORMAL,
>>     NULL);
>>
>> Until you know that this is what has happened, arguing about the MFC flags 
>> seems
>> pointless.
>>
>> And yes, I get what the OP is trying to do: open an existing, inactive 
>> file with multiple
>> readers and blocking any potential writers.  If I wanted to do this, I 
>> would use
>> CreateFile as above, and if CFile::Open didn't behave as expected, the 
>> first thing I'd do
>> is make sure that it is properly translated to the above sequence.  If it 
>> is, then there
>> are issues in the operating system.  If it isn't, there's a bug in MFC.
>> joe
>>
>
>That's a good point.  I did trace into the MFC code and found modeRead is 
>mapped to GENERIC_READ and modeDenyWrite is mapped to FILE_SHARE_READ.  So 
>all is well here.
>
>In fact, I could not repro the original issue.  I wrote a program called 
>FileLock (poorly named but still) available at 
>http://dcsoft.com/private/filelock.zip (MFC source code included, for 
>VC2008) that lets you specify a file path, open mode, and share mode.  I 
>specified a file called c:\x.bat on my PC, Read mode, and shareDenyWrite. 
>It opened fine.
>
>I then opened another instance of the app and repeated the above.  It was 
>also opened fine.  So the original claim that shareDenyWrite prevented 
>multiple apps from opening the file did not happen to me.
>
>I also verified that while either only the first, or both the first and 
>second instances of my app had the file open, I could not edit and save the 
>file in notepad (notepad gave an error and opened File Save dialog for me to 
>specify another filename).
>
>So it looks like all is well here.
>
>-- David
>
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
7/23/2008 12:36:54 PM
Reply:

Similar Artilces:

not enough memory when sorting email
I continue to get an error message saying I don't have enough memory for my e-mail rules used for sorting my e- mail into their proper boxes. CAn you please increase it? Can it be solved? ...

not enough resources
Hi there Hope someone can help. I am running excel 2002, and just recently been getting messages when trying to save work. Its all ok for about an hour then it locks up when I try to save, when I have 2 or 3 workbooks open. It says not enough resources close some other running programs. I am not running any others at the time. after many trys it finally says disk full. I am running xp home, service pack 2. I have plenty of disk space about 10gb so that's not the problem. any help would be appreciated. Also when I now start up excel a blank workbook appears this never used to. Also when I o...

Not enough memory to load graphics
Hi there, I've got a problem with Microsoft Publisher 2000. Whenever I try and paste a bitmap, it brings up the message that "publisher doesnt have enough memory to load graphics or embedded objects". Now, this doesnt happen on my 4 years old computer, it happens on my brand new computer - it has 2.8GHZ, 512MB RAM, 20GB Hard Drive. Why? After managing to set up OE-QuoteFix on his new PC, Ed reads a message from Omar <anonymous@discussions.microsoft.com>... > I've got a problem with Microsoft Publisher 2000. Whenever > I try and paste a bitmap, it brings up...

Do you have enough setup information?
Because everyone's business is different, the Great Plains program is highly customizable; you have a lot of configuration options. Does the Great Plains Help documentation provide you with enough information to know how to set up the program before you enter your first transaction? You can reply to this message, or click the link below to type your comments on the Microsoft® Business Solutions–Great Plains® User Assistance Team documentation survey site. http://weblogs.asp.net/bizdoc/archive/2004/11/12/256684.aspx -Ryan -- This posting is provided "AS IS" wi...

shareDenyWrite is not enough
I want to prevent writing to a file but allow several processes to read it simultaneously. The flag shareDenyWrite does the first but not the second and I'm forced to use shareDenyNone (which works). Any thoughts? "Alexander" <the44secs@yahoo.com> wrote in message news:6c435000-7beb-4b49-96c5-c0db4423f89a@u6g2000prc.googlegroups.com... >I want to prevent writing to a file but allow several processes to > read it simultaneously. The flag shareDenyWrite does the first but not > the second and I'm forced to use shareDenyNone (which works). > shareDenyWrite...

Enough. Where is the policy?
Okay, Who the heck is in charge on these groups? Someone totally hidden and entirely unaccountable..? What's the posting policy and where the heck is some honesty about how these groups are moderated..? Where is the FAQ..? (or FAQs..?) Yes, I've had it. I'm upset that 1 or 2 critical posts I made didn't get posted. So, you can contact me at: ==================================================== Scott Davis, 45 Dunfield Av, Unit 2117 Self-Employed Toronto, ON, Canada, M4S 2H4 Tech Consultant Mobile. (416) 432-4334 The IP addrs I use to post all UseNet: 66.207.21...

Not enough memory?
I am trying to send a 172MB attachment, but get the message "Not enough memory"? I have 4 GB RAM installed, with a net of 2.87 GB available with nothing running and 735GB avilable on my hard drive. Why am I getting this message? Is there a size limitation in Windows Mail? -- McM I don't know of any server that would allow a 172MB message. Even if they did, you'd probably end up with a really teed-off recipient when they tried to download it. Use an upload site. Here are a couple, but you can Google for more. Upload large files. An alternative to e-mail....

there isn't enough free memory to refresh the display
I'm working with a table of over 1 million records. After running a query I try open it in design view I get the above message. Any suggestions how to get rid of this On Wed, 25 Nov 2009 16:29:01 -0800, Siegfried <Siegfried@discussions.microsoft.com> wrote: Run it on a machine with more memory, or perhaps switch to a server database like SQL Server. Are you talking about a select query or an action query? -Tom. Microsoft Access MVP >I'm working with a table of over 1 million records. After running a query I >try open it in design view I get the abo...

Are you GOOD ENOUGH for Heaven ??
Are you GOOD ENOUGH for Heaven ?? Click here to read more.... http://emailministry.webs.com/areyougoodenoughforheav.htm Thanks ...

Not enough memory
I have a friend who edits a Newsletter in Publisher 2000 and recently he has been beset by not enough memory errors when trying to paste text from an Outlook Express body into a Publisher text box. Anyone who edits Newsletters knows that many of their contributors are reluctant or unable to use attachments so this procedure is often necessary. He has used this same method for ages before with no problems. He can overcome the problem by saving to Word and pasting from there. I'm sure I had this problem myself once and doing a search provided an answer. I can't find the so...

Help with not enough memory error message on Publisher 2007
My company purchased new computer with Office 2007 suite. Computer has XP Pro with 3 GB Ram. As I have been using Publisher, I have received two error messages. #1 - "Cannot complete this operation" when I try to print a document a second or third time- the first time I can print, then it "disconnects" from the printer. #2 - I received an error message today that says, "There is not enough memory to complete this operation. To make more memory available, close other programs and try again." I am confused as to why this is happening. My old computer w...

Not Enough Memory
Hello Everybody! as I tried to retrieve some Information from another excel File I stumbled upon a failer. "NOT ENOUGH MEMORY" and "Runtime Error '1004': Unable To set the formula Array Property of the Range Class" I Checked My task mananger but the MEM Usage remained low during the running of the Macro, The CPU Usage However Sky Roketed. While I have 512 MB Ram. I enlarged the Swap File to 1500 but still it gives me the same failure. I'm beginning to think it has something to do with the macro itself. However, I can't see whats wrong. I hope someon...

Not enough memory
The situation is as follows: I have a fairly large Excel file opened(1.7 MB), and can open another large Excel file (1.2MB) in the same folder, with no problems. If, however, I attempt to open another Excel file in another folder larger than around 200K, with only the one larger file already opened, I get the message "Not enough memory"! My computer RAM is at 256MB, so where am I running low on memory?? Any suggestions would be appreciated. Charles Williams has a fairly decent explanation of Excel's "Memory" message. http://www.decisionmodels.com/memlimitsc.htm ...

Not enough results
Dear Wizards, I'm using MS Money 17.0.120.727 I have a search that uses the DJ 30 industrials. Problem is that the search only returns 23 results. I've reset the "Return top __ matches" to 35 but it still only returns 23. I have recently moved the program to a new machine. Any suggestions? TIA for your help! Sam ...

Not enough memory #3
I am using publisher 2000 on a Windows 98 machine and it has worked fine for some time. Now for some reason when I try to open an existing publisher doc I get the message: There is not enough memory to complete this operation. To make more memory available, close other programs, and try again. I have closed all other programs and I still get this message. Does anyone have any idea's. All help is greatly appreciated. Tommy Tommy Romans wrote: > I am using publisher 2000 on a Windows 98 machine and it > has worked fine for some time. Now for some reason when I > try to open...

not enough memory
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel error msg not enough memory on excel and power point office 08 <br> macbook pro 10.6 ver <br> office 08 ver 12.2.3(091001) <br> memory 2gb 1067mhz ddr3 <br> processor 2ghz intel core 2 duo Believe it :-) You don't have enough memory! Snap in at least 2GB more memory. In a MacBook Pro, you're better off to install 6 or 8GB to enable the machine to reach its full potential. Cheers On 15/12/09 11:36 AM, in article 59baf092.-1@webcrossing.JaKIaxP2ac0, "Snow_l...

not enough memory or disk space to display or print the picture after 1st time
Version: 2004 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC I know this topic has been covered before, but not in the way I get the problem. I can open a document with a math formula or a graphic the FIRST time and it will correctly display. Any changes to the document or any subsequent openings I then get the error message, &quot;not enough memory or disk space to display or print the picture&quot;. <br><br>eMac 1.25 Gz 10.4.6, Word 2004 <br><br>Thanks. One possible cause: You're *way* behind on Tiger -- it's been at 10.4.11 for ...

Vlookup is not enough !!
Hi there, Please help me out with the folliwing query. This is my data which I wish to lookup: Group name 12 Brian 33 Norman 12 Victor 12 Sonia 25 Mary 33 Horris 25 Peter 44 james 66 Holden I wish to select say groups 12 & 33 and wish to obtain the following answer (i.e. list all under each other who belong to that group) Thereofre: 12 Brian 12 Victor 12 Sonia 33 Norman 33 Horris Is this possible ... I hope I made myself clear enough. If not, please reply and I will elaborate furthe...

Not Enough Memory
Hi. My database was chugging along just fine until one day... It began to tell me "There isn't enough memory to perform this operation. Close unneeded programs and try the operation again" when I tried to open a form. I closed all programs except for Access and the error still popped up. It only happens to a handful of my twenty or so forms. Any suggestions as to how I can fix this? Thanks ever so much! Stacey How big are the tables that the forms are linked to? I'd try to design your forms so that they only read one record at a time. -- Dorian "G...

Please Verify You have enough crystal license
Hi, When i click the report module on CRM, i got the following error. Crystal Reports Logon Error Please verify that you have enough crystal licenses I noticed that in ISS Manager, the 4 extensions are also missing (.cri, ..rpt, .csp, .cwr). Also if i go to http://crmserver/reports/crystallogon.csp, the page will return http 500 internal server error. I also saw KB 862678 on how to rebuild the crystal Apps. In this case, can i just upload the report toolkit into my crmserver?? Why did i get the internal server error when i logon to crystallogon.csp?? Any ideas as why this is happened...

not enough resources
I have code that does the following: Refreshes 730 X 26 cells from an external data source for the first item in a list Copies the refreshed cells to a new workbook removes rows for items that have no data for the item. do while <> end of list Refreshes the cells for the next item on the list. 730 X26 copies and pastes the cells of the refeshed data under the last set of data pasted. removes rows for the item that have no data Refresh the next item on the list end while I have 5000 items. I estimated the new workbook will contain a sheet with 10,000 rows due t...

won't calculate far enough
Hello, I have a formula (see below) that will work for rows 2-1000, but once I change it to look for columns beyond 2000, it will not work anymore... Any suggestions? This works: =SUMPRODUCT(--('Q Info'!$A$2:$A$1000= 'Per Peice'!A9),'Q Info'!$C$2:$C$1000*'Q Info'!$B$2:$B$1000) This DOESN'T work: =SUMPRODUCT(--('Q Info'!$A$2:$A$9999= 'Per Peice'!A9),'Q Info'!$C$2:$C$9999*'Q Info'!$B$2:$B$9999) -- Nicki Taylor Both you formulas work for me. -- HTH Sandy sandymann2@mailinator.com Replace@mailinator.com with @tiscal...

not enough rows
Excel is limited to 65,536 rows. What is the work around to make this limit higher? There is no workaround except using multiple sheets -- Regards, Peo Sjoblom (No private emails please, for everyone's benefit keep the discussion in the newsgroup/forum) "mc" <anonymous@discussions.microsoft.com> wrote in message news:300bc01c46da1$617ed200$a301280a@phx.gbl... > Excel is limited to 65,536 rows. What is the work around > to make this limit higher? "mc" <anonymous@discussions.microsoft.com> wrote in message news:300bc01c46da1$617ed200$a3012...

Not enough resources..
I have created an excel sheet with some rather simple comboboxes, command buttons etc... I get a message saying "Not enough resources to display completely" often now, when I click on these comboboxes. I have over 512MB or ram and lots of room on the HD. What is going on anyone knows? I tried it on my other laptop, running a different version of Windows, different make of laptop etc.. and i get the same message too. Thanks Aranna I enclose below a quote from Ron Martell(MS MVP Windows) regarding "system resources". Makes for some enlightening reading.....Resou...

Not Enough Resources #2
This must be an old issue but I have a very large Excel spreadsheet that at times will go out of control and express an error of "Not enough resources". I have 2 GB RAM and the RAM in use is only 700-800MB. Are there any solutions for this problem. Thank you Maybe... http://support.microsoft.com/kb/313275 "Not enough memory" error messages..." Also... http://www.cpearson.com/excel/HintsAndTipsForNewsgroupUsers.aspx "Hints and Tips..." -- Jim Cone Portland, Oregon USA "pestocat" <gel114@theconnection.com> wrote in message This mu...