INTERACT FORUM

Please login or register.

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

Author Topic: Intercept events in C++ (ATL but idealy Qt) plugin  (Read 6147 times)

neFAST

  • Galactic Citizen
  • ****
  • Posts: 372
  • \o/
Intercept events in C++ (ATL but idealy Qt) plugin
« on: July 24, 2011, 04:22:02 pm »

Hi folks, I'm working on a plugin this time in C++.
My previous plugin was in C# from M. Chriz templates and events were working like a charm.
But now I'm trying to write something using Qt and C++.

At first I tried to connect the FireEvent signal with a QAxObject from Qt, but I gave up.
I restarted a project from scratch with ATL only, and I still fail at intercepting events.
I have read http://wiki.jriver.com/index.php/Media_Center_Automation#Event_Handling 100 times but when tring
Code: [Select]
   BEGIN_SINK_MAP(Bridge)
        SINK_ENTRY_EX(1, DIID_IMJAutomationEvents, 1, handleJRMCEvent)
    END_SINK_MAP()
I get this error:
Code: [Select]
error C2440: 'static_cast' : cannot convert from '_atl_event_classtype *' to 'ATL::_IDispEventLocator<nID,piid> *
What is wrong with my code?

Thanks a lot for your help with ATL guys (and if you have a solution that works with Qt it would be even better)
Logged

neFAST

  • Galactic Citizen
  • ****
  • Posts: 372
  • \o/
Re: Intercept events in C++ (ATL but idealy Qt) plugin
« Reply #1 on: July 25, 2011, 05:42:57 am »

Finally found the way to do it thanks to Qt tool "dumpdoc.exe"
Logged

neFAST

  • Galactic Citizen
  • ****
  • Posts: 372
  • \o/
Re: Intercept events in C++ (ATL but idealy Qt) plugin
« Reply #2 on: July 27, 2011, 01:32:19 pm »

I removed the SOLVED tag in my thread since I have an issue.
If I call Play() on a PlaybackAutomationPtr from my plugin, it works correctly ...
... except if I call it from the function that is hooked to windows events.
In that specific case, the Play() call never returns: if I add a breakpoint to the next line of code, it is never reached!

Does Play() triggers an event that could be caught and wrongly handled by my event hook?

Thanks a lot for your help guys!
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42372
  • Shoes gone again!
Re: Intercept events in C++ (ATL but idealy Qt) plugin
« Reply #3 on: July 27, 2011, 01:45:28 pm »

Using PlaybackAutomationPtr from a worker thread could cause trouble, because internally it sends messages to the player window.  Especially if the handling of these messages fires an event that tries to re-enter your event handler.

Instead, I would recommend posting MCC messages to the player if you're in a worker thread.

For example:
PostMessage(MJ.GetWindowHandle(), WM_MC_COMMAND, MCC_PLAY_CPLDB_INDEX, -1);
Logged
Matt Ashland, JRiver Media Center

neFAST

  • Galactic Citizen
  • ****
  • Posts: 372
  • \o/
Re: Intercept events in C++ (ATL but idealy Qt) plugin
« Reply #4 on: July 27, 2011, 02:15:34 pm »

Thanks for the tips. I'm not really used to working with events.
I double checked that my event hook is running in the main thread.
I have something working now.

Is there a way to detect :
 - MC is closing?
 - current track rating changed?
 - current track lyrics changed?
 - current track cover changed?

If I ask for the current track cover thumbnail (GetImageFile(IMAGEFILE_THUMBNAIL_MEDIUM) I guess that MC cleans up thumbnails once in a while, is it possible that the path becomes quickly invalid?

Thanks for your help Matt

EDIT: I thought I had something working but its wrong. Within my eventhandler I need to get MC current track position and return this as the result of the event. Can I do this with a PostMessage?
Logged
Pages: [1]   Go Up