{"id":2004,"date":"2020-01-19T22:33:00","date_gmt":"2020-01-19T20:33:00","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=2004"},"modified":"2020-01-19T17:20:42","modified_gmt":"2020-01-19T15:20:42","slug":"so-yes-c-winrt-is-how-c-development-is-to-be-done-on-windows","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/2004","title":{"rendered":"So yes, C++\/WinRT is how C++ development is to be done on Windows"},"content":{"rendered":"\n<p>&#8220;Modern&#8221; <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/uwp\/cpp-and-winrt-apis\/intro-to-using-cpp-with-winrt\">C++\/WinRT<\/a> is the way to write rather powerful things in a compact and readable way, mixing everything you can think of together: classic C++ and libraries, UWP APIs including HTTP client, JSON, COM, ability to put code into console\/desktop applications, async API model and C++20 coroutines.<\/p>\n\n\n\n<p>Fragment of Telegram bot code snippet that echoes a message back, written with just bare Windows 10 SDK API set without external libraries, for example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for(auto&amp;&amp; UpdateValue: UpdateArray) \/\/ https:\/\/core.telegram.org\/bots\/api#update\n{\n\tJsonObject Update = UpdateValue.GetObject();\n\tconst UINT64 UpdateIdentifier = static_cast&lt;UINT64>(Update.GetNamedNumber(L\"update_id\"));\n\tm_Context.m_NextUpdateIdentifier = UpdateIdentifier + 1;\n\tif(Update.HasKey(L\"message\"))\n\t{\n\t\tJsonObject Message = Update.GetNamedObject(L\"message\");\n\t\tm_Journal.Write(\n\t\t{ \n\t\t\tL\"Message\",\n\t\t\tstatic_cast&lt;std::wstring>(Message.Stringify()),\n\t\t});\n\t\tconst UINT64 MessageIdentifier = static_cast&lt;UINT64>(Message.GetNamedNumber(L\"message_id\"));\n\t\tJsonObject FromUser = Message.GetNamedObject(L\"from\");\n\t\tconst UINT64 FromUserIdentifier = static_cast&lt;UINT64>(FromUser.GetNamedNumber(L\"id\"));\n\t\tstd::wstring FromUserUsername = static_cast&lt;std::wstring>(FromUser.GetNamedString(L\"username\"));\n\t\t#pragma region ACK\n\t\tJsonObject Chat = Message.GetNamedObject(L\"chat\");\n\t\tconst UINT64 ChatIdentifier = static_cast&lt;UINT64>(Chat.GetNamedNumber(L\"id\"));\n\t\t{\n\t\t\tstd::wstring Text = Format(L\"Hey, *@%ls*, I confirm message _%llu_\\\\. Send me a file now\\\\!\", FromUserUsername.c_str(), MessageIdentifier);\n\t\t\tUri RequestUri(static_cast&lt;winrt::hstring>(Format(L\"https:\/\/api.telegram.org\/bot%ls\/sendMessage\", m_Configuration.m_Token.c_str())));\n\t\t\tJsonObject Request;\n\t\t\tRequest.Insert(L\"chat_id\", JsonValue::CreateNumberValue(static_cast&lt;DOUBLE>(ChatIdentifier)));\n\t\t\tRequest.Insert(L\"text\", JsonValue::CreateStringValue(static_cast&lt;winrt::hstring>(Text)));\n\t\t\tRequest.Insert(L\"parse_mode\", JsonValue::CreateStringValue(L\"MarkdownV2\"));\n\t\t\tm_Journal.Write(\n\t\t\t{ \n\t\t\t\tL\"sendMessage\",\n\t\t\t\tL\"Request\",\n\t\t\t\tstatic_cast&lt;std::wstring>(Request.Stringify()),\n\t\t\t});\n\t\t\tHttpStringContent Content(Request.Stringify(), UnicodeEncoding::Utf8);\n\t\t\tContent.Headers().ContentType(Headers::HttpMediaTypeHeaderValue(L\"application\/json\"));\n\t\t\tHttpResponseMessage ResponseMessage = Client.PostAsync(RequestUri, Content).get();\n\t\t\tJsonObject Response = JsonObject::Parse(ResponseMessage.Content().ReadAsStringAsync().get());\n\t\t\tm_Journal.Write(\n\t\t\t{ \n\t\t\t\tL\"sendMessage\",\n\t\t\t\tL\"Response\",\n\t\t\t\tstatic_cast&lt;std::wstring>(Response.Stringify()),\n\t\t\t});\n\t\t\t__D(Response.GetNamedBoolean(L\"ok\"), E_UNNAMED);\n\t\t}\n\t\t#pragma endregion\n\t}<\/code><\/pre>\n\n\n\n<p>Please count me as a fan of this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;Modern&#8221; C++\/WinRT is the way to write rather powerful things in a compact and readable way, mixing everything you can think of together: classic C++ and libraries, UWP APIs including HTTP client, JSON, COM, ability to put code into console\/desktop applications, async API model and C++20 coroutines. Fragment of Telegram bot code snippet that echoes&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/2004\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[588,592,581],"class_list":["post-2004","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c-winrt","tag-telegram","tag-winapi-2"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=2004"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2004\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=2004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=2004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=2004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}