WindowsPromoteStringBuffer function (winstring.h)

Creates an HSTRING from the specified HSTRING_BUFFER.

Syntax

HRESULT WindowsPromoteStringBuffer(
  HSTRING_BUFFER bufferHandle,
  HSTRING        *string
);

Parameters

bufferHandle

Type: [in] HSTRING_BUFFER

The buffer to use for the new HSTRING. You must use the WindowsPreallocateStringBuffer function to create the HSTRING_BUFFER.

string

Type: [out] HSTRING*

The newly created HSTRING that contains the contents of bufferHandle.

Return value

Type: HRESULT

This function can return one of these values.

Return code Description
S_OK
The HSTRING was created successfully.
E_POINTER
string is NULL.
E_INVALIDARG
bufferHandle was not created by calling the WindowsPreallocateStringBuffer function, or the caller has overwritten the terminating NULL character in bufferHandle.

Remarks

Use the WindowsPromoteStringBuffer function to create a new HSTRING from an HSTRING_BUFFER. Calling the WindowsPromoteStringBuffer function converts the mutable buffer to an immutable HSTRING. Use the WindowsPreallocateStringBuffer function to create the HSTRING_BUFFER.

If the WindowsPromoteStringBuffer call fails, you can call the WindowsDeleteStringBuffer function to discard the mutable buffer.

Each call to the WindowsPromoteStringBuffer function must be matched with a corresponding call to WindowsDeleteString.

Examples

The following code example demonstrates how to use the WindowsPromoteStringBuffer function.

#include <winstring.h>

int main()
{
    HSTRING hString = NULL;
    HSTRING_BUFFER hStringBuffer = NULL;
    PWSTR strBuffer = NULL;

    HRESULT hr = WindowsPreallocateStringBuffer(10, &strBuffer, &hStringBuffer);

    if (SUCCEEDED(hr))
    {
        // Fill in the buffer

        hr = WindowsPromoteStringBuffer(hStringBuffer, &hString);

        if (SUCCEEDED(hr))
        {
            WindowsDeleteString(hString);
        }
        else
        {
            WindowsDeleteStringBuffer(hStringBuffer);
        }
    }
}

Requirements

Requirement Value
Minimum supported client Windows 8 [desktop apps | UWP apps]
Minimum supported server Windows Server 2012 [desktop apps | UWP apps]
Target Platform Windows
Header winstring.h
Library RuntimeObject.lib
DLL ComBase.dll

See also

HSTRING

HSTRING_BUFFER

WindowsDeleteString

WindowsDeleteStringBuffer

WindowsPreallocateStringBuffer