#sprintf u16 for windows StringCchPrintfW

1 messages · Page 1 of 1 (latest)

wheat rover
#

Seems to me that both in std.os.windows and zigwin32 there is no StringCchPrintfW. Without converting strings forth and back, what would be the correct way to sprintf an UTF-16 string for display in a windows MessageBoxW ?

worldly tulip
#

What's wrong with converting?

wheat rover
#

The runtime overhead, and it's far more code

#

FormatMessageW gives me an utf16 string

#

So when working with zig strings I would have to first build everything except the message in zig with regular utf8

#

then allocate a buffer manually for the utf 16 string (which I have to do either way, so that's okay)

#

then convert the utf8 string to utf16 at runtime, as the errno will be runtime info, so no comptime there, and copy it to that buffer,
and then copy the already existing utf-16 string from FormatMessageW to the end of the allocated buffer

#

TBH that's quite a bit more than what one would do in C, directly using the UTF-16 API. While I'm no fan of windows using wchars everywhere instead of utf-8, it's the way it is, and I would like not to have to go through hoops and workarounds everytime I try something with zig :/