On Saturday, 5 December 2020 at 19:51:14 UTC, Jack wrote:
So in D I have a struct like this:

struct ProcessResult
{
        string[] output;
        bool ok;
}

in order to use output from C WINAPI with unicode, I need to convert each string to wchar* so that i can acess it from C with wchar_t*. Is that right or am I missing anything?


struct ProcessResult
{
        string[] output;
        bool ok;

        C_ProcessResult toCResult()
        {
                auto r = C_ProcessResult();
                r.ok = this.ok; // just copy, no conversion needed
                foreach(s; this.output)
                        r.output ~= cast(wchar*)s.ptr;
                return r;
        }
}

version(Windows) extern(C) export
struct C_ProcessResult
{
        wchar*[] output;
        bool ok;
}

I would just use std.encoding

https://dlang.org/phobos/std_encoding.html

and use transcode

https://dlang.org/phobos/std_encoding.html#transcode

Reply via email to