INTERACT FORUM

Windows => Plug-in Development => Topic started by: tommer on December 09, 2005, 01:00:52 am

Title: Please help on using c# (.net) for Automation
Post by: tommer on December 09, 2005, 01:00:52 am

Reference is made to this post: http://yabb.jriver.com/interact/index.php?topic=28732.0

I've implemented the following code:

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MediaJukebox;

namespace WindowsApplication1
{
    public partial class fStart : Form
    {
        public fStart()
        {
            InitializeComponent();
         
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MJAutomation aut = null;
       
            aut = (MJAutomation)System.Runtime.InteropServices.Marshal.GetActiveObject("MediaJukebox Application");


           
            MJPlaylistsAutomation playlists = aut.GetPlaylists();

            for (int i = 0; i < playlists.GetNumberPlaylists(); i++)
            {
                MJPlaylistAutomation playlist = playlists.GetPlaylist(i);
                listBox1.Items.Add(playlist.Name);
               
            }
        }
    }
}

However, I'm receiving the following error message:


System.Runtime.InteropServices.COMException (0x800401E3): Operation unavailable. (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
   at System.Runtime.InteropServices.Marshal.GetActiveObject(Guid& rclsid, IntPtr reserved, Object& ppunk)
   at System.Runtime.InteropServices.Marshal.GetActiveObject(String progID)
   at WindowsApplication2.Form1.button1_Click(Object sender, EventArgs e) in C:\...



Anybody knows what I'm doing wrong??

Or, anybody has a working c# automation program???

Regards
Tom
Title: Re: Please help on using c# (.net) for Automation
Post by: esajesa on December 09, 2005, 08:28:43 am
Hey,

well I'm no C# mastermind exactly, only played with VC# Express a bit, but I'd try to change a these lines:

Code: [Select]
MJAutomation aut = null;
       
aut = (MJAutomation)System.Runtime.InteropServices.Marshal.GetActiveObject("MediaJukebox Application");

to:

Code: [Select]
IMJAutomation aut = null;
Object = obj;
obj = aut.GetActiveObject("MediaJukebox Application");

Hope it helps...

Cheers,
Jens
Title: Re: Please help on using c# (.net) for Automation
Post by: cncb on December 09, 2005, 12:47:58 pm
GetActiveObject() will only succeed if Media Center is running.  See this thread for how to handle both cases:

http://yabb.jriver.com/interact/index.php?topic=27357.0
Title: Re: Please help on using c# (.net) for Automation
Post by: tommer on December 11, 2005, 03:17:29 pm
Seems like I'm having a problem with ActiveX registration  :(

Anyhow, I changed to VB.NET, seems like C# is a little bit to complicated for me...
Title: Re: Please help on using c# (.net) for Automation
Post by: Mr ChriZ on January 24, 2006, 07:26:49 am
 :-\

Snap.
Theres loads of people in the past that seem to have got this to
work, but it doesn't seem to work now?
I'm wondering is something broken or am I doing something stupid?
Are there any other plugins that use this that I can test with?
Title: Out Of Proc Broken? Media Center.Exe from Media~1.exe
Post by: Mr ChriZ on January 24, 2006, 08:13:47 am
I think it is broken.
Looking in the registry, when the task name was changed to Media Center.Exe from Media~1.exe it
wasn't updated for out of proc.

Additional Note...
Actually not sure this is the cause of the problem..
Title: Re: Out of proc broken
Post by: Mr ChriZ on January 24, 2006, 10:40:36 am
Just done some C++ Tests.
If I do CreateObject then GetActiveObject works...
otherwise it doesn't.

Title: Re: Out of Proc Broken?
Post by: Mr ChriZ on February 10, 2006, 03:36:45 pm
*Bump*

It would be really good to get this working, because it would mean that C#
Scripts could be set up to run from the command line.

A "yeh it's broken, we'll fix it sometime,
or a it's working fine:- learn to code would do"  :)
Title: Re: Out of Proc Broken?
Post by: Mr ChriZ on February 13, 2006, 08:16:35 pm
Does MC11.exe use out of proc disproving my theory?



ChriZ

Additonal Note:
Nope. MC11.exe still works whether the CLSID is there or not.