class CComVariant : public tagVARIANT
CComVariant wraps the VARIANT type, which consists of a tagged union, as well as a member indicating the value type stored in the union. VARIANTs are typically used in Automation.
#include <atlbase.h>
See Also "VARIANT and VARIANTARG" in the Win32 SDK
Methods | |
Attach | Attaches a VARIANT to the CComVariant object. |
CComVariant | Constructor. |
ChangeType | Converts the CComVariant object to a new type. |
Clear | Clears the CComVariant object. |
Copy | Copies a VARIANT to the CComVariant object. |
Detach | Detaches the underlying VARIANT from the CComVariant object. |
ReadFromStream | Loads a VARIANT from a stream. |
WriteToStream | Saves the underlying VARIANT to a stream. |
Operators | |
operator = | Assigns a value to the CComVariant object. |
operator = = | Indicates whether the CComVariant object equals the specified VARIANT. |
operator!= | Indicates whether the CComVariant object does not equal the specified VARIANT. |
HRESULT Attach( VARIANT* pSrc );
Return Value
A standard HRESULT value.
Parameters
pSrc [in] Points to the VARIANT to be attached to the object.
Remarks
Attaches the specified VARIANT to the CComVariant object. Attach sets the variant type of the object to VT_EMPTY.
CComVariant Overview | Class Members
See Also CComVariant::Detach, "VARIANT and VARIANTARG" in the Win32 SDK
CComVariant( );
CComVariant( const CComVariant& varSrc );
CComVariant( const VARIANT& varSrc );
CComVariant( LPCOLESTR lpsz );
CComVariant( LPCSTR lpsz );
CComVariant( BSTR bstrSrc );
CComVariant( int nSrc );
CComVariant( BYTE nSrc );
CComVariant( short nSrc );
CComVariant( long nSrc, VARTYPE vtSrc = VT_I4 );
CComVariant( float fltSrc );
CComVariant( double dblSrc );
CComVariant( CY cySrc );
CComVariant( IDispatch* pSrc );
CComVariant( IUnknown* pSrc );
Parameters
varSrc [in] The CComVariant or VARIANT used to initialize the CComVariant object.
lpsz [in] The character string used to initialize the CComVariant object. The Unicode version specifies an LPCOLESTR; the ANSI version specifies an LPCSTR.
bstrSrc [in] The BSTR used to initialize the CComVariant object.
nSrc [in] The int, BYTE, short, or long used to initialize the CComVariant object.
vtSrc [in] The type for the CComVariant object. This parameter is available only when passing a long for nSrc. vtSrc can only be VT_I4 (the default value) or VT_ERROR; otherwise, the constructor will assert.
fltSrc [in] The float used to initialize the CComVariant object.
dblSrc [in] The double used to initialize the CComVariant object.
cySrc [in] The CY used to initialize the CComVariant object.
pSrc [in] The IDispatch or IUnknown pointer used to initialize the CComVariant object.
Remarks
Each constructor initializes the object by calling the VariantInit Win32 function. If you pass a parameter value, the constructor sets the objects value and type accordingly.
The destructor manages cleanup by calling CComVariant::Clear.
CComVariant Overview | Class Members
See Also "VARIANT and VARIANTARG", VariantInit, VariantCopy, and VariantClear in the Win32 SDK
HRESULT ChangeType( VARTYPE vtNew, const VARIANT* pSrc = NULL );
Return Value
A standard HRESULT value.
Parameters
vtNew [in] The new type for the CComVariant object.
pSrc [in] A pointer to the VARIANT whose value will be converted to the new type. The default value is NULL, meaning the CComVariant object will be converted in place.
Remarks
Converts the CComVariant object to a new type. If you pass a value for pSrc, ChangeType will use this VARIANT as the source for the conversion. Otherwise, the CComVariant object will be the source.
CComVariant Overview | Class Members
See Also "VARIANT and VARIANTARG", VariantChangeType in the Win32 SDK
HRESULT Clear( );
Return Value
A standard HRESULT value.
Remarks
Clears the CComVariant object by calling the VariantClear API function.
The destructor automatically calls Clear.
CComVariant Overview | Class Members
See Also "VARIANT and VARIANTARG", VariantClear in the Win32 SDK
HRESULT Copy( const VARIANT* pSrc );
Return Value
A standard HRESULT value.
Parameters
pSrc [in] A pointer to the VARIANT to be copied
Remarks
Frees the CComVariant object and then assigns it a copy of the specified VARIANT.
CComVariant Overview | Class Members
See Also CComVariant::operator =, "VARIANT and VARIANTARG" and VariantCopy in the Win32 SDK
HRESULT Detach( VARIANT* pSrc );
Return Value
A standard HRESULT value.
Parameters
pSrc [out] Returns the underlying VARIANT value of the object.
Remarks
Detaches the underlying VARIANT from the CComVariant object and sets the objects type to VT_EMPTY.
CComVariant Overview | Class Members
See Also CComVariant::Attach, "VARIANT and VARIANTARG" in the Win32 SDK
HRESULT ReadFromStream( IStream* pStream );
Return Value
A standard HRESULT value.
Parameters
pStream [in] A pointer to the IStream interface on the stream containing the data.
Remarks
Sets the underlying VARIANT to the VARIANT contained in the specified stream. ReadToStream requires a previous call to WriteToStream.
CComVariant Overview | Class Members
See Also IStream in the Win32 SDK
HRESULT WriteToStream( IStream* pStream );
Return Value
A standard HRESULT value.
Parameters
pStream [in] A pointer to the IStream interface on a stream.
Remarks
Saves the underlying VARIANT to a stream.
CComVariant Overview | Class Members
See Also CComVariant::ReadFromStream, IStream in the Win32 SDK
CComVariant& operator =( const CComVariant& varSrc );
CComVariant& operator =( const VARIANT& varSrc );
CComVariant& operator =( LPCOLESTR lpsz );
CComVariant& operator =( LPCSTR lpsz );
CComVariant& operator =( BSTR bstrSrc );
CComVariant& operator =( int nSrc );
CComVariant& operator =( BYTE nSrc );
CComVariant& operator =( short nSrc );
CComVariant& operator =( long nSrc );
CComVariant& operator =( float nSrc );
CComVariant& operator =( double nSrc );
CComVariant& operator =( CY cySrc );
CComVariant& operator =( IDispatch* pSrc );
CComVariant& operator =( IUnknown* pSrc );
Remarks
Assigns a value and corresponding type to the CComVariant object.
CComVariant Overview | Class Members
See Also CComVariant::Copy, "VARIANT and VARIANTARG" in the Win32 SDK
BOOL operator = =( const VARIANT& varSrc );
Remarks
Returns TRUE if the value and type of varSrc are equal to the value and type, respectively, of the CComVariant object. Otherwise, FALSE.
CComVariant Overview | Class Members
See Also CComVariant::operator !=, "VARIANT and VARIANTARG" in the Win32 SDK
BOOL operator !=( const VARIANT& varSrc );
Remarks
Returns TRUE if either the value or type of varSrc is not equal to the value or type, respectively, of the CComVariant object. Otherwise, FALSE.
CComVariant Overview | Class Members
See Also CComVariant::operator = =, "VARIANT and VARIANTARG" in the Win32 SDK