On Monday, 15 September 2014 at 23:57:59 UTC, Ali Çehreli wrote:
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

GetUserNameW() return a zero on error and non-zero on success. The actual number of bytes copied into lpwszUsernam is in dUsername2.

auto userName = lpwszUsername[0..dUsername2];

Reply via email to