Re: CComPtr and CComQIPtr
From: Tim Roberts (timr_at_probo.com)
Date: 08/14/04
- Next message: Tim Roberts: "Re: Does anyone know where to and how to retrieve local TV Guide data?"
- Previous message: Don Wilson: "Re: Multiple Port Grabber Cards"
- In reply to: Martin Danielsson: "Re: CComPtr and CComQIPtr"
- Next in thread: Gabest: "Re: CComPtr and CComQIPtr"
- Reply: Gabest: "Re: CComPtr and CComQIPtr"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 13 Aug 2004 23:35:58 -0700
"Martin Danielsson"
<martin.my_finger.danielsson@spam.spam.nospam.im-c.spamspam.de> wrote:
>> > CComQIPtr<IBaseFilter> pBaseFilter(pUnk);
>> > if (!pBaseFilter)
>> > hr = E_NOINTERFACE;
>>
>> I prefer this style usually:
>>
>> if(CComQIPtr<IBaseFilter> pBaseFilter = pUnk)
>> {
>> // do something with pBaseFilter
>> }
>
>Wow. Ok, but I think this looks really weird. I had to think for half a
>minute before I got what you were doing here :)
>
>> It's a bit like dynamic_cast.
>
>Perhaps; I didn't realize you could use CComQIPtr like that. Good to know.
This is not all that magic; he is just declaring a variable as part of the
"if" expression, similar to:
for( int i = 0; i < 8; i++ )
The problem with his code (and I admit it's a minor problem) is that I
would be constantly asking myself "does pBaseFilter expire at the end of
the 'if' statement, or is it part of the surrounding scope?" In this
particular case, pBaseFilter *IS* part of the "if" scope, so it works like
he says, but the confusion surrounding "for" statements would make it so I
have to look twice every time I saw it.
-- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc
- Next message: Tim Roberts: "Re: Does anyone know where to and how to retrieve local TV Guide data?"
- Previous message: Don Wilson: "Re: Multiple Port Grabber Cards"
- In reply to: Martin Danielsson: "Re: CComPtr and CComQIPtr"
- Next in thread: Gabest: "Re: CComPtr and CComQIPtr"
- Reply: Gabest: "Re: CComPtr and CComQIPtr"
- Messages sorted by: [ date ] [ thread ]