EN
此内容没有您的语言版本,但有英语版本。

VariantToBuffer function

Extracts the contents of a buffer stored in a VARIANT structure of type VT_ARRRAY | VT_UI1.

Syntax


HRESULT VariantToBuffer(
  _In_   REFVARIANT varIn,
  _Out_  VOID *pv,
  _In_   UINT cb
);

Parameters

varIn [in]

Type: REFVARIANT

Reference to a source VARIANT structure.

pv [out]

Type: VOID*

Pointer to a buffer of length cb bytes. When this function returns, contains the first cb bytes of the extracted buffer value.

cb [in]

Type: UINT

The size of the pv buffer, in bytes. The buffer should be the same size as the data to be extracted, or smaller.

Return value

Type: HRESULT

Returns one of the following values:

Return codeDescription
S_OK

Data successfully extracted.

E_INVALIDARG

The VARIANT was not of type VT_ARRRAY | VT_UI1.

E_FAIL

The VARIANT buffer value had fewer than cb bytes.

 

Remarks

This function is used when the calling application expects a VARIANT to hold a buffer value. The calling application should check that the value has the expected length before it calls this function.

If the source VARIANT has type VT_ARRAY | VT_UI1, this function extracts the first cb bytes from the structure and places them in the buffer pointed to by pv.

If the stored value has fewer than cb bytes, then VariantToBuffer fails and the buffer is not modified.

If the value has more than cb bytes, then VariantToBuffer succeeds and truncates the value.

Examples

The following example, to be included as part of a larger program, demonstrates how to use VariantToBuffer to access a structure that has been stored in a VARIANT.


// VARIANT var;
// Assume variable var is initialized and valid. 
// The application expects var to hold a WIN32_FIND_DATAW structure 
// with sizeof(WIN32_FIND_DATAW) bytes.

HRESULT hr = E_UNEXPECTED;

// Verify that the value length is acceptable before you call VariantToBuffer.
if (VariantGetElementCount(var) == sizeof(WIN32_FIND_DATAW))
{
    WIN32_FIND_DATAW wfd;

    hr = VariantToBuffer(var, &wfd, sizeof(wfd));

    if (SUCCEEDED(hr))
    {
        // wfd is now initialized.
    }
}

Requirements

Minimum supported client

Windows XP with SP2, Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2003 with SP1 [desktop apps only]

Redistributable

Windows Desktop Search (WDS) 3.0

Header

Propvarutil.h

Library

Propsys.lib

DLL

Propsys.dll (version 6.0 or later)

See also

InitVariantFromBuffer
PropVariantToBuffer

 

 

社区附加资源

添加
显示:
© 2014 Microsoft