How to have access to the members of a class
-
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.
-
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.
CAttachement *pAttach;
IAttachment pIAttach;
pAttach = (CAttachement*) pIAttach;pAttach can now call the class members of the its class.
This space is empty.
-
CAttachement *pAttach;
IAttachment pIAttach;
pAttach = (CAttachement*) pIAttach;pAttach can now call the class members of the its class.
This space is empty.
*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!
-
*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!
yeah correct.:doh:
Code Review Correction.
if(pObList == NULL)
{
pObList = NULL;
delete pObList;
}MSN Messenger. prakashnadar@msn.com
-
yeah correct.:doh:
Code Review Correction.
if(pObList == NULL)
{
pObList = NULL;
delete pObList;
}MSN Messenger. prakashnadar@msn.com
-
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
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
-
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
-
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
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