Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The **strncmp** function performs an ordinal comparison of at most the first *co

**wcsncmp** and **_mbsncmp** are wide-character and multibyte-character versions of **strncmp**. The arguments of **wcsncmp** are wide-character strings; those of **_mbsncmp** are multibyte-character strings. **_mbsncmp** recognizes multibyte-character sequences according to a multibyte code page and returns **_NLSCMPERROR** on an error.

Also, **_mbsncmp** and **_mbsncmp_l** validate parameters. If *string1* or *string2* is a null pointer, the invalid parameter handler is invoked, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, **_mbsncmp** and **_mbsncmp_l** return **_NLSCMPERROR** and set **errno** to **EINVAL**. **strncmp** and **wcsncmp** do not validate their parameters. These functions behave identically otherwise.
Also, **_mbsncmp** and **_mbsncmp_l** validate parameters. If *string1* or *string2* is a null pointer and *count* is not equal to 0, the invalid parameter handler is invoked, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, **_mbsncmp** and **_mbsncmp_l** return **_NLSCMPERROR** and set **errno** to **EINVAL**. **strncmp** and **wcsncmp** do not validate their parameters. These functions behave identically otherwise.

The comparison behavior of **_mbsncmp** and **_mbsncmp_l** is affected by the setting of the **LC_CTYPE** category setting of the locale. This controls detection of leading and trailing bytes of multibyte characters. For more information, see [setlocale](setlocale-wsetlocale.md). The **_mbsncmp** function uses the current locale for this locale-dependent behavior. The **_mbsncmp_l** function is identical except that it uses the *locale* parameter instead. For more information, see [Locale](../../c-runtime-library/locale.md). If the locale is a single-byte locale, the behavior of these functions is identical to **strncmp**.

Expand Down
192 changes: 83 additions & 109 deletions docs/cpp/variant-t-operator-equal.md
Original file line number Diff line number Diff line change
@@ -1,149 +1,123 @@
---
description: "Learn more about: _variant_t::operator ="
title: "_variant_t::operator ="
ms.date: "11/04/2016"
description: "Learn more about: _variant_t::operator="
title: "_variant_t::operator="
ms.date: 03/23/2021
f1_keywords: ["_variant_t::operator="]
helpviewer_keywords: ["operator= [C++], variant", "operator = [C++], variant", "= operator [C++], with specific Visual C++ objects"]
ms.assetid: 77622723-6e49-4dec-9e0f-fa74028f1a3c
---
# _variant_t::operator =
# `_variant_t::operator=`

**Microsoft Specific**
Assigns a new value to a `_variant_t` instance.

The `_variant_t` class and its `operator=` member are **Microsoft-specific**.

## Syntax

```cpp
_variant_t& operator=( const VARIANT& varSrc );
_variant_t& operator=( const VARIANT* pVarSrc );
_variant_t& operator=( const _variant_t& var_t_Src );
_variant_t& operator=( short sSrc );
_variant_t& operator=( long lSrc );
_variant_t& operator=( float fltSrc );
_variant_t& operator=( double dblSrc );
_variant_t& operator=( const CY& cySrc );
_variant_t& operator=( const _bstr_t& bstrSrc );
_variant_t& operator=( const wchar_t* wstrSrc );
_variant_t& operator=( const char* strSrc );
_variant_t& operator=( IDispatch* pDispSrc );
_variant_t& operator=( bool bSrc );
_variant_t& operator=( IUnknown* pSrc );
_variant_t& operator=( const DECIMAL& decSrc );
_variant_t& operator=( BYTE byteSrc );
_variant_t& operator=( char cSrc );
_variant_t& operator=( unsigned short usSrc );
_variant_t& operator=( unsigned long ulSrc );
_variant_t& operator=( int iSrc );
_variant_t& operator=( unsigned int uiSrc );
_variant_t& operator=( __int64 i8Src );
_variant_t& operator=( unsigned __int64 ui8Src );
```
_variant_t& operator=(
const VARIANT& varSrc
);

_variant_t& operator=(
const VARIANT* pVarSrc
);

_variant_t& operator=(
const _variant_t& var_t_Src
);

_variant_t& operator=(
short sSrc
);

_variant_t& operator=(
long lSrc
);

_variant_t& operator=(
float fltSrc
);
### Parameters

_variant_t& operator=(
double dblSrc
);
*`varSrc`*\
A reference to a `VARIANT` from which to copy the content and `VT_*` type.

_variant_t& operator=(
const CY& cySrc
);
*`pVarSrc`*\
A pointer to a `VARIANT` from which to copy the content and `VT_*` type.

_variant_t& operator=(
const _bstr_t& bstrSrc
);
*`var_t_Src`*\
A reference to a `_variant_t` from which to copy the content and `VT_*` type.

_variant_t& operator=(
const wchar_t* wstrSrc
);
*`sSrc`*\
A **`short`** integer value to copy. Given type `VT_BOOL` if `*this` is of type `VT_BOOL`. Otherwise, it's given type `VT_I2`.

_variant_t& operator=(
const char* strSrc
);
*`lSrc`*\
A **`long`** integer value to copy. Given type `VT_BOOL` if `*this` is of type `VT_BOOL`. Given type `VT_ERROR` if `*this` is of type `VT_ERROR`. Otherwise, given type `VT_I4`.

