Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I need to code a simple program in C++ that reacts to itunes triggered events, such as "the user pressed play".

Following a few examples i managed to get itunes listening to events. However, I do not know how to do this:
-Be in "waiting" mode until an event triggered...
-When an event is triggered, just do "whatever".
-Once "whatever" is finished, go back to "waiting" mode to wait for new events...

Right now, if I connect to the event handler as follows, the program exits before I can trigger any event from itunes:
C++
//main
IConnectionPointContainer* icpc;
IConnectionPoint* icp;
CiTunesEventHandler* eventHandler;
DWORD dwAdvise;
 
eventHandler = new CiTunesEventHandler();
piTunes->QueryInterface(IID_IConnectionPointContainer, (void **)&icpc);
icpc->FindConnectionPoint(DIID__IiTunesEvents, &icp);
icpc->Release();
icp->Advise(eventHandler,&dwAdvise);
icp->Release();
//end main

//example got from the discussion of this CODE project: Controlling iTunes through COM


If I tried this infinite loop:
for(;;)
icp->Advise(eventHandler,&dwAdvise);

it works until the first event is triggered, and then it goes mad, blocks itunes and keeps triggering the same event again and again...

Any ideas of how to constantly wait for new events without exiting the program or blocking everything???

Thanks a lot for your help!!!!
pj
Posted
Updated 2-Jul-12 6:38am
v2
Comments
[no name] 2-Jul-12 12:45pm    
If this is a console application, which is appears to be, I think that you would have to implement some sort of message pump.
pardillojuegos 2-Jul-12 13:55pm    
Thanks for your reply Wes Aday!

Please tell me in case I did not understand. The message pump, is that not what the for(;;) do?

The intention of that line was looping until there is an event. It works well until the first event. The problem is that after the first event is triggered, it keeps triggerring the same event infinitely

Thanks!

The Advise function looks like this in case it helps:

HRESULT STDMETHODCALLTYPE CiTunesEventHandler::Invoke(DISPID dispidMember, REFIID, LCID,WORD, DISPPARAMS* pdispparams, VARIANT*,EXCEPINFO*, UINT*){

cout<< dispidMember<<endl;

switch (dispidMember)
{
case 2:
//there was an onplayer event

break;
default: break;
}

return S_OK;
}
Code-o-mat 3-Jul-12 14:28pm    
What happens if you just do a Sleep(INFINITE); after using Advise once (so not in a loop)?
pardillojuegos 4-Jul-12 4:44am    
Thanks for your help Code-o-mat !

I tried to do what you were suggesting but unfortunately it didn't work. I guess it went to sleep before the first event was triggered and then it could not listen to the events from itunes

Thanks a lot!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900