Share using Windows Runtime Components

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

 

With Windows Runtime components, you can now mix programming languages and API technologies to build the apps you envision.

This topic contains the following sections.

 

What is a Windows Runtime Component?

A Windows Runtime Component, sometimes referred to as a 3rd-party Windows Runtime Component, is a component you build to expose functionality to all supported languages. By using the Windows Runtime, which is supported on Windows Phone 8 and Windows 8, you can create components and call them in a simple and natural way from the language of your choice. The component is built using the Windows Runtime Component template in Visual Studio. Its functionality is output as a .winmd file, which contains the metadata needed to project the functionality automatically into C#, C++, VB and JavaScript.

When to use a Windows Runtime Component when building an app for Windows Phone 8 and Windows 8 

The following list describes when you should consider sharing functionality of your app in Windows Runtime Component.

  • Harnessing the power of C++: If your app carries out computationally intensive operations, you might opt to write that code in C++ to achieve optimal performance. If the code that uses this functionality is written in C# or VB, you can package the functionality as a Windows Runtime Component and call the component from your managed code.

  • Crossing language boundaries: In general, using a Windows Runtime Component is a great way to expose your code to all supported languages. This is not necessary if your app is written in one language and you don’t intend to expose any of your functionality to other languages. Instead you can compose your app of regular class libraries, Portable Class Libraries or, depending on the size and complexity of your app, just write the whole app in the same project.

  • Using Direct3D, Win32, or COM APIs: Windows Phone 8 delivers native API to enable powerful gaming scenarios, native networking and access to camera API from native code. To use these API from managed code, you can wrap this functionality in a Windows Runtime Component. For more info, see Supported Win32 APIs for Windows Phone 8 and Games for Windows Phone 8.

  • Using third-party libraries: In the past, it was difficult to consume a third-party library, written in one language, if your app written in another language. With Windows Runtime Components, it is possible to grab a library, wrap it in a Windows Runtime Component and expose the functionality to your app written in any supported language.

The preceding list is some of the scenarios where writing a Windows Runtime Component is a very useful way of sharing code. However, a Windows Runtime Component is not a standard DLL or assembly. There are very specific requirements you must follow when creating a Windows Runtime Component. These requirements include using only allowed data types, handling collections, creating only sealed classes and many more. Visual Studio will help at compile time, and indicate clearly when something goes wrong.

Creating and consuming Windows Runtime Components

The language in which you can write a Windows Runtime Component and the languages that can consume a Windows Runtime Component vary for each platform. The following table summarizes what is supported on Windows Phone 8 and what is supported on Windows 8.

Platform

Create

Consume

Windows Phone 8

C++

C++, C#, VB

Windows 8

C++, C#, VB

C++, C#, VB, JavaScript

See Also

Other Resources

Windows Phone 8: Using C++ in your Applications (Build 2012)

Build 2012: How to Leverage your Code across Windows Phone 8 and Windows 8

Code Sample: Explore Windows Runtime Components for Windows Phone

Code Sample: PixPresenter