Click here to Skip to main content
Click here to Skip to main content

Controlling iTunes through COM

By , 14 Jul 2004
 

Introduction

Apple's iTunes is a powerful audio library manager and player now available for both Windows and Mac. Its feature set is endless and expanding, and, thankfully, through COM, third-party developers can access a good portion of this, even through the .NET Framework and its interop capabilities.

I have built a simple demo application to demonstrate a variety of the features that are available using the iTunes COM interface. This application, by no means, represents the full power of the interface, but is designed to show the different capabilities. Apple's developer web site has an SDK for the complete COM interface.

My application is a system tray utility for controlling iTunes easily and displaying the currently play track. It calls methods, changes properties, and receives events all through COM. It implements the basic functionality of playing, pausing, stopping and changing the currently playing track as well as popping up a window when the track changes.

Instantiating the iTunes Application

In order to access the features that iTunes has to offer, you must first add a reference to the iTunes COM Library to your project. Right click on your project in the Solution Explorer, choose "Add Reference...". Select the COM tab and find the "iTunes 1.1 Type Library", click "Select" and finally click "OK". You will now see "iTunesLib" under your References list for that project.

Next, in any files that you want to communicate with iTunes in, add the following directive:

using iTunesLib;

In order to control iTunes you must create a new instance if the controlling interface. This interface allows your program to communicate with and control (and be controlled by) and already open instance of iTunes.

private myiTunes = new iTunesAppClass();

Using this myiTunes member, you can access functions like Play(), Pause(), Stop(), and Quit(). If for some reason iTunes is closed and your application continues to try and communicate with it, a COMException will be thrown.

Receiving Events from iTunes

The myiTunes member also allows access to certain events like when a new track starts playing, when the current one stops, etc. To specify a new event handler for one of these events, iTunesLib uses the same delegate model that all other events in C# use:

// Add Event Handler
myiTunes.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(
    myiTunes_OnPlayerPlayEvent);

// Event Handler
protected void myiTunes_OnPlayerPlayEvent(object iTrack)
{
...
}

The iTrack parameter provides information about the currently playing track, but in order to get at this information, we must first cast the iTrack into an IITTrack variable.

string myArtist, myName;

IITTrack myTrack = (IITTrack) iTrack;
myArtist = myTrack.Artist;
myName = myTrack.Name;

This is by no means all of the information available in the IITTrack interface. More information is available in Apple's documentation.

Conclusion

I hope that I have merely whetted you appetite in terms of what can be done with controlling Apple's powerful audio application, iTunes. The possibilities are endless: you can batch convert your media to a different format, organize and manage playlists, and batch rename tracks, among other things. Consult Apple's SDK for more information. It is vague in terms of examples, however it contains information about all of the interfaces, what they do, and what members and functions are accessible through each.

Furthermore, I hope I have introduced you to the idea of COM (component object module) and its potentials within your own work. Whether utilizing other COM components functionality or creating your own COM components, I think you will find that it can be endlessly useful, under the right circumstances.

System Requirements

This software is known to work with the following configuration:

  • Microsoft Windows XP SP1 or later
  • Microsoft .NET Framework 1.1
  • Apple iTunes 4.6

The software may possibly work under different configurations, but this has not be verified to date.

Known Issues

  • AnimateWindow WinAPI function does not work properly for fading in the popup display.
  • Popup window timer does not reset when track is changed while popup is showing.

History

  • 07/14/2004 - Article Released

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Adam Durity
Web Developer
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow Do I Search The Itune Library?membercworkman2972922 Jul '09 - 19:55 
im tryin to make an app that automatically adds new tracks to the library how do i search the current library to determin if the newly copied song already exists? Confused | :confused:
Generalstreaming track from iPod to PCmemberHalid Niyaz23 Aug '06 - 5:29 
Hi all,
Assume that a track that is in iPod is not in iTunes library(not in local machine also). Am using iTunes SDK to write my own app for streaming a track from iPod to PC. iTunes SDK provides API to play it directly thru iTunes. But can anyone tell me if iTunes is locally storing it somewhere while playing a track from iPod or does iTunes SDK exposes any API to do this? can I convert a track that is in iPod, say in protected AAC format to mp3 using iTunes SDK?
 

 
Halid Niyaz
GeneralPopup window timer does not reset when track is changed while popup is showing.memberzelig26 May '06 - 6:49 
It seems that the System.Windows.Forms.Timer doesn't work correctly if the form's not visible, but using a System.Timers timer fixes this issue....
GeneralEvent handlingmemberdark_omen23 Mar '06 - 13:43 
I tried using the eventhamdler and it didnt work. I was trying to update a label, like in the example, using pretty much the same code.
This is what I used to set up the EventHandler
iApp.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(iApp_OnPlayerPlayEvent);
 
