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. ATL / WTL / STL
  4. How to have access to the members of a class

How to have access to the members of a class

Scheduled Pinned Locked Moved ATL / WTL / STL
c++tutorialworkspace
8 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.
  • R Offline
    R Offline
    Roozbeh69
    wrote on last edited by
    #1

    Hi everybody I have written an ATL 3.0 project including two sample classes named CAttachment & CAttachments. These classes have interfaces IAttachment & IAttachments in order. IAttachments has got a method named "Item" that returns a result of the type of IAttachment. But before returning the IAttachment, I want to call some member functions of the CAttachment class to setup the IAttachment properly. I know how to create the IAttachment interface, but I don't know how to have access to the members of the CAttachment from the "Item" method. I will be thankful if anybody replies to me. Regards, Roozbeh.

    P 1 Reply Last reply
    0
    • R Roozbeh69

      Hi everybody I have written an ATL 3.0 project including two sample classes named CAttachment & CAttachments. These classes have interfaces IAttachment & IAttachments in order. IAttachments has got a method named "Item" that returns a result of the type of IAttachment. But before returning the IAttachment, I want to call some member functions of the CAttachment class to setup the IAttachment properly. I know how to create the IAttachment interface, but I don't know how to have access to the members of the CAttachment from the "Item" method. I will be thankful if anybody replies to me. Regards, Roozbeh.

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      CAttachement *pAttach;
      IAttachment pIAttach;
      pAttach = (CAttachement*) pIAttach;

      pAttach can now call the class members of the its class.


      This space is empty.

      J 1 Reply Last reply
      0
      • P Prakash Nadar

        CAttachement *pAttach;
        IAttachment pIAttach;
        pAttach = (CAttachement*) pIAttach;

        pAttach can now call the class members of the its class.


        This space is empty.

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        *bzzt* Wrong way. This should never ever be done. You can never be certain what pIAttach points to. Any COM book will tell you this at least a dussin times. :) A better way to gain access to members of CAttachment is to use CComObject<CAttachement> instead.

        CComObject<CAttachement>* pObj;
        HRESULT hr = CComObject<CAttachement>::CreateInstance(&pObj);
        pObj->AddRef(); // CComObject<CAttachement>::CreateInstance does not addref!
        pObj->member = value;
        pObj->InterfaceMethod();
        IAttachment* pAtt = pObj; // can safely be passed along as interface pointer to other apartments, etc

        -- Unser Tanz ist so wild! Ein neuer böser Tanz. Alle gegen Alle!

        P 1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          *bzzt* Wrong way. This should never ever be done. You can never be certain what pIAttach points to. Any COM book will tell you this at least a dussin times. :) A better way to gain access to members of CAttachment is to use CComObject<CAttachement> instead.

          CComObject<CAttachement>* pObj;
          HRESULT hr = CComObject<CAttachement>::CreateInstance(&pObj);
          pObj->AddRef(); // CComObject<CAttachement>::CreateInstance does not addref!
          pObj->member = value;
          pObj->InterfaceMethod();
          IAttachment* pAtt = pObj; // can safely be passed along as interface pointer to other apartments, etc

          -- Unser Tanz ist so wild! Ein neuer böser Tanz. Alle gegen Alle!

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #4

          yeah correct.:doh:


          Code Review Correction.

          if(pObList == NULL)
          {
          pObList = NULL;
          delete pObList;
          }

          MSN Messenger. prakashnadar@msn.com

          S 1 Reply Last reply
          0
          • P Prakash Nadar

            yeah correct.:doh:


            Code Review Correction.

            if(pObList == NULL)
            {
            pObList = NULL;
            delete pObList;
            }

            MSN Messenger. prakashnadar@msn.com

            S Offline
            S Offline
            Steve S
            wrote on last edited by
            #5

            Surely not. if (pObList != NULL) { delete pObList; pObList = NULL; } unless, of course, you've worked where I'm working at the moment, where apparently that would be an acceptable style of coding. :( Steve S

            P 1 Reply Last reply
            0
            • S Steve S

              Surely not. if (pObList != NULL) { delete pObList; pObList = NULL; } unless, of course, you've worked where I'm working at the moment, where apparently that would be an acceptable style of coding. :( Steve S

              P Offline
              P Offline
              Prakash Nadar
              wrote on last edited by
              #6

              Steve S wrote: Surely not. sure i aggree with you, it was the code review correction that i gave to my coworker (its a mistake that i asked him to correct it) but for some reason, that piece code works perfectly, coz deleteing null pointer is ignored. :-)


              MSN Messenger. prakashnadar@msn.com

              S 1 Reply Last reply
              0
              • P Prakash Nadar

                Steve S wrote: Surely not. sure i aggree with you, it was the code review correction that i gave to my coworker (its a mistake that i asked him to correct it) but for some reason, that piece code works perfectly, coz deleteing null pointer is ignored. :-)


                MSN Messenger. prakashnadar@msn.com

                S Offline
                S Offline
                Steve S
                wrote on last edited by
                #7

                Indeed :) However, unless somewhere there is a corresponding delete for non-null pointers, I suspect you might have at the very least some diagnostics about leaks when running under the debugger. Steve S

                P 1 Reply Last reply
                0
                • S Steve S

                  Indeed :) However, unless somewhere there is a corresponding delete for non-null pointers, I suspect you might have at the very least some diagnostics about leaks when running under the debugger. Steve S

                  P Offline
                  P Offline
                  Prakash Nadar
                  wrote on last edited by
                  #8

                  Steve S wrote: unless somewhere there is a corresponding delete for non-null pointers no this is was the only delete for that object in the dtor. Yes there was a memory leak in this case and other places. I just placed it in my sig to show that how stupid anyone can get to write that kinda of code. But then i removed it coz i thought it was not rite to make a joke of others programming pratice.


                  MSN Messenger. prakashnadar@msn.com

                  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