Simon
Wed Apr 20 10:49:31 CDT 2005
"MikeJohnson" <mikejohnson@volcanomail.com> wrote in message
news:1113970824.043055.141680@g14g2000cwa.googlegroups.com...
> There has to be a way to create a new
> _com_ptr_t -based object given a raw interface pointer?
>
> I have an IMessage*.
> I need to create an _MailItemPtr. (based upon _com_ptr_t).
>
> This did not compile:
>
> IMessage* pMessage;
> // set pMessage here
>
> _MailItemPtr pMailItem;
>
> pMailItem.Attach (pMessage);
>
>
> Thanks very much!
> -Mike
>
Assuming that _MailItemPtr is a typedef for _com_ptr_t<_MailItem> then you
can simply do:
_MailItemPtr pMailItem;
pMailItem = pMessage;
But, pMailItem may end up being NULL if the object pointed to by pMessage
does not support the _MailItem interface. The _com_ptr_t will QueryInterace
the IMessage* for the a pointer to the _MailItem interface.
You can't use Attach except with objects of type _MailItem* or _MailItemPtr.
You probably would not want to be doing Attach anyway, as it does not
increase the reference count on the object.
Look up operator= at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang__com_ptr_t.asp