Skip to content
Raymond Chen edited this page Jan 23, 2020 · 1 revision

The wil::details::string_maker is an internal template type which is used to create Unicode strings.

template<typename string_type>
struct string_maker<string_type>;

Supported types

The string_maker supports any Unicode string type that has a string_allocator:

  • unique_process_heap_string
  • unique_hlocal_string
  • unique_hglobal_string
  • unique_cotaskmem_string
  • unique_midl_string

It also supports the following string types:

  • unique_hstring
  • std::wstring (requires stl.h)

Methods

HRESULT make(_In_reads_opt_(length) PCWSTR source, size_t length) noexcept;

Allocates memory for a string that can hold length characters (plus a terminating null).

If source is non-null, then the memory is initialized from source.

If source is nullptr, then the memory is zero-initialized.

It is legal to call make more than once. Doing so frees the previous buffer.

wchar_t* buffer();

Returns a pointer to the memory allocated by make. The expectation is that the caller will fill this buffer with data, up to length characters.

string_type release();

Converts the memory allocated by make to a string and returns it. The string_maker is returned to its empty state.

static PCWSTR get(string_type const& value);

Static function to extract a pointer to a null-terminated string buffer from an existing string object.