We have developed a C++ WinRT Component DLL & C#.NET application in the post here Under the hood Part 1 : C++ WinRT Component DLL & C#.NET Metro application
we have seen the compiler generated components for making the C# application access the C++ WinRT component here Under the hood Part 2 : C++ WinRT Component DLL & C#.NET Metro application
See the post on First Look at What’s New in Windows 8 here.
Going further, I created a C++ Metro application and accessed the C++ WinRT Component DLL from this application. The interesting part here is that C++ applications is XAML based. No more .RC and resource.h files in C++ (for metro). We will explore the C++ application in another post. In this post, let us walk through the packaging and installation process that happens in the background during building and deploying of the applications.
Basically, there are two registrations for our application.
- Extension registration
- Class registration.
The figure 1 (from Build con) shows the relation between the two.
Fig : Slide related to Extension Catalog and Class Catalog shown @ Build con.
Go to Visual Studio 2011 –> Solution Explorer –> CSharpApplication project, here you can find a file named Package.appxmanifest as shown in figure 1 . This file has most of the information needed to deploy the application. This is the information that windows uses to identify the application. Package Name is the name used in most of the identification process.
Fig 1: Package.appxmanifest file in Visual Studio 2011 Solution Explorer.
Code snippet of Package.appxmanifest file.
<Identity Name="CSharpApplicationCallingCPPComponent" Publisher="CN=Kishore" Version="126.96.36.199" />
<Resource Language="en-us" />
<Application Id="App" Executable="csharpapplication.exe" EntryPoint="CSharpApplication.App">
<VisualElements DisplayName="CSharpApplication" Logo="Images\Logo.png" SmallLogo="Images\SmallLogo.png" Description="CSharpApplication" ForegroundText="light" BackgroundColor="#222222" InitialRotationPreference="portrait">
<SplashScreen Image="Images\SplashScreen.png" />
<Capability Name="internetClient" />
The applications implement contract like search contract, share, play queue contract. Those contract registrations are the extensions registration for the operating system. Tile that you see in the Windows start page is just another contract activation. I,e windows.launch contract. So if you go to HKEY_CURRENT_USER\Software\Classes\Extensions\ContractId\Windows.Launch, you can find your application package id that we saw in figure 1. Everything under Windows.Launch is organized by package ID as shown in the figure 2 below.
Fig 2: Registry settings showing the registered Extensions.
From figure 2, we can see our package HKEY_CURRENT_USER\Software\Classes\Extensions\ContractId\Windows.Launch\ PackageId\csharpapplicationcallingcppcomponent_188.8.131.52_x86_neutral_kb63pw67p0swp. This package has a ActivatableClassId key . Under that we see App as shown in figure 3. This is the class registration for this extension.
Fig 3: App registry settings for your application.
Let us see how the class registration for the applications looks like. First, We have extensions which say I implement this contract for ex I implement this launch and then we have classes. The extensions point to the classes. classes are actually the implementation. All applications are just Windows Runtime objects to the Windows OS, this is where all it starts. This is the windows runtime class that the OS knows about for your application.
The interesting part is in the class registration for the application. If we go up in the registry editor, we should see a registry key called ActivatableClasses at HKEY_CURRENT_USER\Software\Classes\ActivatableClasses, this is where the class registrations are for all of our applications are. Here again we find package. All extensions, all classes are organized based on the package. That means our application or package has unique set of classes and they don’t share extension points or classes with other applications. They are all unique for our app. If we expand it, we see ActivatableClassId, the same name we saw in extensions. Here we should find the App classId. This is the WinRT class registration. This is the same for all types of applications, libraries etc.
Here we can see some registration attributes . The ActivationType is an important one. Windows Runtime supports two activation styles.
- InProcess activation
- Out of process activation
So Windows Runtime supports InProcess activation where we provide the DLL and windows load that into the process and it also supports out of process activation, where we will provide an exe and windows will launch the exe as your class implementation.
Registry key values:
ActivationType = 1 indicates its out of process activation class. out of process classes have a server. we have to know where the executable is, so there is a server registion here.
ActivationType = 0 indicates its in process activation
Out of process has a server and so there is a server registration here. Server with value App.AppXpdnr4x0evrk1yjmz5xfw2ksncfcjc5er.mca as shown in figure 4.
Fig 4: Server registry values for your application.
In figure 3, below the ActivationType , we can find Server attribute and it contains the App.AppXpdnr4x0evrk1yjmz5xfw2ksncfcjc5er.mca we got from the above Server value. The server registration, tells the windows runtime enough information about what code we actually need to get from the disk and start running to get the app up and running. The ExePath attribute gives the path to the exe.
Windows runtime supports two apartment models. MTA & STA. If you have worked in VC++ COM, COM+ earlier, then you might have programmed the components for Multi Threaded Apartment model & Single Threaded Apartment model.
Let us see some more ActivatableClassId entries for Windows Runtime present at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsRuntime as shown in figure 5.
Fig 5: Windows Runtime classes information.
Finally, the slide that caught my attention was the deployment pipeline process shown in Fig 6 that shows the overall view of the above mentioned information.
Figure 6 showing the role of the deployment engine @ Build Con.
"Only those who risk going too far can possibly find out how far they can go." – T.S. Eliot