From
PowerWriteFriendlyName[
^]:
Quote:
BufferSize [in]
The size of the friendly name specified by the Buffer parameter, including the terminating NULL character.
So you must specify two more bytes than the string length. Because the
Buffer
parameter is a Unicode string, you should also use
CStringW
:
CStringW szPlanName = L"abcdefghijabcdefghij";
PowerWriteFriendlyName(
NULL,
[PowerSchemeGuid],
NULL,
NULL,
(UCHAR *)szPlanName.GetBuffer(),
(1 + szPlanName.GetLength()) * sizeof(wchar_t)
);