INTERACT FORUM

Please login or register.

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

Author Topic: Releasing C# Com Handle or How to Properly Create and use a Handle to Begin With  (Read 3342 times)

LoliChan

  • Member
  • *
  • Posts: 4

So I'm now in the middle of trying to develop my second J River media center plugin type application.

I gave up on the first one after coming across this problem, and now that it's been about 6 months and I feel that I've more than scoured all the scattered bits and pieces of documentation that I could find, I figure I might as well ask for help as to how to actually use this library properly.


So my general purpose is to grab a handle to the COM library
Gather some currently playing song information
Release the COM handle
and go about my merry way

so I've been going about this like so
First I add the MediaCenter itl in the Media Center install director to my references
then
Code: [Select]
MediaCenter.MCAutomation mcAuto = new MCAutomation();
MediaCenter.IMJFileAutomation mcFileInfo = null;

//lots of null checks and stuff
if (mediaCenterAutomation.GetPlayback().State == MJPlaybackStates.PLAYSTATE_PLAYING)
{
    if (mediaCenterAutomation.GetCurPlaylist() != null && mediaCenterAutomation.GetPlayback() != null)
    {
        mcFileInfo = mediaCenterAutomation.GetCurPlaylist().GetFile(mediaCenterAutomation.GetCurPlaylist().Position);
        if (mcFileInfo != null)
        {
            String song = mcFileInfo.Name;
            //got what I wanted
        }
    }
}

which all works out fine until I stop my application (usually for debugging purposes)
and then when I start the next application and go to do something I will get to here
Code: [Select]
MediaCenter.MCAutomation mcAuto = new MCAutomation();

and then I will get something like this
Quote
Retrieving the COM class factory for component with CLSID {572802D5-FBF6-4C30-89CA-BDF2CE4AEC2B} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

At first I assumed it was because I failed to release the COM handle but no matter how many attempts I make to close I still get the error
Googling has led me to believe it has something to me registering my plugin in the registry

I remember the wiki saying something about this
Quote
It must enter information in the registry to let Media Center know it exists. In C++, this can simply be a block of code added to the DllRegisterServer function. In VB, you will have to make a .reg file for the user to run on their machine. (see the included samples for examples of this)
But it doesn't give any details
there are no C# examples
not even a VB example
and I looked at the C++ Example but I don't understand what CLSID
is being used here
Quote
LPWSTR strID; StringFromCLSID(CLSID_SleepTimerCtrl, &strID);

I feel like I'm close but I can't figure it out... Can someone please help me out here?
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 71382
  • Where did I put my teeth?

I can't answer your question, but did you consider using MCWS (on the Devzone page) instead of Com?
Logged

LoliChan

  • Member
  • *
  • Posts: 4

I can't answer your question, but did you consider using MCWS (on the Devzone page) instead of Com?

No, because I have a need to monitor anything remotely
I don't see any need to go out of my way to get the web service working when this is suppose to be what the com library is for

on top of that I already have a local web server bound to port 80
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41941
  • Shoes gone again!

You may need to find the existing instance instead of create a new instance every time.  Look at the first C++ example here:
http://wiki.jriver.com/index.php/Media_Center_Automation

However, I'll echo Jim's suggestion to build against MCWS if possible.  It runs on any port (52199 by default), supports remote access, works cross-platform, works nicely with any language, and is actively supported and improved.
Logged
Matt Ashland, JRiver Media Center

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608

I didn't see this before, but I have a C# wrapper class for MC that is mostly-complete.

If you'd like a copy, PM me.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/
Pages: [1]   Go Up