INTERACT FORUM

Please login or register.

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

Author Topic: Please help on using c# (.net) for Automation  (Read 8970 times)

tommer

  • Recent member
  • *
  • Posts: 19
Please help on using c# (.net) for Automation
« 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
Logged

esajesa

  • Regular Member
  • Recent member
  • *
  • Posts: 12
  • nothing more to say...
Re: Please help on using c# (.net) for Automation
« Reply #1 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
Logged

cncb

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3106
Re: Please help on using c# (.net) for Automation
« Reply #2 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
Logged
-Craig    MO 4Media remote and player:  Android/TV/Auto | iOS | Windows 10/UWP

tommer

  • Recent member
  • *
  • Posts: 19
Re: Please help on using c# (.net) for Automation
« Reply #3 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...
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Please help on using c# (.net) for Automation
« Reply #4 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?

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Out Of Proc Broken? Media Center.Exe from Media~1.exe
« Reply #5 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..

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Out of proc broken
« Reply #6 on: January 24, 2006, 10:40:36 am »

Just done some C++ Tests.
If I do CreateObject then GetActiveObject works...
otherwise it doesn't.

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Out of Proc Broken?
« Reply #7 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"  :)

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Out of Proc Broken?
« Reply #8 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.
Pages: [1]   Go Up