_variant_t& operator=(
IDispatch* pDispSrc
);
*`fltSrc`*\
A **`float`** numerical value to copy. Given type `VT_R4`.

_variant_t& operator=(
bool bSrc
);
*`dblSrc`*\
A **`double`** numerical value to copy. Given type `VT_DATE` if `this` is of type `VT_DATE`. Otherwise, given type `VT_R8`.

_variant_t& operator=(
IUnknown* pSrc
);
*`cySrc`*\
A `CY` object to copy. Given type `VT_CY`.

_variant_t& operator=(
const DECIMAL& decSrc
);
*`bstrSrc`*\
A `BSTR` object to copy. Given type `VT_BSTR`.

_variant_t& operator=(
BYTE bSrc
);
*`wstrSrc`*\
A Unicode string to copy, stored as a `BSTR` and given type `VT_BSTR`.

_variant_t& operator=(
char cSrc
);
*`strSrc`*\
A multibyte string to copy, stored as a `BSTR` and given type `VT_BSTR`.

_variant_t& operator=(
unsigned short usSrc
);
*`pDispSrc`*\
An `IDispatch` pointer to copy with a call to `AddRef`. Given type `VT_DISPATCH`.

_variant_t& operator=(
unsigned long ulSrc
);
*`bSrc`*\
A **`bool`** value to copy. Given type `VT_BOOL`.

_variant_t& operator=(
int iSrc
);
*`pSrc`*\
An `IUnknown` pointer to copy with a call to `AddRef`. Given type `VT_UNKNOWN`.

_variant_t& operator=(
unsigned int uiSrc
);
*`decSrc`*\
A `DECIMAL` object to copy. Given type `VT_DECIMAL`.

_variant_t& operator=(
__int64 i8Src
);

_variant_t& operator=(
unsigned __int64 ui8Src
);
```

## Remarks
*`byteSrc`*\
A `BYTE` value to copy. Given type `VT_UI1`.

The operator assigns a new value to the `_variant_t` object:
*`cSrc`*\
A **`char`** value to copy. Given type `VT_I1`.

- **operator=(** *varSrc* **)** Assigns an existing `VARIANT` to a `_variant_t` object.
*`usSrc`*\
An **`unsigned short`** value to copy. Given type `VT_UI2`.

- **operator=(** *pVarSrc* **)** Assigns an existing `VARIANT` to a `_variant_t` object.
*`ulSrc`*\
An **`unsigned long`** value to copy. Given type `VT_UI4`.

- **operator=(** *var_t_Src* **)** Assigns an existing `_variant_t` object to a `_variant_t` object.
*`iSrc`*\
An **`int`** value to copy. Given type `VT_INT`.

- **operator=(** *sSrc* **)** Assigns a **`short`** integer value to a `_variant_t` object.
*`uiSrc`*\
An **`unsigned int`** value to copy. Given type `VT_UINT`.

- **operator=(** `lSrc` **)** Assigns a **`long`** integer value to a `_variant_t` object.
*`i8Src`*\
An **`__int64`** or **`long long`** value to copy. Given type `VT_I8`.

- **operator=(** *fltSrc* **)** Assigns a **`float`** numerical value to a `_variant_t` object.
*`ui8Src`*\
An **`unsigned __int64`** or **`unsigned long long`** value to copy. Given type `VT_UI8`.

- **operator=(** *dblSrc* **)** Assigns a **`double`** numerical value to a `_variant_t` object.

- **operator=(** *cySrc* **)** Assigns a `CY` object to a `_variant_t` object.

- **operator=(** *bstrSrc* **)** Assigns a `BSTR` object to a `_variant_t` object.

- **operator=(** *wstrSrc* **)** Assigns a Unicode string to a `_variant_t` object.

- **operator=(** `strSrc` **)** Assigns a multibyte string to a `_variant_t` object.

- **operator=(** `bSrc` **)** Assigns a **`bool`** value to a `_variant_t` object.

- **operator=(** *pDispSrc* **)** Assigns an `IDispatch*` object to a `_variant_t` object and calls `AddRef`.

- **operator=(** *pIUnknownSrc* **)** Assigns an `IUnknown*` object to a `_variant_t` object and calls `AddRef`.
## Remarks

- **operator=(** *decSrc* **)** Assigns a `DECIMAL` value to a `_variant_t` object.
The `operator=` assignment operator clears any existing value, which deletes object types, or calls `Release` for `IDispatch*` and `IUnknown*` types. Then, it copies a new value into the `_variant_t` object. It changes the `_variant_t` type to match the assigned value, except as noted for **`short`**, **`long`**, and **`double`** arguments. Value types are copied directly. A `VARIANT` or `_variant_t` pointer or reference argument copies the assigned object's contents and type. Other pointer or reference type arguments create a copy of the assigned object. The assignment operator calls `AddRef` for `IDispatch*` and `IUnknown*` arguments.

- **operator=(** `bSrc` **)** Assigns a `BYTE` value to a `_variant_t` object.
`operator=` invokes [`_com_raise_error`](../cpp/com-raise-error.md) if an error occurs.

**END Microsoft Specific**
`operator=` returns a reference to the updated `_variant_t` object.

## See also

[_variant_t Class](../cpp/variant-t-class.md)
[`_variant_t` class](../cpp/variant-t-class.md)