INTERACT FORUM

Please login or register.

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

Author Topic: C++ interface Automation question  (Read 4390 times)

scthom

  • Citizen of the Universe
  • *****
  • Posts: 621
C++ interface Automation question
« on: January 12, 2007, 08:52:41 am »

I'm updating the EQdb plugin to use events.  With MC 11 (using "Media Jukebox.tlb"), the following code (C++) worked fine to get the Automation and Mixer interfaces:
Code: [Select]
In CEQdbCtrl.h:
private:
   IMJMixerAutomationPtr m_pMixer;
public:
   IMJAutomationPtr m_pMJ;

In CEQdbCtrl.cpp:
STDMETHODIMP CEQdbCtrl::Init(IDispatch* d) {
   m_pMJ.Attach((IMJAutomation *) d, TRUE);
   m_pMixer = m_pMJ->GetMJMixer();
...
}

Now using MC12's "MediaCenter.tlb", the same code is crashing with a Run-Time Error #0 on the GetMJMixer() function.  The description of this error is that the register ESP is not the same before and after the call, which is usually caused by calling the function with a different calling convention than it was declared as.  I think ESP is used to store the size of the stack.  Before and after the GetMJMixer function, the difference is 4 bytes extra (stack leak).

I've tried compiling with __cdecl, __fastcall, and __stdcall (the old plugin was compiled with __cdecl).  None of which work.  Did something change?  What calling convention is used for the Type Library functions?  Is the passed pointer d not attached correctly (e.g. do I use GetActiveObject instead) ?

I've tried everything I can think of, without success.  Any ideas?
Logged

John Gateley

  • Citizen of the Universe
  • *****
  • Posts: 4957
  • Nice haircut
Re: C++ interface Automation question
« Reply #1 on: January 12, 2007, 09:56:33 am »

Conflict between debugging and release versions?

When I see this error, often a complete rebuild fixes it.

j

MahlerFreak

  • Recent member
  • *
  • Posts: 49
Re: C++ interface Automation question
« Reply #2 on: January 13, 2007, 03:20:56 pm »

I had a similar problem moving from MC11 to MC12. I don't have my source code available to me at the moment, but what I did to solve my problem was to make sure the IMJAutomationPtr passed into Init got an AddRef (I believe by assigning it to the ComPtr rather than attaching it). It seems as though MC12 is Releasing the automation pointer immediately after the Init call.

Try that out, and see if it fixes your problem.

Scott
Logged

MahlerFreak

  • Recent member
  • *
  • Posts: 49
Re: C++ interface Automation question
« Reply #3 on: January 13, 2007, 03:36:37 pm »

I see, by reviewing your post more closely, that your problem is not likely the same as mine ...
Logged

MahlerFreak

  • Recent member
  • *
  • Posts: 49
Re: C++ interface Automation question
« Reply #4 on: January 13, 2007, 06:05:26 pm »

Looking at my own code, the following does work, and will accomplish the same thing you're trying to do:

      IMJZonesAutomationPtr pZonesAuto = m_pAutomation->GetZones();
      IMJZoneAutomationPtr pActZone = pZonesAuto->GetZone(pZonesAuto->GetActiveZone());
      IMJMixerAutomationPtr = pActZone->GetMixer();

This has worked under MC12 builds 130 and 139 so far.

Good luck.
Logged

scthom

  • Citizen of the Universe
  • *****
  • Posts: 621
Re: C++ interface Automation question
« Reply #5 on: January 19, 2007, 09:47:12 pm »

As usual, user error :-)

When I switched over to the version 12 tlb, I thought I needed to use the get_Filename function to get the Filename property, so I used "embedded_idl" on the #import directive.  Of course, you've included the GetFilename function, so once I removed the "embedded_idl" things worked fine.

Naturally I rebuilt the plugin several times and wasted three or four days in the process.
Logged

MahlerFreak

  • Recent member
  • *
  • Posts: 49
Re: C++ interface Automation question
« Reply #6 on: January 19, 2007, 10:49:14 pm »

After 20 years of programming, I've learned that there is no such thing as a "smart mistake"  :)

Programming enforces humility. No matter how convinced you are that you are right, the compiler remains unimpressed
until you follow its rules without exception.

Good that you found your problem.

Logged

scthom

  • Citizen of the Universe
  • *****
  • Posts: 621
Re: C++ interface Automation question
« Reply #7 on: January 20, 2007, 09:01:50 am »

It doesn't help that these plugins are COM and there are so many ways to implement things.  ATL, attributes, C++ Standard Library, events, polling, etc.  As an amateur programmer who's only had a few programming classes, it can be very confusing.  Logic only gets you so far and brute force is my only hammer, and the compiler doesn't appreciate it  ;D.

Thanks for your support!
Logged

scthom

  • Citizen of the Universe
  • *****
  • Posts: 621
Re: C++ interface Automation question
« Reply #8 on: January 20, 2007, 10:56:27 pm »

The new Events are driving me nuts.  I can't figure out how to implement them.

Looks like they're connection points (as opposed to attributed events), and I implement that, but I get compile errors on the sink map entry (I'm not a dialog window??).  Or, if I use DispEventImp (DispEventAdvise) I get no compile errors, but I don't sink any events either.

The SDK is no help since it's timer-based.

