CComPtr<istream> releasing problem</istream>
-
Hi, I have used CComPtr class to declear two IStream type variable like below:
CComPtr<IStream> m_pStream;
CComPtr<IStream> m_pStream2;and some where in my code I Create a stream on a file and let my m_pStream variable point at it like below:
::SHCreateStreamOnFileW(FileName,STGM_READWRITE | STGM_SHARE_DENY_WRITE,&pStream);
Now I want to do sth cause the first Stream variable "m_pStream" release the specified File, so I could create the stream on the same file and let my secound Stream variable m_pStream2 points at it like below:
::SHCreateStreamOnFileW(FileName,STGM_READWRITE | STGM_SHARE_DENY_WRITE,&pStream2);
because my Stream vars are defined with CComPtr class I coudn't use the Release method of my Stream variables. even I have tested nullifying the first Stream variable but it didn't solve my problem. What should I do?
-
Hi, I have used CComPtr class to declear two IStream type variable like below:
CComPtr<IStream> m_pStream;
CComPtr<IStream> m_pStream2;and some where in my code I Create a stream on a file and let my m_pStream variable point at it like below:
::SHCreateStreamOnFileW(FileName,STGM_READWRITE | STGM_SHARE_DENY_WRITE,&pStream);
Now I want to do sth cause the first Stream variable "m_pStream" release the specified File, so I could create the stream on the same file and let my secound Stream variable m_pStream2 points at it like below:
::SHCreateStreamOnFileW(FileName,STGM_READWRITE | STGM_SHARE_DENY_WRITE,&pStream2);
because my Stream vars are defined with CComPtr class I coudn't use the Release method of my Stream variables. even I have tested nullifying the first Stream variable but it didn't solve my problem. What should I do?
-
Hi, I have used CComPtr class to declear two IStream type variable like below:
CComPtr<IStream> m_pStream;
CComPtr<IStream> m_pStream2;and some where in my code I Create a stream on a file and let my m_pStream variable point at it like below:
::SHCreateStreamOnFileW(FileName,STGM_READWRITE | STGM_SHARE_DENY_WRITE,&pStream);
Now I want to do sth cause the first Stream variable "m_pStream" release the specified File, so I could create the stream on the same file and let my secound Stream variable m_pStream2 points at it like below:
::SHCreateStreamOnFileW(FileName,STGM_READWRITE | STGM_SHARE_DENY_WRITE,&pStream2);
because my Stream vars are defined with CComPtr class I coudn't use the Release method of my Stream variables. even I have tested nullifying the first Stream variable but it didn't solve my problem. What should I do?
-
use detach or different scope for the streams
Press F1 for help or google it. Greetings from Germany
-
-
would you please explain it more I couldn't find any thing. a little code would be useful and there is no detach method
-
CComPtr::Detach() http://msdn.microsoft.com/en-us/library/w200fbea%28VS.80%29.aspx[^]
Press F1 for help or google it. Greetings from Germany
for m_pStream->Detach(); I got the following Error:
Error 1 error C2039: 'Detach' : is not a member of 'ATL::_NoAddRefReleaseOnCComPtr<T>'
Even I taype cast my CComPtr to CComPtrBase but again there were only to Member functions which both were in private scope!:confused:
-
Hi, I have used CComPtr class to declear two IStream type variable like below:
CComPtr<IStream> m_pStream;
CComPtr<IStream> m_pStream2;and some where in my code I Create a stream on a file and let my m_pStream variable point at it like below:
::SHCreateStreamOnFileW(FileName,STGM_READWRITE | STGM_SHARE_DENY_WRITE,&pStream);
Now I want to do sth cause the first Stream variable "m_pStream" release the specified File, so I could create the stream on the same file and let my secound Stream variable m_pStream2 points at it like below:
::SHCreateStreamOnFileW(FileName,STGM_READWRITE | STGM_SHARE_DENY_WRITE,&pStream2);
because my Stream vars are defined with CComPtr class I coudn't use the Release method of my Stream variables. even I have tested nullifying the first Stream variable but it didn't solve my problem. What should I do?
May be you can try as follows:
void Foo()
{
{
CComPtr<IStream> m_pStream;
::SHCreateStreamOnFileW(...);
}{
CComPtr<IStream> m_pStream2;
::SHCreateStreamOnFileW(...);
}
} -
May be you can try as follows:
void Foo()
{
{
CComPtr<IStream> m_pStream;
::SHCreateStreamOnFileW(...);
}{
CComPtr<IStream> m_pStream2;
::SHCreateStreamOnFileW(...);
}
} -
My Problem is accessing the file because the Stream Created previously doesn't release the file I can't access the file with another stream (even nullifying that stream doesn't cause it to release the file)
In the code segment in my previour post, m_pStream and m_pStream2 are in different scopes (between {}), so the streams will be closed automatically when the scope ends. So, both calls to SHCreateStreamOnFile(...) will be successfull.
-
for m_pStream->Detach(); I got the following Error:
Error 1 error C2039: 'Detach' : is not a member of 'ATL::_NoAddRefReleaseOnCComPtr<T>'
Even I taype cast my CComPtr to CComPtrBase but again there were only to Member functions which both were in private scope!:confused:
-
of course I know But The Release Method of CComPtr Class is a private method and compiler does not let me to use it.
Amir_m wrote:
of course I know But The Release Method of CComPtr Class is a private method and compiler does not let me to use it.
No, it's not private. The following compiles fine:
CComPtr<IStream> spStream;
spStream.Release();Steve