then this is the eventhandler i used:
private void iApp_OnPlayerPlayEvent(object iTrack)
{
songTitle = ((IITTrack)iTrack).Name;
songArtist = ((IITTrack)iTrack).Artist;
songAlbum = ((IITTrack)iTrack).Album;
SongName.Text = songTitle;
TrackArtist.Text = songArtist;
TrackAlbum.Text = songAlbum;
this.Refresh();
}
 
But when the song changes it doesn't update the information. Does anybody have a solution?
Thanks
AnswerRe: Event handlingmemberndphuong16 Sep '06 - 21:08 
I got same problem as you. And I find following way work.
 
iTunesAppClass myitunes = new iTunesAppClass();
 
...
 
void myitunes_OnPlayerPlayEvent(object iTrack)
{
IITTrack myTrack = myitunes.CurrentTrack;
txtArtist.Text = myTrack.Artist;
txtSong.Text = myTrack.Name;
}
AnswerRe: Event handlingmemberChiser9910 Nov '06 - 12:02 
Not sure why, but calling code directly from the event handlers doesnt work, (i think it has something to do with the thread its being called from), but an easy way to make it work is to use the Form.Invoke() method to call another method to do the updating.
 

 
delegate void Router(object arg);
 
iTunes.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(
delegate(object o){
this.Invoke(new Router(iTunes_OnPlayerPlayEvent), o);
});
 
void iTunes_OnPlayerPlayEvent(object iTrack)
{
MessageBox.Show("Player Event!");
}

GeneralUsing with .NET 2.0 FrameworkmemberShawn McCartt23 Jan '06 - 14:31 
In order to get the Title/Artist update working correctly with VS 2005 and the .NET 2.0 Framework, I found I needed to add a line to the iTunesTray constuctor:
 
Label.CheckForIllegalCrossThreadCalls = false;
 
to prevent this new check from blocking the label text update. Just an FYI to anyone else seeing this problem.
GeneralNot workingmemberLudo de la Pena10 Mar '06 - 8:15 
I've tried adding that line of code on the constructor, but the events are still unhandled.
 
Did you come up with a solution for this problem?
 
I also tried
Control.CheckForIllegalCrossThreadCalls = false;
but it doesn't work either...
 

GeneralRe: Not working ?memberLudo de la Pena10 Mar '06 - 8:44 
Uhmm... looks that your solutionn is goo enought.
Just make sure to use
Control.CheckForIllegalCrossThreadCalls = false;
for a more general solution.
 
I'm not quite sure, but I think the problem with events not handled is previous threads connected to iTunes Application that didn't close properly. This happens numerous times during development, and thus, iTunes won't fire any event to new instances of our application.
 
Does this make any sense at all?
Hope it helps...

GeneralManaging multiple invocations of the COM interopmemberDrew Noakes21 Jan '06 - 10:58 
I'm playing with the iTunes COM API via interop with some success. However, my app only works once per iTunes-process-lifetime. IE: I launch iTunes, then my app, and it works... close my app and start it again (without restarting iTunes) and my app doesn't receive events...
 
Do I have to do something nice when disconnecting from the iTunes API?
 
Any help greatly appreciated!
 
Drew Noakes
drewnoakes.com
GeneralRe: Managing multiple invocations of the COM interopmemberMember 235878828 Aug '08 - 3:24 
Hi there!
Probably you have already solved this issue now two years after you wrote it but for others battling with the same problem here is how I solved it.
 
It's easy actually, just release the iTunesAppClass like this!
 
System.Runtime.InteropServices.Marshal.ReleaseComObject(itunes);
 
Best regards
/Peter Nylander
GeneralRe: Managing multiple invocations of the COM interopmemberDrew Noakes28 Aug '08 - 5:08 
Hi Peter,
 
Actually I did fix this issue. I can't remember exactly how I did so now, though I don't think I used the Marshall class. Perhaps the object was disposable?
 
