-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItunesEventHandler.cpp
executable file
·168 lines (145 loc) · 5.33 KB
/
ItunesEventHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "stdafx.h"
#include "ItunesEventHandler.h"
#include "AppView.h"
iTunesEventHandler::iTunesEventHandler(AppView * m) : main(m), m_dwRefCount(1)
{
ITypeLib* pITypeLib = NULL;
HRESULT hr = ::LoadRegTypeLib
(LIBID_iTunesLib,
1, 5,
0x00, &pITypeLib);
hr = pITypeLib->GetTypeInfoOfGuid(DIID__IiTunesEvents,
&m_pITypeInfo);
pITypeLib->Release();
}
STDMETHODIMP iTunesEventHandler::QueryInterface(REFIID riid, void **ppvObject)
{
*ppvObject = NULL;
if (riid == IID_IUnknown || riid == DIID__IiTunesEvents)
{
*ppvObject = this;
return S_OK;
} else {
return E_NOINTERFACE;
}
}
STDMETHODIMP_(ULONG) iTunesEventHandler::AddRef(void)
{
return InterlockedIncrement(&m_dwRefCount);
}
STDMETHODIMP_(ULONG) iTunesEventHandler::Release(void)
{
if (InterlockedDecrement(&m_dwRefCount) == 0)
{
delete this;
return 0;
}
return m_dwRefCount;
}
STDMETHODIMP iTunesEventHandler::GetTypeInfoCount(UINT *pctinfo)
{
//this method is not called by iTunes
if (pctinfo)
*pctinfo = 0;
return S_OK;
}
STDMETHODIMP iTunesEventHandler::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
{
//this method is not called by iTunes
return TYPE_E_ELEMENTNOTFOUND;
}
STDMETHODIMP iTunesEventHandler::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames,
LCID lcid, DISPID *rgDispId)
{
//this method is not called by iTunes
return E_INVALIDARG;
}
STDMETHODIMP iTunesEventHandler::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
DISPPARAMS *pDispParams, VARIANT *pVarResult,
EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
VARIANTARG* objectIDArray;
HRESULT hResult;
long lb = 0;
long ub = -1;
switch (dispIdMember)
{
case ITEventDatabaseChanged:
////iTunes passes 2 parameters for this event. COM delivers them in reverse order.
////1st parameter: changed IITObjects (2nd in pDispParams)
////2nd parameter: deleted IITObjects (1st in pDispParams)
////Each parameter is a 2-dimensional SAFEARRAY of VARIANT.
////1st dimension: the IITObject that changed or was deleted
////2nd dimension: the 4 ids that uniquely identify the IITObject:
//// source, playlist in source, track in playlist, track in database
////See Apple iTunes API documentation for details.
//if (pDispParams->cArgs != 2)
// return DISP_E_PARAMNOTFOUND;
//for (i=ITunesAPI::Changed, objectIDArray = pDispParams->rgvarg;
// i<=ITunesAPI::Deleted; i++, objectIDArray++)
//{
// if (objectIDArray->vt != (VT_ARRAY|VT_VARIANT))
// return DISP_E_PARAMNOTFOUND;
// hResult = SafeArrayGetLBound(objectIDArray->parray, 1, &lb);
// if (hResult |= S_OK)
// return DISP_E_PARAMNOTFOUND;
// hResult = SafeArrayGetUBound(objectIDArray->parray, 1, &ub);
// if (hResult |= S_OK)
// return DISP_E_PARAMNOTFOUND;
// long index[2];
// ITunesAPI::IITObjectIDs oid;
// for (index[0]=lb; index[0]<=ub; index[0]++)
// {
// for (index[1]=0; index[1]<4; index[1]++)
// {
// VARIANT objects;
// VariantInit(&objects);
// hResult = SafeArrayGetElement(objectIDArray->parray, index, &objects);
// if (hResult != S_OK)
// return DISP_E_PARAMNOTFOUND;
// hResult = VariantChangeType(&objects, &objects, 0, VT_I4);
// if (hResult != S_OK)
// return DISP_E_PARAMNOTFOUND;
// oid.idarray[index[1]] = objects.lVal;
// }
// //Send message to main dialog. WPARAM=Deleted or Changed. LPARAM=object ids
// mainDialog->SendMessage(WM_APP_ITUNES_DATABASE_CHANGED, i, (LPARAM)&oid);
// }
//}
//prevIndex = -1;
//break;
break;
case ITEventPlayerPlay:
main->OnPlay(0,0,0);
break;
case ITEventPlayerStop:
main->OnStop(0,0,0);
break;
case ITEventPlayerPlayingTrackChanged:
main->OnTrackChanged(0,0,0);
break;
case ITEventUserInterfaceEnabled:
//case ITEventCOMCallsDisabled:
// iTunesEnabled = false;
// mainDialog->SendMessage(WM_APP_ITUNES_BUSY, FALSE, 0);
// //We can never block the iTunes event thread. If we do, and then
// //call an iTunes API function, the entire system deadlocks.
// //EnterNoWait isn't perfect, but it's the best we can do.
// criticalSection->EnterNoWait();
// break;
//case ITEventCOMCallsEnabled:
// iTunesEnabled = true;
// criticalSection->LeaveNoWait();
// mainDialog->SendMessage(WM_APP_ITUNES_BUSY, TRUE, 0);
// prevIndex = -1;
// break;
//case ITEventQuitting:
// mainDialog->SendMessage(WM_APP_ABORT, 0, 0);
// break;
case ITEventAboutToPromptUserToQuit:
case ITEventSoundVolumeChanged:
default:
break;
}
return S_OK;
}