Skip to content

Commit

Permalink
updates to the porting topics (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevewhims authored Apr 21, 2020
1 parent 8008b78 commit 816370e
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ms.localizationpriority: medium

This topic presents a case study of porting one of the [Universal Windows Platform (UWP) app samples](https://github.com/microsoft/Windows-universal-samples) from [C#](/visualstudio/get-started/csharp) to [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt). You can gain porting practice and experience by following along with the walkthrough and porting the sample for yourself as you go.

Also see [Move to C++/WinRT from C#](/windows/uwp/cpp-and-winrt-apis/move-to-winrt-from-csharp), which presents a number of sections that address specific technical details involved in porting from C# to C++/WinRT.
For a comprehensive catalog of the technical details involved in porting to C++/WinRT from C#, see the companion topic [Move to C++/WinRT from C#](/windows/uwp/cpp-and-winrt-apis/move-to-winrt-from-csharp).

## Download and test the Clipboard sample

Expand Down Expand Up @@ -134,7 +134,9 @@ And you'll recall that **MainPage.Scenarios** is a collection of **Scenario** ob

Now let's add to the `MainPage.idl` file the new types and the new member of **Mainpage** that we've decided to declare in IDL. At the same time, we'll remove from the IDL the placeholder members of **Mainpage** that the Visual Studio project template gave us.

So, in your C++/WinRT project, open `MainPage.idl`, and edit it so that it looks like the listing below. Note that one of the edits is to change the namespace name from **Clipboard** to **SDKTemplate**. If you like, you can just delete the current contents of your `MainPage.idl`, and paste in the listing below. Another tweak to note is that we're changing the name of **Scenario::ClassType** to **Scenario::ClassName**.
So, in your C++/WinRT project, open `MainPage.idl`, and edit it so that it looks like the listing below. Note that one of the edits is to change the namespace name from **Clipboard** to **SDKTemplate**. If you like, you can just replace the entire contents of `MainPage.idl` with the following code. Another tweak to note is that we're changing the name of **Scenario::ClassType** to **Scenario::ClassName**.



```idl
// MainPage.idl
Expand Down Expand Up @@ -1122,7 +1124,7 @@ There's value in consolidating your runtime classes into a single IDL file (see

While we're doing that, let's also remove the auto-generated dummy property (`Int32 MyProperty;`, and its implementation) from each of those five XAML page types.

First, add a new **Midl File (.idl)** item to the C++/WinRT project. Name it `Project.idl`. Delete the default contents of `Project.idl`, and in its place paste the listing below.
First, add a new **Midl File (.idl)** item to the C++/WinRT project. Name it `Project.idl`. Replace the entire contents of `Project.idl` with the following code.

```idl
// Project.idl
Expand Down
2 changes: 2 additions & 0 deletions windows-apps-src/cpp-and-winrt-apis/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ If you have a runtime class that frees resources in its destructor, and that run
- If you can't guarantee that you have the last remaining reference to an object (because you passed it to other APIs, which could be keeping a reference), then calling **IClosable::Close** is a good idea.
- When in doubt, it's safe to call **IClosable::Close** manually, rather than waiting for the wrapper to call it on destruction.

So, if you know that you have the last reference, then you can let the wrapper destructor do the work. If you need to close before the last reference vanishes, then you need to call **Close**. To be exception-safe, you should **Close** in a resource-acquisition-is-initialization (RAII) type (so that close happens on unwind). C++/WinRT doesn't have a **unique_close** wrapper, but you can make your own.

## Can I use LLVM/Clang to compile with C++/WinRT?
We don't support the LLVM and Clang toolchain for C++/WinRT, but we do make use of it internally to validate C++/WinRT's standards conformance. For example, if you wanted to emulate what we do internally, then you could try an experiment such as the one described below.

Expand Down
4 changes: 2 additions & 2 deletions windows-apps-src/cpp-and-winrt-apis/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ C++/WinRT performs better and produces smaller binaries than any other language
| [Move to C++/WinRT from C++/CX](move-to-winrt-from-cx.md) | This topic describes the technical details involved in porting the source code in a [C++/CX](/cpp/cppcx/visual-c-language-reference-c-cx) project to its equivalent in [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt). |
| [Interop between C++/WinRT and C++/CX](interop-winrt-cx.md) | This topic shows two helper functions that can be used to convert between [C++/CX](/cpp/cppcx/visual-c-language-reference-c-cx) and [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt) objects. |
| [Move to C++/WinRT from WRL](move-to-winrt-from-wrl.md) | This topic shows how to port [Windows Runtime C++ Template Library (WRL)](/cpp/windows/windows-runtime-cpp-template-library-wrl) code to its equivalent in [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt). |
| [Porting the Clipboard sample to C++/WinRT from C#—a case study](clipboard-to-winrt-from-csharp.md) | This topic presents a case study of porting one of the [Universal Windows Platform (UWP) app samples](https://github.com/microsoft/Windows-universal-samples) from [C#](/visualstudio/get-started/csharp) to [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt). |
| [Move to C++/WinRT from C#](move-to-winrt-from-csharp.md) | This topic describes the technical details involved in porting the source code in a [C#](/visualstudio/get-started/csharp) project to its equivalent in [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt). |
| [Porting the Clipboard sample to C++/WinRT from C#—a case study](clipboard-to-winrt-from-csharp.md) | This topic presents a case study of porting one of the [Universal Windows Platform (UWP) app samples](https://github.com/microsoft/Windows-universal-samples) from [C#](/visualstudio/get-started/csharp) to [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt). You can gain porting practice and experience by following along with the walkthrough and porting the sample for yourself as you go. |
| [Move to C++/WinRT from C#](move-to-winrt-from-csharp.md) | This topic comprehensively catalogs the technical details involved in porting the source code in a [C#](/visualstudio/get-started/csharp) project to its equivalent in [C++/WinRT](/windows/uwp/cpp-and-winrt-apis/intro-to-using-cpp-with-winrt). |
| [Interop between C++/WinRT and the ABI](interop-winrt-abi.md) | This topic shows how to convert between application binary interface (ABI) and C++/WinRT objects. |
| [Strong and weak references in C++/WinRT](weak-references.md) | The Windows Runtime is a reference-counted system; and in such a system it's important for you to know about the significance of, and distinction between, strong and weak references. |
| [Agile objects](agile-objects.md) | An agile object is one that can be accessed from any thread. Your C++/WinRT types are agile by default, but you can opt out. |
Expand Down
Loading

0 comments on commit 816370e

Please sign in to comment.