oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Building .NET Add-Ins for Windows Media Center Edition

by Michael Earls


Windows XP Media Center Edition 2005 is an exciting platform for enjoying all of your media from the comfort of your sofa. However, there are many times that you might wish to extend Media Center to perform functionality that it does not have "out of the box." Microsoft has created a software development kit that allows you to write your own software that runs in Media Center. In a previous article, I gave you a broad-brush introduction to creating an HTML application that runs in the 10-foot experience of Windows Media Center. This article will introduce you to the creation of .NET add-ins that are hosted within Media Center. The .NET add-ins allow you to write functional code that can interact with Media Center using your favorite .NET language.

There are two types of .NET add-ins for Media Center:

  • Background--runs at Media Center startup and remains running in the background
  • On-Demand--executed in response to some action from the user

Getting Started

One of the first things you need to know about creating add-ins for Windows XP Media Center Addition 2005 is that they must be written and compiled in .NET 1.0. This is due to the fact that the add-in is hosted by the Media Center process, and that's the only version that Microsoft supports at the present time. This causes many developers a little discomfort, because they are accustomed to working with Visual Studio 2003, which supports only .NET 1.1. However, you can continue to use your existing editor of choice to write the code and then use the .NET compiler on the Media Center computer to compile it. That is the approach that I'll take in this article so that you can get a quick feel for developing an add-in for Media Center without having to install an older version of Visual Studio.

Before we get started, make sure you've downloaded and installed the Media Center Software Developer Kit (SDK).

Related Reading

Home Hacking Projects for Geeks
By Eric Faulkner, Tony Northrup

Required Interfaces

In order to allow your class to interact with Media Center, you need to be familiar with two interfaces:

  • IAddInModule--Media Center uses this interface to trigger your add-in to initialize and uninitialize. It has two methods:
    • Initialize--called when the add-in is first loaded
    • Uninitialize--called when Media Center wants to shut down your add-in
  • IAddInEntryPoint--This is the main interface that Media Center uses when it launches your add-in. All add-ins must implement this interface. It has a single method:
    • Launch--Called after your add-in has been initialized, this is where your primary execution logic should go. Think of it as the old reliable Sub Main in Visual Basic.

Sample Code--Hello, World

Let's create a class that will implement the required interfaces and show users a dialog when they run it. It's important that you not pop your own dialogs or create your own windows from your add-in. All interaction with the user should be done through the provided interface. Media Center provides us with a dialog that we can use. Create a directory on the Media Center machine to contain your source code. Then, save the code below to a file named HelloWorld.cs:

using System;
using System.Collections;
using Microsoft.MediaCenter.AddIn;

namespace Sample
  public class HelloWorld : MarshalByRefObject, 
    private AddInHost mcHost;

    void IAddInModule.Initialize(
                           IDictionary dictAppInfo,
                           IDictionary dictEntryPoint)

    void IAddInModule.Uninitialize()

    void IAddInEntryPoint.Launch(AddInHost host)
      mcHost = host;
      mcHost.HostControl.Dialog("Hello, World", 

Notice that the Launch method of the IAddInEntryPoint handed us a reference to an instance of the AddInHost. This is our doorway to the functionality provided by Media Center. Everything you'll ever need to do with Media Center is in that AddInHost instance. We simply asked the HostControl instance to pop a dialog for us.

We need to tell the compiler a little bit about our class, so create a text file named AssemblyInfo.cs, paste the following code into it, and save it in the same folder with the HelloWorld.cs file:

using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("Media Center Hello World")]
[assembly: AssemblyDescription("Hello, World")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("1.0.0")]

Pages: 1, 2

Next Pagearrow