Actually I wanted to revisit my application as I believe the iTunes API provides more notifications of events these days, reducing the need for polling.
 
Best regards,
 
Drew Noakes.
 
Drew Noakes
drewnoakes.com

QuestionHide iTunesmembertayspen11 Nov '05 - 9:35 
how could i hide iTunes? i Cant ocnvert the code below. Frown | :( Please help
 
FPP
QuestionMusic FoldermemberTraPpeur29 Sep '05 - 8:49 
Is it possible to get the "iTunes music folder" (define in "preferences"-->"advanced" of iTunes ) with that API ?
 
Thank you for your answer.
 
PS : sorry for my english, I'am french.
AnswerRe: Music FoldermemberAdam Durity13 Oct '05 - 17:53 
Sorry for the late reply.
 
It is not possible to get at this setting through the iTunes COM SDK. However, it might be possible to determine this based on the Registry, though my cursory search has turned up no promising results.
 

 
-- Adam
 
"If you can't beat your computer in chess, try kickboxing"
GeneralRe: Music FoldermemberTraPpeur14 Oct '05 - 0:37 
Well, fisrt thank you for your answer...
I haved search for finding it on the Registry too but I have'nt found any good result...So I don't kno w how to find it...So if you find any posibility...
Ben
GeneralRe: Music FoldermemberErikpro8 May '07 - 22:43 
Its in the Reg. Not sure under what key, but i'm using more then one software that knows to read it (Traktor etc).
 
Keep digging
 
Erikpro
GeneralAdding Tracks to iTunesmembersindhoor5 Jun '05 - 4:25 
I am trying to use the iTunes API from C++ to manipulate playlists in iTunes.
Does anyone know how I can add tracks to iTunes from a specific location and then get
the IITTrack object corresponding to that Track?
 
What i want to do is set the play order of that track. But i need to get the IITTrack object to set the play order and i am not sure how i can do that. Any idea?
 
Sindhoor
GeneralItunes COM Eventsmemberzx2c425 Mar '05 - 14:12 
I am currently writing a program in C++ which uses the iTunes COM interfaces from the iTunes COM SDK (http://developer.apple.com/sdk/itunescomsdk.html). I have found it easy to use IiTunes (CoInitialize(NULL); CoCreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER, IID_IiTunes, (PVOID *)&iITunes);), but using _IiTunesEvents poses some adversity. I would like the OnAboutToPromptUserToQuitEvent to call a function where I can run some cleanup code. How can I implement _IiTunesEvents? I am used to C# where I can use += easily, but it is my understanding that COM requires sinks and things of that sort.
 
I want to have something like this:
IiTunes *iITunes = NULL;
//make object bla bla bla
??????????(OnAboutToPromptUserToQuitEvent);
 
.....
 
HRESULT OnAboutToPromptUserToQuitEvent()
{
.....
}
 

Thanks,
Jason A. Donenfeld
ZX2C4 Software
AnswerRe: Itunes COM EventsmemberpVALIUM2 Nov '07 - 0:37 
Hi ZX2C4,
I know, the answer comes 2 years to late for you Wink | ;-) but i want to show my solution for this problem. (because i also was sitting a few days to get it ... and searching in the web for solutions^^)
 
#### in my main program: ####
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 ####
 
#### header of my CiTunesEventHandler class ####
#include "iTunesCOMInterface.h"
 
class CiTunesEventHandler : public _IiTunesEvents
{
private:
long m_dwRefCount;
ITypeInfo* m_pITypeInfo; // Pointer to type information.

public:
CiTunesEventHandler();
~CiTunesEventHandler();
 
HRESULT OnAboutToPromptUserToQuitEvent();
HRESULT OnPlayerPlayEvent();
//...and all the functions you want to use
 
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject);
ULONG STDMETHODCALLTYPE AddRef();
ULONG STDMETHODCALLTYPE Release();
HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT *){return E_NOTIMPL;};
HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT,LCID,ITypeInfo ** ){return E_NOTIMPL;};
HRESULT STDMETHODCALLTYPE GetIDsOfNames(const IID &,LPOLESTR * ,UINT,LCID,DISPID *){return E_NOTIMPL;};
HRESULT STDMETHODCALLTYPE Invoke(DISPID dispidMember, REFIID, LCID,WORD, DISPPARAMS* pdispparams, VARIANT*,EXCEPINFO*, UINT*);
};
#### end header CiTunesEventHandler ####
 
