INTERACT FORUM

Please login or register.

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

Author Topic: Trouble getting Automation Object.  (Read 2717 times)

RedDom

  • Recent member
  • *
  • Posts: 20
Trouble getting Automation Object.
« on: March 07, 2005, 07:18:20 am »

I have written a plugin for getting jrmc current track and playback info, and displaying this via an LCDSmartie plugin.  But I have 1 major issue.  Its been mentioned ion a couple of other threads, but no soloutions proposed.

The issue is that when Mediacenter is started up normally.  My plugin is unable to access the activeX object (I get the 429 error)
This is using the VB code from the sdk sample.

mcInst = GetObject(, "MediaJukebox Application")

If however I start the application from a seperate program that does nothing more than CreateObject and then i stop that program (but leave MediaCenter running)

Set mcInst = CreateObject("MediaJukebox Application")

then after that I can successfully get the object from my lcd plugin. 
It seems there is some differentce between starting MC from another COM app than starting from the startup menu, or using netremote.

Any help would be much appreciated
Logged

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20063
Re: Trouble getting Automation Object.
« Reply #1 on: March 07, 2005, 12:25:55 pm »

ya i know

Never had much luck with that sample

when you terminate mc and it is in the plug-in it will crash

this however works fine

Public Function Init(ByVal MediaJukebox As Object) As Variant
    On Error Resume Next
    Set mcInst = MediaJukebox
End Function


Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio, Music
https://MyAAGrapevines.com
https://centercitybbs.com
Fayetteville, NC, USA

RedDom

  • Recent member
  • *
  • Posts: 20
Re: Trouble getting Automation Object.
« Reply #2 on: March 07, 2005, 02:48:48 pm »

Thanks for the help,
however I'm not actually writing a 'plugin' I'm just trying to get a handle on jrmc, so i can get the nowplaying info in LCD smartie using an out of process dll that is a smartie plugin.  I think the sample is the only way to access jrmc from outside.
 
I think the sample code you have is a way to get a handle from inside MC.  I suppose i could do it the other way and have a jrmc plugin call out to a custom  smartie plugin, but thats probably going to add awhole level of complexity that is probably beyond me at the moment.

RD
Logged

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20063
Re: Trouble getting Automation Object.
« Reply #3 on: March 07, 2005, 05:59:15 pm »

I C

well try this sample below

Note the sample in the SDK is not written correctly see below

add the "on error resume next" this should allow the program to continue on the 429 error and hit the if then (that is missing the endif statement in the sdk sample)

Private Sub Form_Load()
'
On Error Resume Next ' <-----<<< Add This Line
    '
    ' First try to get an already running object '
    Set myobj = GetObject(, "MediaJukebox Application")
    If Err.Number = 429 Then
    ' on error, create a new object '
        Set myobj = CreateObject("MediaJukebox Application")
    '
    End If  ' <-----<<< Add This Line
    '
End Sub

i have never created an out of proc program so not sure how it will work even more so since this was written many versions ago, not sure if it still works with media center 11
Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio, Music
https://MyAAGrapevines.com
https://centercitybbs.com
Fayetteville, NC, USA

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20063
Re: Trouble getting Automation Object.
« Reply #4 on: March 07, 2005, 06:25:46 pm »

i just played with it, below works (at least it pulls up media center after that i am not sure)

this is the full project code that will pull up media center as out of proc

RhinoBanga knows more about this and has posted some messages in this forum about out of proc, not sure he is even around, he does have a support forum for his playing now plug-in

Quote
Dim myobj As Object
Option Explicit

Private Sub Form_Load()
 On Error Resume Next
 ' First try to get an already running object '
' Dim myobj As Object
 Set myobj = GetObject(, "MediaJukebox Application")
 If Err.Number = 429 Then
    ' Then, create a new object '
    Set myobj = CreateObject("MediaJukebox Application")
 End If

End Sub
Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio, Music
https://MyAAGrapevines.com
https://centercitybbs.com
Fayetteville, NC, USA

RedDom

  • Recent member
  • *
  • Posts: 20
Re: Trouble getting Automation Object.
« Reply #5 on: March 08, 2005, 03:59:38 am »

The code you post shows the same issue that I have (Except you cant see it cos the on error stuff).
If i run through the code the first time, it creates the media center app, as it doesn't exist  the first time.
If i the run the code again, it works (Because the original media center was opened using the vb app).
however most users wont do this, i need my app to talk to an existing instance of mediacenter.

If i start mediacenter by hand, then run the code it fails to find an instance and errors through to creating a new instance, which also fails.  and so the app then wont continue.

