Bug 19151 – std.utf.toUTF16z() can not be used for LPWSTR
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-08-09T08:17:53Z
Last change time
2019-02-22T23:27:22Z
Keywords
pull
Assigned to
No Owner
Creator
Stefan Liebig
Comments
Comment #0 by StefanLiebig — 2018-08-09T08:17:53Z
The documentation of toUTF16z() (https://dlang.org/phobos/std_utf.html#toUTF16z) says that it can be used for LPWSTR or LPCWSTR.
When compiling:
auto success = CreateProcessW( null,
commandLine.toUTF16z(), // <- error
null,
null,
TRUE,
CREATE_UNICODE_ENVIRONMENT,
null,
null,
&startupInfo,
&processInfo );
I got the compile error:
source\process.d(32,32): Error: function `core.sys.windows.winbase.CreateProcessW(const(wchar)*, wchar*, SECURITY_ATTRIBUTES*, SECURITY_ATTRIBUTES*, int, uint, void*, const(wchar)*, STARTUPINFOW*, PROCESS_INFORMATION*)` is not callable using argument types `(typeof(null), const(wchar)*, typeof(null), typeof(null), int, uint, typeof(null), typeof(null), STARTUPINFOW*, PROCESS_INFORMATION*)`
source\process.d(32,32): cannot pass argument `toUTF16z(cast(const(char)[])commandLine)` of type `const(wchar)*` to parameter `wchar*`
Casting the second parameter to LPWSTR works.
Using DMD 2.081.1
Maybe it relates to https://issues.dlang.org/show_bug.cgi?id=2275
Comment #1 by Bastiaan — 2019-01-21T19:06:26Z
I can confirm this.
Not sure whether this workaround is right, but it works:
commandLine.toUTFz!(wchar*)
@veelo created dlang/phobos pull request #6875 "toUTF16z cannot be used for LPWSTR." fixing this issue:
- toUTF16z cannot be used for LPWSTR.
Remove false statement from the documentation. Fixes issue 19151.
https://github.com/dlang/phobos/pull/6875
Comment #4 by dlang-bot — 2019-02-22T23:27:22Z
dlang/phobos pull request #6875 "toUTF16z cannot be used for LPWSTR." was merged into master:
- 9e5752313498999fa97a97d7d3d6adc8b7f74b33 by Bastiaan Veelo:
toUTF16z cannot be used for LPWSTR.
Remove false statement from the documentation. Fixes issue 19151.
https://github.com/dlang/phobos/pull/6875