Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CComPtr<istream> releasing problem</istream>

CComPtr<istream> releasing problem</istream>

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionannouncement
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A Ms
    wrote on last edited by
    #1

    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?

    K S K 3 Replies Last reply
    0
    • A A Ms

      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?

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      use detach or different scope for the streams

      Press F1 for help or google it. Greetings from Germany

      A 1 Reply Last reply
      0
      • A A Ms

        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?

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        Amir_m wrote:

        because my Stream vars are defined with CComPtr class I coudn't use the Release method of my Stream variables.

        CComPtr has a Release[^] method. Use . ***NOT*** ->: pStream.Release();

        Steve

        A 1 Reply Last reply
        0
        • K KarstenK

          use detach or different scope for the streams

          Press F1 for help or google it. Greetings from Germany

          A Offline
          A Offline
          A Ms
          wrote on last edited by
          #4

          would you please explain it more I couldn't find any thing. a little code would be useful and there is no detach method

          K 1 Reply Last reply
          0
          • S Stephen Hewitt

            Amir_m wrote:

            because my Stream vars are defined with CComPtr class I coudn't use the Release method of my Stream variables.

            CComPtr has a Release[^] method. Use . ***NOT*** ->: pStream.Release();

            Steve

            A Offline
            A Offline
            A Ms
            wrote on last edited by
            #5

            of course I know But The Release Method of CComPtr Class is a private method and compiler does not let me to use it.

            S 1 Reply Last reply
            0
            • A A Ms

              would you please explain it more I couldn't find any thing. a little code would be useful and there is no detach method

              K Offline
              K Offline
              KarstenK
              wrote on last edited by
              #6

              CComPtr::Detach() http://msdn.microsoft.com/en-us/library/w200fbea%28VS.80%29.aspx[^]

              Press F1 for help or google it. Greetings from Germany

              A 1 Reply Last reply
              0
              • K KarstenK

                CComPtr::Detach() http://msdn.microsoft.com/en-us/library/w200fbea%28VS.80%29.aspx[^]

                Press F1 for help or google it. Greetings from Germany

                A Offline
                A Offline
                A Ms
                wrote on last edited by
                #7

                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:

                K 1 Reply Last reply
                0
                • A A Ms

                  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?

                  K Offline
                  K Offline
                  KingsGambit
                  wrote on last edited by
                  #8

                  May be you can try as follows:

                  void Foo()
                  {
                  {
                  CComPtr<IStream> m_pStream;
                  ::SHCreateStreamOnFileW(...);
                  }

                  {
                  CComPtr<IStream> m_pStream2;
                  ::SHCreateStreamOnFileW(...);
                  }
                  }

                  A 1 Reply Last reply
                  0
                  • K KingsGambit

                    May be you can try as follows:

                    void Foo()
                    {
                    {
                    CComPtr<IStream> m_pStream;
                    ::SHCreateStreamOnFileW(...);
                    }

                    {
                    CComPtr<IStream> m_pStream2;
                    ::SHCreateStreamOnFileW(...);
                    }
                    }

                    A Offline
                    A Offline
                    A Ms
                    wrote on last edited by
                    #9

                    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)

                    K 1 Reply Last reply
                    0
                    • A A Ms

                      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)

                      K Offline
                      K Offline
                      KingsGambit
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • A A Ms

                        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:

                        K Offline
                        K Offline
                        KarstenK
                        wrote on last edited by
                        #11

                        Casting is absolutitly no solution for this problem!!! use different scope for both variables

                        Press F1 for help or google it. Greetings from Germany

                        1 Reply Last reply
                        0
                        • A A Ms

                          of course I know But The Release Method of CComPtr Class is a private method and compiler does not let me to use it.

                          S Offline
                          S Offline
                          Stephen Hewitt
                          wrote on last edited by
                          #12

                          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

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups