core.exception.UnicodeException at src\rt\util\utf.d(400): illegal UTF-16 value
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 15 16:57:59 PDT 2014
On 09/15/2014 04:36 PM, notna wrote:
> WCHAR lpwszUsername[254];
> debug writefln("lpwszUsername.sizeof is %s, WCHAR.sizeof is
> %s", lpwszUsername.sizeof, WCHAR.sizeof);
> // DWORD dUsername2 = lpwszUsername.sizeof / WCHAR.sizeof;
> DWORD dUsername2 = 254;
> GetUserNameW(lpwszUsername.ptr, &dUsername2);
You must make use of the returned value to slice your wstring. Something
like this (not compiled):
auto actualLength = GetUserNameW(lpwszUsername.ptr, &dUsername2);
auto userName = lpwszUsername[0..actualLength];
Otherwise, D knows that lpwszUsername is a 254-char string and will try
to print all of it.
Ali
More information about the Digitalmars-d-learn
mailing list