We are writing our plugin for Windows Media Center. Part 1
Hello, habra community!
On this wonderful day, all those who are not indifferent to words such as development, code, compilation and debugging, those who are currently typing their anniversary 100 millionth line of code and those who have successfully compiled and launched the first ever "Hello, World!" I want to congratulate you on your professional holiday. I wish you fewer bugs, fast compilers, mutual understanding with the debugger, and most importantly, there should be people nearby who can truly appreciate your work!
I recently started writing my application under WMC .
Translating and quoting the SDK is boring and not interesting.
Therefore, today I will describe step by step the creation of a simple plugin.
Let's try to write a simple analog clock.
You can download the SDK at this address .
The SDK installs after installing Visual Studio.
Examples included in the development kit are located in the% Program Files% \ Microsoft SDKs \ Windows Media Center \ v6.0 \ Samples folder.
We start Visual Studio.
If the installation and integration of the SDK was successful, then in the type tree you can easily find the Windows Media Center branch.
As a development language, I chose C #. Select the Windows Media Center Application - Fundamental template. Give our project a name, for example habraClock. Click OK.

I think that the Visual Studio interface does not need to be described separately, we are all well acquainted with it.
Let's take a better look at what we see in the solution explorer. The Code folder contains the Launch.cs file. This file describes our MyAddIn class, which inherits the IAddInModule, IAddInEntryPoint interfaces. The Launch procedure implements a member of the IAddInEntryPoint interface and is an entry point. It is she who is called when our application is launched in Media Center. The basic objects of WMC navigation are the pages described in the xml-based MCML markup language . The only thing that the Launch procedure will do in our example is to go to the Default page described in the Default.mcml file of the Markup folder.

Also important files for us are DevInstall.cmd in the project bark and Registration.xml in the Setup folder.
DevInstall.cmd is needed to register our assembly in the system. Without this action, we will not see anything new in WMC applications.
To register our plugin, you need to run the command line in administrator mode, go to the project folder, and run there
The / debug switch is added if the configuration of the Debug assembly is. If the Release configuration is being assembled, then you do not need to add a key.
Another startup option is / u. The key is used to remove information about our plugin from the system.
In order not to suffer with a large number of open windows, I do so - in the project properties on the tab "Build Events" in the event after build, I add the automatic registration of the assembly. Accordingly, Visual Studio starts in administrator mode.
In order for the plugin to run in WMC, it must be signed.
In the project properties, go to the "Signing" tab, check the box "Sign the assembly" and select the snk file with your signature.
If you do not already have such a file, then create it by selecting the "Create" item from the drop-down list.
Putting together a project (F6).
Run the command line to get the public key of the assembly. At the command prompt, execute
At the output, we get a string of the form
We open the Registration.xml file in the Setup folder and change PublicKeyToken = insert_public_key_token_here to PublicKeyToken = 597ac92eb14461f4 there.
We assemble the project, install it with DevInstall (unless, of course, you registered automatic installation according to my recipe).
Launch Media Center.
If we did everything right, then on the Applications page we will see, among others, our habraClock. After its launch, the contents of the Default.mcml file will appear on the screen, namely, a line with the text Hello.


Today we learned how to create, sign and register an application for Windows Media Center.
On this I want to finish the first part of the article.
And, while I am engaged in its continuation - a little homework.
Since I myself am not a designer at all - think up and change the standard picture of the application, for something more sane and associated with the Habr.
Waiting for your suggestions, wishes, criticism.
2009 lnking . Any use of the materials of this article outside the habr is permitted with the obligatory indication of the source.
A slight digression
On this wonderful day, all those who are not indifferent to words such as development, code, compilation and debugging, those who are currently typing their anniversary 100 millionth line of code and those who have successfully compiled and launched the first ever "Hello, World!" I want to congratulate you on your professional holiday. I wish you fewer bugs, fast compilers, mutual understanding with the debugger, and most importantly, there should be people nearby who can truly appreciate your work!
Now let's get started
I recently started writing my application under WMC .
Translating and quoting the SDK is boring and not interesting.
Therefore, today I will describe step by step the creation of a simple plugin.
Let's try to write a simple analog clock.
What do we need?
- Windows with MediaCenter installed (I use Windows 7 ultimate rtm)
- Microsoft Visual Studio (I will give examples for version 2008)
- Microsoft MediaCenter SDK (Hereinafter we focus on version 6.0)
Installation
You can download the SDK at this address .
The SDK installs after installing Visual Studio.
Examples included in the development kit are located in the% Program Files% \ Microsoft SDKs \ Windows Media Center \ v6.0 \ Samples folder.
Create a simple empty template application
We start Visual Studio.
File -> Create -> Project -> New Project
If the installation and integration of the SDK was successful, then in the type tree you can easily find the Windows Media Center branch.
As a development language, I chose C #. Select the Windows Media Center Application - Fundamental template. Give our project a name, for example habraClock. Click OK.
What is before us?
I think that the Visual Studio interface does not need to be described separately, we are all well acquainted with it.
Let's take a better look at what we see in the solution explorer. The Code folder contains the Launch.cs file. This file describes our MyAddIn class, which inherits the IAddInModule, IAddInEntryPoint interfaces. The Launch procedure implements a member of the IAddInEntryPoint interface and is an entry point. It is she who is called when our application is launched in Media Center. The basic objects of WMC navigation are the pages described in the xml-based MCML markup language . The only thing that the Launch procedure will do in our example is to go to the Default page described in the Default.mcml file of the Markup folder.
Also important files for us are DevInstall.cmd in the project bark and Registration.xml in the Setup folder.
DevInstall.cmd is needed to register our assembly in the system. Without this action, we will not see anything new in WMC applications.
To register our plugin, you need to run the command line in administrator mode, go to the project folder, and run there
DevInstall.cmd / debug
The / debug switch is added if the configuration of the Debug assembly is. If the Release configuration is being assembled, then you do not need to add a key.
Another startup option is / u. The key is used to remove information about our plugin from the system.
In order not to suffer with a large number of open windows, I do so - in the project properties on the tab "Build Events" in the event after build, I add the automatic registration of the assembly. Accordingly, Visual Studio starts in administrator mode.
We sign the assembly
In order for the plugin to run in WMC, it must be signed.
In the project properties, go to the "Signing" tab, check the box "Sign the assembly" and select the snk file with your signature.
If you do not already have such a file, then create it by selecting the "Create" item from the drop-down list.
Putting together a project (F6).
Run the command line to get the public key of the assembly. At the command prompt, execute
% Program Files% \ Microsoft SDKs \ Windows \ v6.0A \ Bin \ sn.exe -T [path to our project] \ Bin \ Debug \ habraClock.dll
At the output, we get a string of the form
Public Key Token: 597ac92eb14461f4
We open the Registration.xml file in the Setup folder and change PublicKeyToken = insert_public_key_token_here to PublicKeyToken = 597ac92eb14461f4 there.
We assemble the project, install it with DevInstall (unless, of course, you registered automatic installation according to my recipe).
We admire the results of our work
Launch Media Center.
If we did everything right, then on the Applications page we will see, among others, our habraClock. After its launch, the contents of the Default.mcml file will appear on the screen, namely, a line with the text Hello.
Conclusion
Today we learned how to create, sign and register an application for Windows Media Center.
On this I want to finish the first part of the article.
And, while I am engaged in its continuation - a little homework.
Since I myself am not a designer at all - think up and change the standard picture of the application, for something more sane and associated with the Habr.
Waiting for your suggestions, wishes, criticism.
2009 lnking . Any use of the materials of this article outside the habr is permitted with the obligatory indication of the source.