Re: converting D's string to use with C API with unicode

2020-12-06 Thread Jack via Digitalmars-d-learn
On Sunday, 6 December 2020 at 05:04:35 UTC, tsbockman wrote: On Sunday, 6 December 2020 at 02:07:10 UTC, Jack wrote: On Saturday, 5 December 2020 at 23:31:31 UTC, tsbockman wrote: On Saturday, 5 December 2020 at 21:55:13 UTC, Jack wrote: [...] `ws.length` is the length in `wchar`s, but `

Re: converting D's string to use with C API with unicode

2020-12-06 Thread Jack via Digitalmars-d-learn
On Sunday, 6 December 2020 at 04:41:56 UTC, Виталий Фадеев wrote: 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 conv

Re: converting D's string to use with C API with unicode

2020-12-05 Thread tsbockman via Digitalmars-d-learn
On Sunday, 6 December 2020 at 02:07:10 UTC, Jack wrote: On Saturday, 5 December 2020 at 23:31:31 UTC, tsbockman wrote: On Saturday, 5 December 2020 at 21:55:13 UTC, Jack wrote: wstring ws; transcode(output[i], ws); auto s = malloc(ws.length + 1); if(!s) { onOutOfMemoryEr

Re: converting D's string to use with C API with unicode

2020-12-05 Thread Виталий Фадеев via Digitalmars-d-learn
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

Re: converting D's string to use with C API with unicode

2020-12-05 Thread Jack via Digitalmars-d-learn
On Saturday, 5 December 2020 at 23:31:31 UTC, tsbockman wrote: On Saturday, 5 December 2020 at 21:55:13 UTC, Jack wrote: my code now look like this, still there's a memory corrupt. Could anyone help point out where is it? ... foreach(i; 0..output.length) { wstring ws; transcode(outpu

Re: converting D's string to use with C API with unicode

2020-12-05 Thread tsbockman via Digitalmars-d-learn
On Saturday, 5 December 2020 at 21:55:13 UTC, Jack wrote: my code now look like this, still there's a memory corrupt. Could anyone help point out where is it? ... foreach(i; 0..output.length) { wstring ws; transcode(output[i], ws); auto s = malloc(ws.length + 1); if(!s) {

Re: converting D's string to use with C API with unicode

2020-12-05 Thread Jack via Digitalmars-d-learn
I totally forget to malloc() the strings and array. I don't do C has been a while and totally forget this, thank you so much guys for your answer. my code now look like this, still there's a memory corrupt. Could anyone help point out where is it? struct ProcessResult { string[] out

Re: converting D's string to use with C API with unicode

2020-12-05 Thread tsbockman via Digitalmars-d-learn
On Saturday, 5 December 2020 at 19:51:14 UTC, Jack wrote: version(Windows) extern(C) export struct C_ProcessResult { wchar*[] output; In D, `T[]` (where T is some element type, `wchar*` in this case) is a slice structure that bundles a length and a pointer together. It is NOT the same

Re: converting D's string to use with C API with unicode

2020-12-05 Thread IGotD- via Digitalmars-d-learn
On Saturday, 5 December 2020 at 20:12:52 UTC, IGotD- wrote: 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 ea

Re: converting D's string to use with C API with unicode

2020-12-05 Thread IGotD- via Digitalmars-d-learn
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

converting D's string to use with C API with unicode

2020-12-05 Thread Jack via Digitalmars-d-learn
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 Pro