├── screen.png ├── CMakeLists.txt ├── manifest.xml ├── main.cpp └── README.md /screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cor3ntin/utf8-windows-demo/HEAD/screen.png -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(test_utf8 main.cpp) 2 | target_compile_options(test_utf8 PUBLIC /utf-8) 3 | 4 | if(MSVC) 5 | ADD_CUSTOM_COMMAND( 6 | TARGET test_utf8 7 | POST_BUILD 8 | DEPENDS 9 | COMMAND mt.exe -manifest "${CMAKE_SOURCE_DIR}/manifest.xml" -inputresource:"$"\;\#1 -updateresource:"$"\;\#1 10 | ) 11 | ENDIF(MSVC) 12 | -------------------------------------------------------------------------------- /manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | UTF-8 7 | 8 | 9 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | SetConsoleCP(CP_UTF8); 7 | SetConsoleOutputCP(CP_UTF8); 8 | 9 | auto h = CreateFileA("😊.txt", // name of the write 10 | GENERIC_WRITE, // open for writing 11 | 0, // do not share 12 | NULL, // default security 13 | CREATE_NEW, // create new file only 14 | FILE_ATTRIBUTE_NORMAL, // normal file 15 | NULL); // no attr. template 16 | 17 | CloseHandle(h); 18 | 19 | std::cout << "สวัสดีชาวโลก\n" 20 | << "こんにちは世界\n" 21 | << "مرحبا بالعالم\n" 22 | << "你好,世界 😊\n"; 23 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UTF-8 Programs on windows 2 | 3 | This project showcases how to support UTF-8 in windows applications. 4 | By using UTF-8 everywhere, you guarantee your application will be portable accross platforms. 5 | 6 | 7 | ![screenshot](screen.png) 8 | 9 | ⚠️ UTF-8 support on windows is still fairly bleeding edge and requires a very recent of windows that is not widely deployed yet. 10 | 11 | ## Requirements 12 | 13 | * Windows 1903 or greater 14 | * [Windows Terminal](https://github.com/microsoft/terminal) 15 | * Windows SDK 10.0.18362.0 or greater 16 | * [Suitable Fonts](https://www.google.com/get/noto/) 17 | 18 | ## Steps 19 | 20 | * In the main of your application configure the console to expect UTF-8 21 | 22 | ``` 23 | SetConsoleCP(CP_UTF8); 24 | SetConsoleOutputCP(CP_UTF8); 25 | ``` 26 | 27 | * Link the provided manifest to enable UTF-8 as the active code page 28 | * Compile your source files with the `/utf-8` option. Make sure your source files are utf8-encoded. 29 | * Use the ANSI system APIs (functions suffixed with `A`, like `CreateFileA`) with utf-8 encoded string parameters (confusing, isn't it) 30 | 31 | --------------------------------------------------------------------------------