Re: How to return string through output VARIANT from C++ COM object
From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 07/26/04
- Next message: Igor Tandetnik: "Re: How to return string through output VARIANT from C++ COM object"
- Previous message: newscorrespondent_at_charter.net: "MFC with SAP .net Connector?"
- In reply to: Kim Gräsman: "Re: How to return string through output VARIANT from C++ COM object"
- Next in thread: Phil Sherrod: "Re: How to return string through output VARIANT from C++ COM object"
- Reply: Phil Sherrod: "Re: How to return string through output VARIANT from C++ COM object"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 26 Jul 2004 18:35:05 -0400
"Kim Gräsman" <kim@mvps.org> wrote in message
news:uo5FR7ncEHA.2408@tk2msftngp13.phx.gbl
>> "If the variant to be cleared is a COM object that is passed by
>> reference, the vt field of the pvarg parameter is VT_DISPATCH |
>> VT_BYREF or VT_UNKNOWN | VT_BYREF. In this case, VariantClear does
>> not release the object. Because the variant being cleared is a
>> pointer to a reference to an object, VariantClear has no way to
>> determine if it is necessary to release the object. It is therefore
>> the responsibility of the caller to release the object or not, as
>> appropriate."
>
> Gah! I had no idea... I thought VariantClear was smarter than that.
It is plenty smart. A VT_BYREF variant does not own the resource it
holds a reference to. Hence VariantClear is not supposed to release it.
You can legally have
VARIANT var;
var.vt = VT_BSTR;
var.bstrVal = SysAllocString(OLESTR("blah"));
VARIANT varRef;
varRef.vt = VT_BSTR | VT_BYREF;
varRef.pbstrVal = &var.bstrVal;
VariantClear(&varRef); // does not relase the string
VariantClear(&var); // releases the string
> You would have to dereference the VARIANT then, before clearing its
> contents.
Illegal. The server is not supposed to touch the referred-to data, as
opposed to the data directly contained in the VARIANT. Straight
VariantClear implements correct semantics.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
- Next message: Igor Tandetnik: "Re: How to return string through output VARIANT from C++ COM object"
- Previous message: newscorrespondent_at_charter.net: "MFC with SAP .net Connector?"
- In reply to: Kim Gräsman: "Re: How to return string through output VARIANT from C++ COM object"
- Next in thread: Phil Sherrod: "Re: How to return string through output VARIANT from C++ COM object"
- Reply: Phil Sherrod: "Re: How to return string through output VARIANT from C++ COM object"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|