IDWriteLocalizedStrings::GetStringLength method (dwrite.h)

Gets the length in characters (not including the null terminator) of the string with the specified index.

Syntax

HRESULT GetStringLength(
        UINT32 index,
  [out] UINT32 *length
);

Parameters

index

Type: UINT32

A zero-based index of the language/string pair.

[out] length

Type: UINT32*

The length in characters of the string, not including the null terminator, from the language/string pair.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

Use GetStringLength to get the string length before calling the IDWriteLocalizedStrings::GetString method, as shown in the following code.

UINT32 length = 0;

// Get the string length.
if (SUCCEEDED(hr))
{
    hr = pFamilyNames->GetStringLength(index, &length);
}

// Allocate a string big enough to hold the name.
wchar_t* name = new (std::nothrow) wchar_t[length+1];
if (name == NULL)
{
    hr = E_OUTOFMEMORY;
}

// Get the family name.
if (SUCCEEDED(hr))
{
    hr = pFamilyNames->GetString(index, name, length+1);
}

Requirements

Requirement Value
Minimum supported client Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header dwrite.h
Library Dwrite.lib
DLL Dwrite.dll

See also

IDWriteLocalizedStrings