INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Help creating C# Plugin with VS 2008  (Read 3284 times)

Jeronimo

  • Recent member
  • *
  • Posts: 14
  • Suicide's an easy solution...I like easy solutions
Help creating C# Plugin with VS 2008
« on: December 01, 2009, 01:55:32 pm »

Hello everybody.
For a while I've been trying to create a test interface plugin with C# in Visual Studio 2008, for Media Jukebox.

Here are the things I tried:

(VS Console App)
Connect to MJ with COM (added Interop.MediaJukebox to References):
Worked when MJ was off and only once when it was on. All other tries got a 8008005 COMException.

(VS Class Library)
Tried combinations with "MediaCenter.dll" from the .NET Script Plugin folder, "MediaCenter.dll" created with TlbImp from "http://www.jrmediacenter.com/DevZone/MediaCenterSDK.rar/MediaCenterSDK/Shared/MCPlayerLib.tlb" and the Interop.MediaJukebox (Media Jukebox 12.tlb in Media Jukebox installation folder).
Here's the code for the TestPlugin:
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MediaJukebox;
using MediaCenter;
using System.Windows.Forms;

namespace Test_Plugin
{
   public class Test_Plugin
   {
      public void Init(Object automat)
      {
         MessageBox.Show("Finally a plugin !");
      }

      public void Init(MJAutomation automat)
      {
         MessageBox.Show("Finally a plugin !");
      }

      public void Init(MCAutomation automat)
      {
         MessageBox.Show("Finally a plugin !");
      }
   }
}

I just cannot start it in Media Jukebox. It's registered with this .reg file:
Code: [Select]
REGEDIT4

[HKEY_LOCAL_MACHINE\Software\JRiver\Media Jukebox\Plugins\Interface\Test Plugin]
"IVersion"=dword:00000001
"Company"="CTeam2005"
"Version"="1"
"URL"="http://www.cteam2005.de"
"Copyright"="Copylefted. Fuck copyright."
"PluginMode"=dword:00000000
"ProdID"="TestPlugin"

I put the created dll (renamed to "int_TestPlugin", "int_Test Plugin", "TestPlugin" and "Test Plugin") into the "Plugins" folder and into a "Plugins/TestPlugin" folder. Yet all the time I get this error message "Interface plug-in 'Test Plugin' could not be found or created."
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Help creating C# Plugin with VS 2008
« Reply #1 on: December 01, 2009, 02:04:47 pm »

Some of these may help:
http://wiki.jrmediacenter.com/index.php/MC_Plugin_Template_for_Visual_Studio

http://yabb.jriver.com/interact/index.php?topic=31946.0 - bit dated.

Neither of these were produced with 2008, so you may have to play to get them to work...

Jeronimo

  • Recent member
  • *
  • Posts: 14
  • Suicide's an easy solution...I like easy solutions
Re: Help creating C# Plugin with VS 2008
« Reply #2 on: December 02, 2009, 01:52:20 pm »

Mr ChriZ thanx for the link. The template project help me out. I really wanted to know how to create a plugin from scratch with a plugin, so that if I did loose the template (or not have one the first place) I wouldn't need it.

I finally got a VS 2008 C# Class lib to work. For future reference here is the code from the CS file - just copied from Mr ChriZ's file, thus courtesy or Mr ChriZ (thanx again):
Code: [Select]
//Description:
//
//Author:
//
//Plugin Creation Date:
//__/__/____
//Version Number:
//0.0.1
//Template Created by Mr ChriZ


#region Libraries
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
#endregion

namespace MC_CSPlugin
{
    #region Interop Program ID Registration
    //The interop services allow the plugin to be registered with a CLSID so Media Center
    //Can find it
    //The Prog ID must match with that in the registry in order for
    //MC to be able to pick up the plugin
   [System.Runtime.InteropServices.ProgId("Template_MCPlugin.CSTemplate")]
    #endregion
    public partial class MainInterface : UserControl
    {
        #region Attributes
        //This is the Interface to Media Center
        //This is set when Media Center calls the Init Method       
        private MediaJukebox.MJAutomation mediaCenterReference;
        #endregion

        #region Constructor
        /// <summary>
        /// This is the main constructor for the plugin
        /// </summary>
        public MainInterface ( )
        {
            InitializeComponent ( );
        }
        #endregion

        #region Media Center Initialisation
        /// <summary>
        /// After the plugin has been created Media Center
        /// will call the following method, giving us a reference
        /// to the Media Center interface.
        /// </summary>
        /// <param name="mediaCenterReference">
        /// Media Center Reference
        /// </param>       
        public void Init ( MediaJukebox.MJAutomation mediaCenterReference )
        {   
            try
            {                 
                this.mediaCenterReference = mediaCenterReference;
            }
            catch (Exception e)
                    {
                        MessageBox.Show ( "A Fatal error has occured while creating plugin:-" + e.Message +
                                "\n The Failure Occured" +
                                "\n In Class Object " + e.Source +
                                "\n when calling Method " + e.TargetSite +
                                "\n \n The following Inner Exception was caused" + e.InnerException +
                                "\n \n The Stack Trace Follows: \n\n" + e.StackTrace );
                        this.Enabled = false;
            }
            //Placing anything outside of this
            //try catch may cause MC to fail to open.
            //Play safe and insert it try area!
        }

        #endregion

    }
}
Now to small but important details:
  • Project must be of type "Class Library".
  • The code for the plugin should be written in a "User Control" (Right-click project --> Add  --> User Control)
  • AssemblyInfos.cs must contain the following attribute:
Code: [Select]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible ( true )]
  • In the project properties under the build tab (Section "Output:")  "Register for COM interop" must be ticked.

I'm not sure about this but somehow I cannot compile a functional .dll with the MediaJukebox.dll created by the tlbimp tool (mentioned in my first post). It only works with the one in Mr ChriZ's template project.

Compiled with Runtime version 1.1.4322
Lib-version : 1.0.0.0
Works with Media Jukebox 12.0.49.
Logged
Pages: [1]   Go Up