Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Printing international characters on Windows

Part of TutorialAdvanced

Description

This Windows specific code, allows you to print international characters (Greek for instance) on the non UTF-8 Windows console.

Example

import std.c.stdio;
import std.c.windows.windows;

extern (Windows) {
    export BOOL CharToOemW(
            LPCWSTR lpszSrc, // string to translate
            LPSTR lpszDst // translated string
    );
}

void main()
{
    wchar[] s = "Χαίρετε!"; //Greek salutation
    echo(s); // call our function
}

void echo(wchar[] s)
{
    char[] t = new char[s.length];
    CharToOemW(s, t); // calling Windows API function
    puts(t); // printing translated string
}

Compile Instructions

Link to kernel32.lib when compiling.

Source

Link http://www.dsource.org/tutorials/index.php?show_example=147
Posted by Anonymous