Share via


Função WindowsPromoteStringBuffer (winstring.h)

Cria um HSTRING do HSTRING_BUFFER especificado.

Sintaxe

HRESULT WindowsPromoteStringBuffer(
  HSTRING_BUFFER bufferHandle,
  HSTRING        *string
);

Parâmetros

bufferHandle

Tipo: [in] HSTRING_BUFFER

O buffer a ser usado para o novo HSTRING. Você deve usar a função WindowsPreallocateStringBuffer para criar o HSTRING_BUFFER.

string

Tipo: [out] HSTRING*

O HSTRING recém-criado que contém o conteúdo de bufferHandle.

Retornar valor

Tipo: HRESULT

Essa função pode retornar um desses valores.

Código de retorno Descrição
S_OK
O HSTRING foi criado com êxito.
E_POINTER
string é NULL.
E_INVALIDARG
bufferHandle não foi criado chamando a função WindowsPreallocateStringBuffer ou o chamador substituiu o caractere NULL de terminação em bufferHandle.

Comentários

Use a função WindowsPromoteStringBuffer para criar um HSTRING de um HSTRING_BUFFER. Chamar a função WindowsPromoteStringBuffer converte o buffer mutável em um HSTRING imutável. Use a função WindowsPreallocateStringBuffer para criar o HSTRING_BUFFER.

Se a chamada windowsPromoteStringBuffer falhar, você poderá chamar a função WindowsDeleteStringBuffer para descartar o buffer mutável.

Cada chamada para a função WindowsPromoteStringBuffer deve ser correspondida com uma chamada correspondente para WindowsDeleteString.

Exemplos

O exemplo de código a seguir demonstra como usar a função WindowsPromoteStringBuffer .

#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);
        }
    }
}

Requisitos

Requisito Valor
Cliente mínimo com suporte Windows 8 [aplicativos da área de trabalho | Aplicativos UWP]
Servidor mínimo com suporte Windows Server 2012 [aplicativos da área de trabalho | Aplicativos UWP]
Plataforma de Destino Windows
Cabeçalho winstring.h
Biblioteca RuntimeObject.lib
DLL ComBase.dll

Confira também

HSTRING

HSTRING_BUFFER

WindowsDeleteString

WindowsDeleteStringBuffer

WindowsPreallocateStringBuffer