INTERACT FORUM

Please login or register.

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

Author Topic: C#: Out-of-Proc Initialization Best Practice?  (Read 1784 times)

Quixote

  • Regular Member
  • World Citizen
  • ***
  • Posts: 158
  • Change this by choosing profile
C#: Out-of-Proc Initialization Best Practice?
« on: December 14, 2006, 12:54:35 am »

What's the latest on code that works in C# for the Out-of-Process initialization of Media Center 12?
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: C#: Out-of-Proc Initialization Best Practice?
« Reply #1 on: December 14, 2006, 02:26:05 pm »

OK I've just run a modified version of the template C# Script, as seen below, using MC12.
From what I can see the Media Center Object now get's placed in the ROT
from start up  :)
Which means you just need to use GetActiveObject to get a hold of it.
Maybe JRiver could confirm this for us?
In any case the following style of code ensures compatability with MC11 even if it isn't pretty.

using System;
using System.Windows.Forms;
//css_reference MediaCenter.dll;

class Script
{
   static public void Init(object unused, object textBoxReference)
   {                                                                                               
       System.Windows.Forms.TextBox outputTextbox = (System.Windows.Forms.TextBox)textBoxReference;
       MediaJukebox.MJAutomation mediaCenterInterface=null;
       try
       {
           mediaCenterInterface = new MediaJukebox.MJAutomation();
           outputTextbox.AppendText("\r\nCreated Object in ROT");
       }                                               
       catch       
       {                                             
           try
           {
               mediaCenterInterface = (MediaJukebox.MJAutomation) System.Runtime.InteropServices.Marshal.GetActiveObject("MediaJukebox Application");
               outputTextbox.AppendText("\r\nObject already in ROT continuing with recieved reference");
           }
           catch
           {
               outputTextbox.AppendText("\r\nSomethings Gone Horribly Wrong!");
           }
       }                
                                                   
        if ( mediaCenterInterface != null )
        {
          //Show a Sample Message Box Proving we are running!
          MessageBox.Show("I am a Running Script!");
   
          //Set the Volume Of Media Center!
          MediaJukebox.MJMixerAutomation MCMixer;
          MCMixer = mediaCenterInterface.GetMJMixer();
          MCMixer.Volume = 80;   
       }
   }
}
Pages: [1]   Go Up