Anyone have a good COM/events/ATL reference?  I've looked and found some, but none which have helped.
Logged

MahlerFreak

  • Recent member
  • *
  • Posts: 49
Re: C++ interface Automation question
« Reply #9 on: January 22, 2007, 12:07:02 pm »

OK, I've been curious for a while now - what Events are you referring to? There seem to be no MC docs describing such a thing ...

If there were events fired on, for instance, adding/removing files from the library, those would be quite useful to me.

I'm afraid I can't help you much on COM, this is the first COM or ATL programming I've ever done, and I've only learned enough to be dangerous. There is a fascinating book on ATL called "ATL Internals" which gives a much better understanding on how ATL works under the covers, but it's not a reference per se. The authors of that book recommend "Essential COM", by Don Box, as a guide to COM, but I've not yet purchased or perused it.

If you can point me to some information on MC events, I'll try a couple of experiments myself and we might get something going.

Scott



 
Logged

scthom

  • Citizen of the Universe
  • *****
  • Posts: 621
Re: C++ interface Automation question
« Reply #10 on: January 22, 2007, 06:00:05 pm »

Logged

scthom

  • Citizen of the Universe
  • *****
  • Posts: 621
Re: C++ interface Automation question
« Reply #11 on: February 17, 2007, 08:49:53 pm »

Well, I've managed to get my sink connected to the IMJAutomationEvents source, or at least it returns a valid cookie when I Advise(...) the ConnectionPoint, so I think it's connected  ;D.

But, I'm still not receiving the Event notifications correctly.  Maybe John Gateley can answer this since he seems to be the one who wrote the VB version.

What function will be called by MC in my class?  Does it need to be exposed in the interface or just a public function?  The VC Wizard hasn't made it work even when I use the "Implement Interface" wizard.

According to the Type Library, it looks like I should have a function with the prototype:
Code: [Select]
HRESULT FireMJEvent(BSTR type, BSTR param1, BSTR param2)

But I've done that and nothing is received.  I've also tried void (as generated by the Wizard) and _bstr_t, in all the combinations.  It's a public function, and I even tried exposing it on the interface, all to no avail.  I even tried just MJEvent in case the Fire wasn't needed (similar to Fire_MJEvent ??).  I've compared the functions to those used in the Encoder plugins, but since it's the reverse direction, I can't quite figure it out.

Any help would be appreciated, if anyone has a running MC event handler in C++.
Logged

Craig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 612
Re: C++ interface Automation question
« Reply #12 on: February 18, 2007, 03:07:13 am »

Scott,
I don't know how it compares to C++ but in Delphi I imported the .tlb and it created a MCAutomation component that i just dropped on my form.
This has an event handler that fires off whenever an event is recieved, nothing complicated like you're describing.

Now if only those events contained the correct info I'd be able to make some progress with MC2Slim ;)

Craig
Logged
MC2Slim - Windows Shell and JRiver Media Center Integration for Squeezebox.

http://www.duff-zapp.co.uk

scthom

  • Citizen of the Universe
  • *****
  • Posts: 621
Re: C++ interface Automation question
« Reply #13 on: February 18, 2007, 08:13:11 am »

I don't know how it compares to C++ but in Delphi I imported the .tlb and it created a MCAutomation component that i just dropped on my form.
This has an event handler that fires off whenever an event is recieved, nothing complicated like you're describing.

Yeah, I wish.  C++ is much more complicated to get right.  Importing the .tlb is the easy part  ;D
Logged

Craig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 612
Re: C++ interface Automation question
« Reply #14 on: February 18, 2007, 08:22:56 am »

That must be why real programmers do it in C :)
Logged
MC2Slim - Windows Shell and JRiver Media Center Integration for Squeezebox.

http://www.duff-zapp.co.uk

JohnT

  • Citizen of the Universe
  • *****
  • Posts: 4627
Re: C++ interface Automation question
« Reply #15 on: February 26, 2007, 02:52:06 pm »

Well, I've managed to get my sink connected to the IMJAutomationEvents source, or at least it returns a valid cookie when I Advise(...) the ConnectionPoint, so I think it's connected  ;D.

But, I'm still not receiving the Event notifications correctly. 
I finally posted a Wiki page about MC event handling. There is a section for Visual C++ with MFC. Take a look and let me know if it has sufficient information for you to proceed.
Here's the link:
http://wiki.jrmediacenter.com/index.php/Media_Center_Automation#Event_Handling
Logged
John Thompson, JRiver Media Center

scthom

  • Citizen of the Universe
  • *****
  • Posts: 621
Re: C++ interface Automation question
« Reply #16 on: February 26, 2007, 08:54:47 pm »

That looks like enough info for me.  I'll try it out and let you know...
Logged

Craig

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 612
Re: C++ interface Automation question
« Reply #17 on: February 27, 2007, 08:37:07 am »

I could probably add to that with how to get it running under Delphi.
At the moment I'm not able to make much use of events because of the problems I reported in http://yabb.jriver.com/interact/index.php?topic=38889.0

Hopefully when Scott gets up and running he'll be able to confirm or disprove this.

Thanks
Craig
Logged
MC2Slim - Windows Shell and JRiver Media Center Integration for Squeezebox.

http://www.duff-zapp.co.uk
Pages: [1]   Go Up