Reputation: 3247
I am interested in writing a mixed app, with a mix of managed (dotnet/C#) and unmanaged (C++) code. I’m relatively new to dealing with the windows runtime in general, so am getting tied up in the microsoft documentation.
What is the current recommended approach, especially for the native side of things?
Most articles online talk about writing a C++/CLI compatibility layer, but then Microsoft seems to recommend C++/WinRT now, and there was a C++/CX between the two that’s barely ever mentioned.
What’s the (current) deal? Can I write native C++ code, somehow use the C++/WinRT libraries in it, and then expect to be able to create native classes and call their methods? Is some C++/CLI wrapper still necessary?
The similar names between all of these are making it quite difficult to find information that doesn’t assume knowledge of how everything worked historically.
Upvotes: 2
Views: 931
Reputation: 41127
TL;DR: Windows Runtime is something you can use from .NET applications, but it is NOT otherwise related to the .NET Runtime/Framework.
Windows Runtime is a design pattern for APIs. These are consumable from C++, C#, and JavaScript+HTML. It extends classic COM IUnknown
with an IInspectable
that uses .NET style metadata.
C++/CX language extensions were created as a way to easily consume "Windows Runtime" APIs from C++. This reused a lot of the same "reserved keywords" that were already in use for Managed C++, and as a result there's been a lot of conflation between them. The key takeaways here are: (a) there is no .NET Runtime at work, (b) it's only implemented by the Microsoft Visual C++ compiler (the /ZW
, /FU
, /AI
switches), and (c) it's no longer recommended as the way to consume "Windows Runtime" APIs from C++.
https://devblogs.microsoft.com/cppblog/inside-the-ccx-design/
C++/WinRT is a portable Standard C++ Language only way to both consume and author "Windows Runtime" APIs. It uses C++17 language features, and supports both Visual C++ and clang/LLVM as well as other conformant compilers.
https://blogs.windows.com/windowsdeveloper/2016/11/28/standard-c-windows-runtime-cwinrt/
When you author a "Windows Runtime" API, you can support clients calling you from C++, C#, or JavaScript+HTML.
Upvotes: 3