FYI, I'm using MC 11. 201, but i get same behaviour on MC10
It seems to me that media center isn't correctly registered in the windows AppROT, hence it cant be found by getObject.  When VB creates an instance it registers it automatically, so it can then be used agaion.

RD
Logged

RhinoBanga

  • Citizen of the Universe
  • *****
  • Posts: 1703
  • Developer
Re: Trouble getting Automation Object.
« Reply #6 on: March 08, 2005, 11:42:08 am »

Maybe I am not understanding the problem but when I tried this with and without an existing MC running it hooked to it perfectly fine:

Code: [Select]
Option Explicit

Private Sub Form_Load()

    On Error Resume Next
   
    '  Instanciate or hook to existing MC
    Dim myMJ As MediaJukebox.MJAutomation
    Set myMJ = GetObject(, "MediaJukebox Application")
    If myMJ Is Nothing Then
        Set myMJ = CreateObject("MediaJukebox Application")
    End If
   
    '  Get what's playing
    Dim myCurrentFile As MediaJukebox.MJFileAutomation
    Set myCurrentFile = myMJ.GetCurPlaylist.GetFile(myMJ.GetCurPlaylist.Position)
   
    '  Display
    MsgBox myCurrentFile.FileName
   
    '  Release
    Set myCurrentFile = Nothing
    Set myMJ = Nothing
   
End Sub


Only one instance of MC was ever running.

Am I missing something?
Logged

RedDom

  • Recent member
  • *
  • Posts: 20
Re: Trouble getting Automation Object.
« Reply #7 on: March 08, 2005, 04:26:13 pm »

Your code doesn't work for me, but its hard to spot.

If you do the following you will see it.

first endall instances of mediacentre process in task manager.

Then start mediacentre using the start menu.
Then start your project, and step through the code.  You will see that 'GetObject' fails, and it falls into the createobject process.  This works (And also means that all future getObjects will work with this instance of mediacenter)

Basically with your code and mine, getobject never works with a brand new instance of mediacenter that hasn't had a creatobject called in vb. Once create object is called all subsequent getobjects will work.

I could just use createobject, and i probably will, but the side effect is that it will be impossible to close jrmc, as if the lcd is on it will then start it again, which isn't a problem for me as its a music server but may be for some.  I'm still convinced that there is a bug in MC and its not in the ROT.

thx for looking at this

RD

Logged

RhinoBanga

  • Citizen of the Universe
  • *****
  • Posts: 1703
  • Developer
Re: Trouble getting Automation Object.
« Reply #8 on: March 09, 2005, 01:03:31 am »

Hi,

If you think there is a problem post a bug report in the main forum but I would never expect to be able to close an external instance of MC, for example:

1)   I have fired up MC to listen to my favourite tunes
2)   I then run an application which hooks into the existing MC to get playing now
3)   The application exits and terminates MC
4)   I sit and wonder why my music has stopped playing.


However if this is what you want try sending the WM_CLOSE message to the MC process.


I suspect there is one problem though in that when I released all the MC objects, after creating the MC instance via CreateObject, the process did not terminate.
Logged

RedDom

  • Recent member
  • *
  • Posts: 20
Re: Trouble getting Automation Object.
« Reply #9 on: March 09, 2005, 02:39:23 am »

sorry I'm not being very clear.  The problem with using create object, instead of getobject, is that if there is no current instance of medicenter, my application will end up creating a new one.

My app doesn't want to close it, but if the user closes it manually, then my application will just create a new instance, as a side effect of using create object.  This means that the user can never close it as it will keep coming back.  ACtually you are right, if the user closes it it never goes away anyway, and the process remains.
I am still interested if GetObject works for you, on a completely new instance started by hand (Not started by createobject, or left over as an unterminated process from before)..

thx
RD
Logged

RhinoBanga

  • Citizen of the Universe
  • *****
  • Posts: 1703
  • Developer
Re: Trouble getting Automation Object.
« Reply #10 on: March 09, 2005, 05:20:01 am »

Quote
My app doesn't want to close it, but if the user closes it manually, then my application will just create a new instance, as a side effect of using create object

In that case use FindWindow to see if there is an existing MC, and if so then call CreateObject.

Quote
I am still interested if GetObject works for you, on a completely new instance started by hand

No but I am not convinced it makes a difference however that's why I said:

Quote
If you think there is a problem post a bug report in the main forum

Logged

BigDogues

  • Recent member
  • *
  • Posts: 15
Re: Trouble getting Automation Object.
« Reply #11 on: April 12, 2005, 05:54:47 pm »

May I say what a cool idea for a plug-in! 8) Is there any further progress on this front?
Thanks,
Phil 
Logged
Pages: [1]   Go Up