#### implementation of CiTunesEventHandler ####
CiTunesEventHandler::CiTunesEventHandler()
{
m_dwRefCount=0;
ITypeLib* pITypeLib = NULL ;
HRESULT hr = ::LoadRegTypeLib(LIBID_iTunesLib, 1, 5, 0x00, &pITypeLib) ;
// Get type information for the interface of the object.
hr = pITypeLib->GetTypeInfoOfGuid(DIID__IiTunesEvents, &m_pITypeInfo) ;
pITypeLib->Release() ;
}
 
CiTunesEventHandler::~CiTunesEventHandler()
{
}
 
HRESULT CiTunesEventHandler::OnAboutToPromptUserToQuitEvent()
{
//iTunes send OnAboutToPromptUserToQuitEvent
return S_OK;
}
 
HRESULT CiTunesEventHandler::OnPlayerPlayEvent()
{
//iTunes send OnPlayerPlayEvent
return S_OK;
}
 
HRESULT STDMETHODCALLTYPE CiTunesEventHandler::QueryInterface(REFIID iid, void **ppvObject)
{
if ((iid == IID_IDispatch)||(iid == DIID__IiTunesEvents))
{
m_dwRefCount++;
*ppvObject = this;//(_IiTunesEvents *)this;
return S_OK;
}
if (iid == IID_IUnknown)
{
m_dwRefCount++;
*ppvObject = this;//(IUnknown *)this;
return S_OK;
}
return E_NOINTERFACE;
}
 
ULONG STDMETHODCALLTYPE CiTunesEventHandler::AddRef(){
InterlockedIncrement(&m_dwRefCount);
return m_dwRefCount;
}
 
ULONG STDMETHODCALLTYPE CiTunesEventHandler::Release(){
InterlockedDecrement(&m_dwRefCount);
if (m_dwRefCount == 0)
{
delete this;
return 0;
}
return m_dwRefCount;
}
 
HRESULT STDMETHODCALLTYPE CiTunesEventHandler::Invoke(DISPID dispidMember, REFIID, LCID,WORD, DISPPARAMS* pdispparams, VARIANT*,EXCEPINFO*, UINT*){
switch (dispidMember) //look in the documentation for "enum ITEvent" to get the numbers for the functions you want to implement
{
case 2:
this->OnPlayerPlayEvent();
//this->OnPlayerPlayEvent((IITTrack*)&(pdispparams->rgvarg[0].pdispVal));
break;
case 9:
this->OnAboutToPromptUserToQuitEvent();
break;
default: break;
}
return S_OK;
}
#### end implementation CiTunesEventHandler ####
 
the most helpful page for me, was this one: http://www11.ocn.ne.jp/~ikalu/cplus/5501.html
(by the way: Thanks to the japanies Big Grin | :-D )
 
In this way i choose, the function don't have to be named "OnPlayerPlayEvent" and so on... sounds funny (maybe it's not the correct way Roll eyes | :rolleyes: ) but that doesn't matter, because it works :-P
 
If you want to get in example the track with the OnPlayerPlayEvent... you must use something like this : "pdispparams->rgvarg[0].pdispVal" but I don't know exactly (I don't use them *g*)
 
This is a solution without using MFC Smile | :)
 
greetz pVALIUM
(sorry: if my english is not perfect, i am a German)
GeneralRe: Itunes COM Eventsmemberpardillojuegos2 Jul '12 - 4:35 
This thread is 5 years old... but i will try just in case...
 
I like this non MFC solution, but i still have a question...
If I run that project with the Main as it is, the program will terminate in 1 s without having time to create itunes events...
 

Hhow do I tell the main to wait for new events? I tried this infinite loop:
for(;;)
icp->Advise(eventHandler,&dwAdvise);
 
and it works until I first event is triggered, and then it goes mad, blocks itunes and keeps triggering the same event again and again...
 
This is basically what i want...?
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...
 
Thanks!!!!
 
pj
GeneralReceiving Events from iTunessussMatt Berube6 Sep '04 - 8:52 
I'm trying to accomplish this in c++, and it's proving more difficult. Here is the my code:
 
hr = IiTunes->QueryInterface( IID_IConnectionPointContainer, (VOID**)&pContainer );
 
hr = pContainer->FindConnectionPoint( DIID__IiTunesEvents, &pConnectionPoint );
 
