Share via


Funzione WindowsPromoteStringBuffer (winstring.h)

Crea un oggetto HSTRING dal HSTRING_BUFFER specificato.

Sintassi

HRESULT WindowsPromoteStringBuffer(
  HSTRING_BUFFER bufferHandle,
  HSTRING        *string
);

Parametri

bufferHandle

Tipo: [in] HSTRING_BUFFER

Buffer da usare per il nuovo HSTRING. Per creare il HSTRING_BUFFER, è necessario usare la funzione WindowsPreallocateStringBuffer.

string

Tipo: [out] HSTRING*

Oggetto HSTRING appena creato che contiene il contenuto di bufferHandle.

Valore restituito

Tipo: HRESULT

Questa funzione può restituire uno di questi valori.

Codice restituito Descrizione
S_OK
HSTRING è stato creato correttamente.
E_POINTER
la stringa è NULL.
E_INVALIDARG
bufferHandle non è stato creato chiamando la funzione WindowsPreallocateStringBuffer oppure il chiamante ha sovrascritto il carattere NULL di terminazione in bufferHandle.

Commenti

Usare la funzione WindowsPromoteStringBuffer per creare un nuovo HSTRING da un HSTRING_BUFFER. La chiamata alla funzione WindowsPromoteStringBuffer converte il buffer modificabile in un HSTRING non modificabile. Usare la funzione WindowsPreallocateStringBuffer per creare il HSTRING_BUFFER.

Se la chiamata WindowsPromoteStringBuffer ha esito negativo, è possibile chiamare la funzione WindowsDeleteStringBuffer per eliminare il buffer modificabile.

Ogni chiamata alla funzione WindowsPromoteStringBuffer deve essere associata a una chiamata corrispondente a WindowsDeleteString.

Esempio

Nell'esempio di codice seguente viene illustrato come usare la funzione 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);
        }
    }
}

Requisiti

Requisito Valore
Client minimo supportato Windows 8 [app desktop | App UWP]
Server minimo supportato Windows Server 2012 [app desktop | App UWP]
Piattaforma di destinazione Windows
Intestazione winstring.h
Libreria RuntimeObject.lib
DLL ComBase.dll

Vedi anche

HSTRING

HSTRING_BUFFER

WindowsDeleteString

WindowsDeleteStringBuffer

WindowsPreallocateStringBuffer