core.exception.UnicodeException at src\rt\util\utf.d(400): illegal UTF-16 value

notna via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 16 13:19:23 PDT 2014


Thanks AsmMan,

Found 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724432%28v=vs.85%29.aspx 
and with your help, now understand :)

The syntax below prints a blank after my username, so the slice 
seems a bit too long :O So my "final solution" looks like:

  module main;

  import std.stdio;
  import std.c.windows.windows;

  pragma(lib, "user32.lib");
  pragma(lib, "Advapi32");

  void main(string[] args)
  {
     WCHAR lpwszUsername[254];
     DWORD dUsername2 = 254;
     GetUserNameW(lpwszUsername.ptr, &dUsername2);
     writefln("Welcome userW %s", lpwszUsername[0..(dUsername2 - 
1));
     writeln();
   }

THANKS again!!!

On Tuesday, 16 September 2014 at 00:03:55 UTC, AsmMan wrote:
>
> 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];



More information about the Digitalmars-d-learn mailing list