hr = pConnectionPoint->Advise(IiTunesEvents, pdwCookie);
 
IiTunesEvents is my class derived from _IiTunesEvents. All of the calls are successful expect the Advise() call. Does anyone know how to do this in c++?
 
Thanks,
Matt Berube
GeneralRe: Receiving Events from iTunesmemberzx2c426 Mar '05 - 6:26 
What does your derived class look like?
AnswerRe: Receiving Events from iTunesmemberMatt Berube4 Dec '05 - 5:08 
I was eventually able to get this working, thanks to this[^] newsgroup thread. Here is my code:
 


///////////////////////////////////////////////////////////////////
// in my main dialog
CiTunesEventHandler m_eventHandler; // this is my event handler class
CComPtr m_connectionPoint;
CComQIPtr cpCont(IiTunes);
 
if (cpCont)
{
   if (SUCCEEDED(cpCont->FindConnectionPoint(DIID__IiTunesEvents, &m_connectionPoint)))
   {
      m_connectionPoint->Advise(m_eventHandler.GetIDispatch(FALSE), &m_cookie);
   }
}
m_eventHandler.m_parent = m_hWnd; // so my event handler can pass messages back
// end main dialog
///////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////
// iTunesEventHandler.h
#include "iTunesCOMInterface.h" // from Apple's iTunes SDK
 
// my user defined messages that get passed back to the main dialog
static const UINT UWM_ITUNESKEYS_PLAYER_PLAY_EVENT = ::RegisterWindowMessage(_T("UWM_ITUNESKEYS_PLAYER_PLAY_EVENT"));
static const UINT UWM_ITUNESKEYS_PLAYER_STOP_EVENT = ::RegisterWindowMessage(_T("UWM_ITUNESKEYS_PLAYER_STOP_EVENT"));
static const UINT UWM_ITUNESKEYS_ITUNESABOUTTOPROMPTUSERTOQUIT = ::RegisterWindowMessage(_T("UWM_ITUNESKEYS_ITUNESABOUTTOPROMPTUSERTOQUIT"));
 
class CiTunesEventHandler : public CCmdTarget
{
public:
CiTunesEventHandler();
virtual ~CiTunesEventHandler();
 
// Attributes
public:
HWND m_parent;
 
// Operations
public:
 
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CiTunesEventHandler)
public:
virtual void OnFinalRelease();
//}}AFX_VIRTUAL
 
// Here are the events I've chosen to handle.
// The complete list can be found in the iTunes SDK help file.
DECLARE_MESSAGE_MAP()
// Generated OLE dispatch map functions
//{{AFX_DISPATCH(CiTunesEventHandler)
afx_msg void OnDatabaseChangedEvent(const VARIANT FAR&
deletedObjectIDs, const VARIANT FAR& changedObjectIDs);
afx_msg void OnPlayerPlayEvent(const VARIANT FAR& iTrack);
afx_msg void OnPlayerStopEvent(const VARIANT FAR& iTrack);
afx_msg void OnPlayerPlayingTrackChangedEv(const VARIANT FAR& iTrack);
afx_msg void OnUserInterfaceEnabledEvent();
afx_msg void OnCOMCallsDisabledEvent(short reason);
afx_msg void OnCOMCallsEnabled();
afx_msg void OnQuittingEvent();
afx_msg void OnAboutToPromptUserToQuitEvent();
afx_msg void OnSoundVolumeChangedEvent(long newVolume);
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
 
LPUNKNOWN GetInterfaceHook(const void *piid);
 
};
 
// end iTunesEventHandler.h
///////////////////////////////////////////////////////////////////
 

///////////////////////////////////////////////////////////////////
// iTunesEventHandler.cpp
 
#include "stdafx.h"
#include "iTunesEventHandler.h"
 
CiTunesEventHandler::CiTunesEventHandler()
{
EnableAutomation();
}
 
CiTunesEventHandler::~CiTunesEventHandler()
{
}
 
void CiTunesEventHandler::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
 
CCmdTarget::OnFinalRelease();
}
 
