ankush gupta wrote:
> Hi All,
>
> I have a Multithreaded Application in which i am trying to open a Compounded
> Stream using OpenStream method of IStream interface in a following manner:
>
> CComPtr<IStream> ptrDataStream;hr =
> ptrStorage->OpenStream(strDataStreamName,0,STGM_READ |
> STGM_SHARE_EXCLUSIVE,0,&ptrDataStream);
> if (hr)
> return hr;
>
> The problem which I am facing is that at some time not always OpenStream
> return Access Denied error. After getting this error I added a lock in this
> function which is released at the end of the function, but this change
> doesn't effect the error .
> Please help me in this regard.
>
> Thanks in Advance
> Ankush Gupta
What happens if you drop STGM_SHARE_EXCLUSIVE? You are asking for
exclusive rights to the file/data stream.
Additionally, from MSDN Library (which looks terrible under IE6 as of
late - looks like Microsoft is finally killing it off):
-----
When the STGM_DIRECT flag is specified, only one of the following
combination of flags may be specified from the access and sharing groups.
STGM_READ | STGM_SHARE_DENY_WRITE
STGM_READWRITE | STGM_SHARE_EXCLUSIVE
STGM_READ | STGM_PRIORITY
Be aware that direct mode is implied by the absence of STGM_TRANSACTED.
That is, if neither STGM_DIRECT nor STGM_TRANSACTED is specified,
STGM_DIRECT is assumed.
-----
Without specifying STGM_TRANSACTED, you appear to be limited to the
above combinations. Since I don't have any more context to this
problem, it is difficult to say why it is failing. When messing with
COM objects, it is ideal to keep them contained within a single thread.
Passing them between threads is messy and gets you into things like
Apartment threading models. It is easier to work with them if you can
contain each object to the thread it was created in.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/