InitVariantFromString function (propvarutil.h)

Initializes a VARIANT structure with a string.

Syntax

HRESULT InitVariantFromString(
  [in]  PCWSTR  psz,
  [out] VARIANT *pvar
);

Parameters

[in] psz

Type: PCWSTR

Pointer to a buffer that contains the source Unicode string. If this value is NULL, the function initializes the VARIANT with a NULL BSTR.

[out] pvar

Type: VARIANT*

When this function returns, contains the initialized VARIANT structure.

Return value

Type: HRESULT

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

Creates a VT_BSTR variant.

This is an inline function, with its source code provided in the header. It is not included in any .dll or .lib file.

Examples

The following example, to be included as part of a larger program, demonstrates how to use InitVariantFromString.

VARIANT var;

HRESULT hr = InitVariantFromString(L"This is a test", &var);

if (SUCCEEDED(hr))
{
    // var now is valid and has type VT_BSTR.
    VariantClear(&var);
}

Requirements

Requirement Value
Minimum supported client Windows XP with SP2, Windows Vista [desktop apps only]
Minimum supported server Windows Server 2003 with SP1 [desktop apps only]
Target Platform Windows
Header propvarutil.h
DLL Propsys.dll (version 6.0 or later)
Redistributable Windows Desktop Search (WDS) 3.0

See also

InitPropVariantFromString

InitVariantFromStringArray

VariantToString

VariantToStringWithDefault