I try import windows API CharToOem function
Quentin J.
quentin.joseph at outlook.com
Mon Aug 26 12:41:33 PDT 2013
On Monday, 26 August 2013 at 18:02:51 UTC, Adam D. Ruppe wrote:
> To to bring it together:
>
> import std.c.windows.windows;
>
> // use the unicode version of the Windows function
> extern (Windows) bool CharToOemW(const wchar*, char*);
> alias CharToOemW CharToOem;
>
>
> public void PutStringIntoConsole(string text)
> {
> // convert source into a Windows tchar* string
> import std.utf;
> auto source = toUTF16z(text);
>
> // prepare our buffer with enough space to receive the
> data
> char[] dest = new char[](text.length * 2);
>
> // call the function...
> CharToOem(source, dest.ptr);
>
> // we also want to get the length out instead of
> relying on zero termination for a real D string:
> import core.stdc.string;
> dest = dest[0 .. strlen(dest.ptr)];
>
> writeln(dest);
> }
>
It works,
>> char[] dest;
>>
>> CharToOem(source.ptr, dest.ptr);
>And this will give you an AccessViolation if you run it because
>dest is null.
For the array, it is my fault an error of inattention ^^
Thank for your explanation and your help.
Quentin.
More information about the Digitalmars-d
mailing list