INTERACT FORUM
Windows => Plug-in Development => Topic started by: JeffreyK on September 21, 2003, 07:18:21 am
-
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
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;
}
-
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
-
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
-
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
-
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
-
Ignore my previous message. We found a bug in our code which prevents the automation to be initialized second time.
The fixed will be available in the next build.
Thanks,
Nikolay
-
Thanks!
-JeffreyK
-
Where is the documentation for using the out of process automation/object?
-
mjcumming,
The code sample in JeffreyK's post that started this thread shows how to instantiate an Automation object out of process.
Once you have that, the methods, objects, & properties that you can use are documented here:
http://www.musicex.com/mediacenter/devzone.html
Follow the first link, "Media Center automation"
-- Soundman
-
Okay thanks, so there is no real advantage over using MCIO. I thought maybe the API had been updated or improved.
-
mjcumming,
No, there is no advantage over MCIO as of now. In fact, in this thread:
http://www.musicex.com/cgi-bin/yabb/YaBB.cgi?board=dev;action=display;num=1061819687
I pointed out that MCIO is actually faster (by a facter of 2X) than using Media Center Automation directly. This is very counterintuitive, and Nikolay said that he will look into the performance issue.
As for the API, I have been begging for the API to be improved for some time now, as have some others. I think JRiver will get to it eventually. In the meantime, my HTPC project is kinda stuck.
Good Luck,
Soundman