News

Uno Platform Ports Open Source Windows Calculator (C++) to Web/iOS/Android (C#)

While porting a calculator to a different platform might seem simple -- how hard can it be to convert code for addition/subtraction/multiplication/division? -- the reality is far different.

Developers at UNO Platform detailed just how complicated a calculator can be, having just open sourced the Uno Calculator, a port of the previously open sourced Windows Calculator, which now runs on the Web via WebAssembly and natively on iOS and Android.

Uno Platform describes itself as "a framework trying to improve the development cycle of cross-platform apps using Windows, iOS, Android and WebAssembly using Mono and Xamarin."

Those skills were put to the test as the team worked to port Windows Calculator -- featuring a ton of C++ code and backed by a calculation engine dating back to 1995, with C code origins -- to C# code and the Uno Platform. So it now runs on the Web via WebAssembly -- the preview technology backing Microsoft's red-hot Blazor project -- and natively on iOS and Android mobile platforms.

Uno Calculator
[Click on image for larger view.] Uno Calculator (source: Uno Platform).

Enabling the same C# and XAML code to run on Web, mobile and desktop is "what we do," the team said in a June 25 blog post titled "A piece of Windows 10 is now running on WebAssembly, natively on iOS and Android."

"The Windows Calculator is an interesting and not-so-simple piece of software," said the post authored by Jérôme Laban, CTO of Uno Platform. "The simple initial UI you see upon launch can be deceiving. Of course, that is a good UX choice Microsoft made as most uses of the calculator are rather simple ones. However, the calculator is complex both in the way it was coded over the years, as well as the advanced functions it has."

Besides all that C++ code and its ancient origins, the calculator also sports advanced functionality such as support for scientific and programmer modes and much more complicated capabilities.

"The Uno Platform being developed in C#, to be able to support the Calculator on iOS, Android and WebAssembly, some parts of the code needed to be translated to C#," Laban said. "Others needed to be adjusted to be compliant with clang's C++ 11 support."

That resulted in numerous complicated challenges that needed to be overcome, detailed in the blog post and summarized thusly:

  • Porting the Engine to the Uno Platform:
    • Adjusting the C++ of the Calculation Engine
    • Native Code Interop Specifics
    • Converting the C++/CX code to C#
    • Converting the XAML
    • Localization Resources
  • Connecting the C++ and C# Together:
    • Mono for WebAssembly Dynamic and Static Linking Support
    • The C adaptation layer
    • The case of C++ to C# callbacks
    • String Marshalling
    • Adding features to Uno Platform

"The porting of the Calculator is a very interesting project to work on, and also makes for a very good calculator to use on all platforms," Laban concluded. "You can try building it yourself by heading over to the GitHub repo."

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

Subscribe on YouTube