Windows > Plug-in Development

Issue with MC Automation (out-of-proc)

(1/3) > >>

JeffreyK:
I'm trying to use the new out of proc automation of MC in a program I am writing, but am running into a small problem.

If MediaCenter is NOT running, my program runs fine (MediaCenter launches and then exits when my program exits) and I can run it a second time with no problems.  

If MediaCenter IS running, my program works fine the first time, but when run a second time, MC is made the active app and, after a few seconds, my program errors out due to the CreateInstance call failing.

Any thoughts?  The code I am using is below.  Build is 252 and I'm on WinXP.

Thanks!
-Jeff


--- Code: ---CoInitialize(NULL);
IMJAutomationPtr mj;
HRESULT hr = mj.GetActiveObject(L"MediaJukebox Application");
if (hr == S_OK)
   mj.AddRef();
else
   mj.CreateInstance("MediaJukebox Application");

if (mj == NULL)
{
   printf("Failed to create MediaJukebox object!\n");
   return 1;
}

IMJCurPlaylistAutomationPtr pMJCurPlaylist = mj->GetCurPlaylist();

if (pMJCurPlaylist == NULL)
{
   printf("Failed to get CurPlaylistAutomation object!\n");
   return 1;
}

if (pMJCurPlaylist->GetNumberFiles() == 0)
{
   printf("No files in Now Playing.\n");
   return 1;
}

int iFile = pMJCurPlaylist->GetPosition();
IMJFileAutomationPtr pMJCurFile = pMJCurPlaylist->GetFile(iFile);

if (pMJCurFile == NULL)
{
   printf("Failed to get the current file object!\n");
   return 1;
}

--- End code ---

JeffreyK:
Hmm - I was doing more debugging on this and it stopped happening.  Now everything works fine (with no code changes in my program).

I'll keep playing with it and if I can get it to happen again, I'll try to figure out more information about what might be causing it.

-Jeff

JeffreyK:
Ok - one issue that I'd like someone on the MC dev team to look into is the AddRef after a successful GetActiveObject.  I seem to remember (and some quick browsing of MSDN doesn't show me anything to discount this) that GetActiveObject already returns a refcounted object.

That AddRef, however, I don't think is the cause of my problem (which has returned).

A little more debugging shows that when the problem happens, the call to GetActiveObject (which should succeed since MC is already running) returns:
   hr = 0x800401e3 "Operation unavailable"
Then the CreateInstance call works.  The second run of the program, the GetActiveObject fails again in the same way, but this time the CreateInstance call also fails.

This happens even if MC was just launched.  (I am not sure what caused the GetActiveObject to start working on my machine for a bit, but when I tried to exit MC after it was working, MC just hung, so something was in a weird state.)

Any thoughts?
Thanks!
-Jeff

JeffreyK:
No one has any thoughts on this?

I've tried it on a second computer (running .256) with the same problems.

Here is a small test file that I've built so that others can try it (it is basically the sample code from the devzone page with printf statements in it to help debug):
http://home.comcast.net/~jeffrey.krauss/test/test.cpp
http://home.comcast.net/~jeffrey.krauss/test/test.exe

If you run it when MC is not running, it should result in:
GetActiveObject failed, hr = 800401e3
CreateInstance succeeded

If you then launch MC and run the program twice, you should get:
GetActiveObject failed, hr = 800401e3
CreateInstance succeeded

GetActiveObject failed, hr = 800401e3
CreateInstance failed

Can other folks at least try this out to see if you get the same result?

Thanks!
-JeffreyK

Nikolay:
JeffreyK,

Sorry about confusion, but AddRef call is not neccessary with new builds of Media Center.

Take a look a new version of MJAutomation documentation to see the new way.

Nikolay

Navigation

[0] Message Index

[#] Next page

Go to full version