Skip to content

Commit

Permalink
naming convention (#2431)
Browse files Browse the repository at this point in the history
* naming convention

* parens
  • Loading branch information
stevewhims authored Apr 2, 2022
1 parent 4901569 commit 6443eb6
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ The Windows Runtime component that you'll build in this topic contains a runtime
> [!IMPORTANT]
> For essential concepts and terms that support your understanding of how to consume and author runtime classes with C++/WinRT, see [Consume APIs with C++/WinRT](../cpp-and-winrt-apis/consume-apis.md) and [Author APIs with C++/WinRT](../cpp-and-winrt-apis/author-apis.md).
## Naming best practice for Windows Runtime component dlls

> [!IMPORTANT]
> This section describes the naming convention that we recommend you use for the `.dll` file (DLL) that you build your Windows Runtime component into. It's all about the activation sequence that C++/WinRT follows when you consume a runtime class from a Windows Runtime component.
When activating a class factory, C++/WinRT first tries a call to [**RoGetActivationFactory**](/windows/win32/api/roapi/nf-roapi-rogetactivationfactory). If that fails, then C++/WinRT tries to find a DLL to load directly. Windows Runtime activation is always based on a fully-qualified class name. The logic is to remove the class name (from that fully-qualified class name), and then look for a DLL named for the full namespace that remains. If that's not found, remove the most-specific segment name, and repeat.

So for example if the class being activated has a fully-qualified name of **Contoso.Instruments.ThermometerWRC.Thermometer**, and **RoGetActivationFactory** fails, then we'll first look for a `Contoso.Instruments.ThermometerWRC.dll`. If that's not found, then we'll look for `Contoso.Instruments.dll`, and then for `Contoso.dll`.

When a DLL is found (in that sequence), we'll use that DLL's [**DllGetActivationFactory**](/previous-versions/br205771(v=vs.85)) entry point to try to obtain the factory directly (rather than indirectly via the **RoGetActivationFactory** function that we first attempted). Even so, the end result is indistinguishable to the caller and to the DLL.

This process is completely automatic—no registration or tooling is needed. If you're authoring a Windows Runtime component, then you just need to use a naming convention for your DLLs that works with the process just described. And if you're consuming a Windows Runtime component and it's not named correctly, then you have the option to rename it as described.

## Create a Windows Runtime component (ThermometerWRC)

Begin by creating a new project in Microsoft Visual Studio. Create a **Windows Runtime Component (C++/WinRT)** project, and name it *ThermometerWRC* (for "thermometer Windows Runtime component"). Make sure that **Place solution and project in the same directory** is unchecked. Target the latest generally-available (that is, not preview) version of the Windows SDK. Naming the project *ThermometerWRC* will give you the easiest experience with the rest of the steps in this topic.
Expand Down

0 comments on commit 6443eb6

Please sign in to comment.