BEGIN_DISPATCH_MAP(CiTunesEventHandler, CCmdTarget)
//{{AFX_DISPATCH_MAP(CiTunesEventHandler)
DISP_FUNCTION(CiTunesEventHandler, "OnDatabaseChangedEvent",
OnDatabaseChangedEvent, VT_EMPTY, VTS_VARIANT VTS_VARIANT)
DISP_FUNCTION(CiTunesEventHandler, "OnPlayerPlayEvent",
OnPlayerPlayEvent, VT_EMPTY, VTS_VARIANT)
DISP_FUNCTION(CiTunesEventHandler, "OnPlayerStopEvent",
OnPlayerStopEvent, VT_EMPTY, VTS_VARIANT)
DISP_FUNCTION(CiTunesEventHandler, "OnPlayerPlayingTrackChangedEv",
OnPlayerPlayingTrackChangedEv, VT_EMPTY, VTS_VARIANT)
DISP_FUNCTION(CiTunesEventHandler, "OnUserInterfaceEnabledEvent",
OnUserInterfaceEnabledEvent, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CiTunesEventHandler, "OnCOMCallsDisabledEvent",
OnCOMCallsDisabledEvent, VT_EMPTY, VTS_I2)
DISP_FUNCTION(CiTunesEventHandler, "OnCOMCallsEnabled",
OnCOMCallsEnabled, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CiTunesEventHandler, "OnQuittingEvent", OnQuittingEvent,
VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CiTunesEventHandler, "OnAboutToPromptUserToQuitEvent",
OnAboutToPromptUserToQuitEvent, VT_EMPTY, VTS_NONE)
DISP_FUNCTION(CiTunesEventHandler, "OnSoundVolumeChangedEvent",
OnSoundVolumeChangedEvent, VT_EMPTY, VTS_I4)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
 
// Note: we add support for IID_IiTunesEventHandler to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
 
// {429DD3C8-703E-4188-960E-A9821F14B04C}
 
static const IID IID_IiTunesEventHandler = { 0x429dd3c8, 0x703e, 0x4188, { 0x96, 0xe, 0xa9, 0x82, 0x1f, 0x14, 0xb0, 0x4c } };
 
BEGIN_INTERFACE_MAP(CiTunesEventHandler, CCmdTarget)
INTERFACE_PART(CiTunesEventHandler, IID_IiTunesEventHandler, Dispatch)
END_INTERFACE_MAP()
 
/////////////////////////////////////////////////////////////////////////////
// CiTunesEventHandler message handlers
 
//////////////////////////////////////////////////////////////////////
LPUNKNOWN CiTunesEventHandler::GetInterfaceHook(const void *piid)
{
REFIID iid = *(IID *) piid;
if (iid == DIID__IiTunesEvents)
return GetIDispatch(FALSE);
else
return NULL;
}
 
//////////////////////////////////////////////////////////////////////
void CiTunesEventHandler::OnDatabaseChangedEvent(const VARIANT & /*deletedObjectIDs*/, const VARIANT & /*changedObjectIDs*/)
{
}
 
void CiTunesEventHandler::OnPlayerPlayEvent(const VARIANT& /*iTrack*/)
{
PostMessage(m_parent, UWM_ITUNESKEYS_PLAYER_PLAY_EVENT, 0, 0);
}
 
void CiTunesEventHandler::OnPlayerStopEvent(const VARIANT& /*iTrack*/)
{
PostMessage(m_parent, UWM_ITUNESKEYS_PLAYER_STOP_EVENT, 0, 0);
}
 
void CiTunesEventHandler::OnPlayerPlayingTrackChangedEv(const VARIANT & /*iTrack*/)
{
}
 
void CiTunesEventHandler::OnUserInterfaceEnabledEvent()
{
}
 
void CiTunesEventHandler::OnCOMCallsDisabledEvent(short /*reason*/)
{
}
 
void CiTunesEventHandler::OnCOMCallsEnabled()
{
}
 
void CiTunesEventHandler::OnQuittingEvent()
{
}
 
void CiTunesEventHandler::OnAboutToPromptUserToQuitEvent()
{
PostMessage(m_parent, UWM_ITUNESKEYS_ITUNESABOUTTOPROMPTUSERTOQUIT, 0, 0);
}
 
void CiTunesEventHandler::OnSoundVolumeChangedEvent(long /*newVolume*/)
{
}
 
// end iTunesEventHandler.cpp
///////////////////////////////////////////////////////////////////


QuestionRe: Receiving Events from iTunesmemberslowlyhazeing25 Dec '05 - 10:11 
Any idea about how to go about doing that without the use of MFC?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 15 Jul 2004
Article Copyright 2004 by Adam Durity
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid