[Issue 5926] D2 shows empty command line on Windows 98 SE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 4 18:00:07 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5926



--- Comment #9 from Walter Bright <bugzilla at digitalmars.com> 2011-05-04 17:56:09 PDT ---
(In reply to comment #8)
> It's there because the argv data on Windows is in code pages instead of
> Unicode, and it seemed easiest to let the OS deal with the conversion.

Here's the code from druntime/src/rt/dmain2.d in question:

    wchar_t*  wcbuf = GetCommandLineW();
    size_t    wclen = wcslen(wcbuf);
    int       wargc = 0;
    wchar_t** wargs = CommandLineToArgvW(wcbuf, &wargc);
    assert(wargc == argc);

    char*     cargp = null;
    size_t    cargl = WideCharToMultiByte(65001, 0, wcbuf, wclen, null, 0,
null, 0);

    cargp = cast(char*) alloca(cargl);
    args  = ((cast(char[]*) alloca(wargc * (char[]).sizeof)))[0 .. wargc];

    for (size_t i = 0, p = 0; i < wargc; i++)
    {
        int wlen = wcslen(wargs[i]);
        int clen = WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, null, 0,
null, 0)
        args[i]  = cargp[p .. p+clen];
        p += clen; assert(p <= cargl);
        WideCharToMultiByte(65001, 0, &wargs[i][0], wlen, &args[i][0], clen,
null, 0);
    }
    LocalFree(wargs);
    wargs = null;
    wargc = 0;

Since the only thing necessary is to convert argv[] from code pages to utf8,
there is no need for the calls to GetCommandLineW and CommandLineToArgvW, and
so no compatibility problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list