Hi - as a newbie I couldn't find too much info about how to go about writing an interface plugin for MC. As a result, I've put together a small howto showing how I got it to work. Let me know if it's useful or just plain wrong !
S
------------------
How to make a Media Center Interface Plugin
===========================================
This assumes the use of Microsoft Visual Studio .NET 2003
First, create the project
-------------------------
Use the Visual Studio new project wizard (File->New->Project)
to create an "ATL Project" (this can be found under
"Visual C++ Projects->ATL" in the wizard). The default Application
Settings (DLL, etc) are fine.
I will assume the project is called "TestATL" - please bear this in
mind when I refer to this as your project will probably be called
something more sensible !
Now add the control
-------------------
This control will the the one visible in Media Center when you click
on your plugin. Click on Project->Add Class to open the wizard.
Select the ATL Control icon and press Open. Type in a name for your
control in the Short Name box - Visual Studio will fill in the other
boxes automatically.
I will assume your control is called "Test" - please bear this in mind
as you will probably give your control a better name
Before pressing Finish, click on the Options menu on the left. From
this page, select Composite Control - this will allow your control
to host other controls. All the other settings are fine so now click
on Finish.
Tell Media Center about your plugin
-----------------------------------
This is done in the DllRegisterServer() method. By default, this will
be implemented for you so you now have to override it. Go to the main
project file (in the case of this example, TestATL.cpp). You will see
a class called CTestATLModule - put the following code in the
"Override CAtlDllModuleT members" part of the public section.
HRESULT DllRegisterServer()
{
// Register with Media Center
TCHAR cRegistryPath[1024];
HKEY hk;
DWORD dwDisp;
wsprintf( cRegistryPath, _T("%s%s"), REGISTRY_PATH_MJ_PLUGINS_INTERFACE, _T("Test") );
if ( RegCreateKeyEx( HKEY_LOCAL_MACHINE, cRegistryPath,
0, NULL, REG_OPTION_NON_VOLATILE,
KEY_WRITE, NULL, &hk, &dwDisp ) == ERROR_SUCCESS )
{
DWORD nIVersion = 1;
DWORD nPluginMode = 1;
TCHAR* strCompany = _T( "Your Company" );
TCHAR* strVersion = _T( "1.0.0" );
TCHAR* strURL = _T( "
http://www.yourcompany.com" );
TCHAR* strCopyright = _T( "Copyright (c) 2004, You" );
LPWSTR strID;
StringFromCLSID( CLSID_CTest, &strID );
RegSetValueExW( hk, _T("IVersion"), 0, REG_DWORD, (LPBYTE)&nIVersion, sizeof(DWORD) );
RegSetValueExW( hk, _T("PluginMode"), 0, REG_DWORD, (LPBYTE)&nPluginMode, sizeof(DWORD) );
RegSetValueExW( hk, _T("CLSID"), 0, REG_SZ, (LPBYTE)strID, _tcslen(strID)*sizeof(TCHAR) );
RegSetValueExW( hk, _T("Company"), 0, REG_SZ, (LPBYTE)strCompany, _tcslen(strCompany)*sizeof(TCHAR) );
RegSetValueExW( hk, _T("Version"), 0, REG_SZ, (LPBYTE)strVersion, _tcslen(strVersion)*sizeof(TCHAR) );
RegSetValueExW( hk, _T("URL"), 0, REG_SZ, (LPBYTE)strURL, _tcslen(strURL)*sizeof(TCHAR) );
RegSetValueExW( hk, _T("Copyright"), 0, REG_SZ, (LPBYTE)strCopyright, _tcslen(strCopyright)*sizeof(TCHAR) );
}
// Make sure we call the CAtlDllModuleT implementation
return __super::DllRegisterServer();
}
Of course if your control is called something other than Test then please change the
above accordingly - specifically the CLSID_CTest bit.
Before this code will compile, you'll need to add the following lines to the file.
// The automatically generated file containing the GUID definitions
#include "_TestATL_i.c"
// The Media Center Plugin registry key
static const TCHAR* REGISTRY_PATH_MJ_PLUGINS_INTERFACE = _T("Software\\JRiver\\Media Jukebox\\Plugins\\Interface\\");
Additionally, for the above code to compile you will need to setup your project to use
Unicode. Do this by going to Project->TestATL Properties and changing "Character Set" to
"Use Unicode Character Set" in the General menu.
Implement the Media Center interface
------------------------------------
We're almost done with setting up the plugin. All that's is that we implement the Init()
interface that Media Center requires all interface plugins to provide. To do this,
switch to "Class View" in the Visual Studio project window at the top right. From here,
right click on the ITest interface and choose Add->Add Method. Enter "Init" for the
method name, check the "in" parameter attribute and select IDispatch* as the parameter
type. Call the parameter what you want and click Finish.
Compile and see your plugin in Media Center
-------------------------------------------
Hit F7 to build the solution. If all goes well, Visual Studio will build and then register
your ATL control (have a look in the registry to make sure). Then start Media Center, go to
Tools->Plugin Manager and then select Interface. You should see your plugin ! Click on it
and you should see the information you entered in DllRegisterServer(). Just to make sure,
exit the Plugin Manager and select Plugins from the main tree display on the left. You
should see your plugin ! Clicking on it will show a blank window - but that's because we
haven't actually got our plugin to do anything yet - that's up to you