On Monday, 20 June 2016 at 05:11:12 UTC, Hugo wrote:
On Sunday, 19 June 2016 at 23:01:26 UTC, Adam D. Ruppe wrote:
One potentially simple option would be to preprocess it by doing a .replace(`\"`, `\\"`) then pass to CommandLineToArgvW to hack in the extra slash...

The problem with that approach is that replace does not work with wchar*. I might convert it to string, replace and then typecast as wchar* again because that's what CommandLineToArgvW expects, but when I try to convert the output to strings again, all I get are memory addresses instead. It seems something is lost during conversion or typecast.

FWIW, it seems there's some problem with print wchar* or strings converted from wchar*. With these lines:

auto cmdLine = GetCommandLineW();
auto str = to!string(cmdLine);
writeln(str);

Whether I use to!string or to!wstring, whether I print str or cmdLine, all I get are addresses. However, replacing GetCommandLineW with GetCommandLineA yields the correct result (my test is compiled as slash.exe):

Command: slash "foo\"
Output: slash  "foo\"

It shouldn't hurt to use the A variant, as Windows will do the necessary conversions under the hood. However, I'd love to know what the problem is with converting wchar* to a string type. This also prints an address:

auto foo = "I'm a wstring"w.ptr;
writeln(to!wstring(foo));



Reply via email to