-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTapiCommon.cpp
More file actions
209 lines (167 loc) · 5.05 KB
/
TapiCommon.cpp
File metadata and controls
209 lines (167 loc) · 5.05 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Copyright (C) 2003, 2004 Amit Schreiber <gnobal@yahoo.com>
*
* This file is part of Caller ID plugin for Miranda IM.
*
* Caller ID plugin for Miranda IM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Caller ID plugin for Miranda IM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Caller ID plugin for Miranda IM ; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "TapiCommon.h"
HRESULT InitializeTAPI(CComPtr<ITTAPI>& pTapi, long lEventFilterMask)
{
HRESULT hr = E_FAIL;
hr = pTapi.CoCreateInstance(
CLSID_TAPI,
NULL,
CLSCTX_INPROC_SERVER
);
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
return hr;
}
hr = pTapi->Initialize();
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
pTapi = NULL;
return hr;
}
hr = pTapi->put_EventFilter(lEventFilterMask);
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
pTapi->Shutdown();
pTapi = NULL;
return hr;
}
return S_OK;
}
void ShutdownTAPI(CComPtr<ITTAPI>& pTapi)
{
if (pTapi != NULL)
{
pTapi->Shutdown();
pTapi = NULL;
}
}
HRESULT FindAddresses(CComPtr<ITTAPI>& pTapi, long lAddressType, long lMediaType, /*CComPtr<ITAddress>& pValidAddress*/ AddressArray& arrValidAddresses)
{
HRESULT hr = E_FAIL;
CComPtr<IEnumAddress> pEnumAddress;
hr = pTapi->EnumerateAddresses(&pEnumAddress);
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
return hr;
}
while (TRUE)
{
CComPtr<ITAddress> pAddress;
hr = pEnumAddress->Next( 1, &pAddress, NULL );
if (S_OK != hr)
{
break;
}
CComQIPtr<ITAddressCapabilities> pAddressCaps = pAddress;
if (pAddressCaps == NULL)
{
pAddress = NULL;
continue;
}
long nType = 0;
hr = pAddressCaps->get_AddressCapability(AC_ADDRESSTYPES, &nType);
pAddressCaps = (ITAddressCapabilities*) NULL;
if (FAILED(hr))
{
pAddress = NULL;
continue;
}
if (nType & lAddressType)
{
CComQIPtr<ITMediaSupport> pMediaSupport = pAddress;
if (pMediaSupport == NULL)
{
pAddress = NULL;
continue;
}
CComVariant bvarMediaTypeSupported = VARIANT_FALSE;
hr = pMediaSupport->QueryMediaType(lMediaType, &bvarMediaTypeSupported.boolVal);
pMediaSupport = (ITMediaSupport*) NULL;
if (SUCCEEDED(hr) && (VARIANT_TRUE == bvarMediaTypeSupported.boolVal))
{
CComBSTR bstrAddressName;
hr = pAddress->get_AddressName(&bstrAddressName);
if (FAILED(hr))
{
ATLTRACE("FindAddress: failed to get address name\n");
}
else
{
ATLTRACE("%S\n", bstrAddressName);
}
// pValidAddress = pAddress;
arrValidAddresses.push_back(pAddress);
// break;
}
}
pAddress = NULL;
}
pEnumAddress = NULL;
/* if (pValidAddress == NULL)
{
return E_FAIL;
}
*/
if (arrValidAddresses.size() == 0)
return E_FAIL;
return S_OK;
}
HRESULT AdviseTAPI(
CComPtr<ITTAPI>& pTapi,
CComPtr<ITTAPIEventNotification> pEventHandler,
CComPtr<IConnectionPoint>& pCP,
DWORD& dwCookie
)
{
dwCookie = 0;
CComQIPtr<IConnectionPointContainer> pCPC = pTapi;
HRESULT hr = pCPC->FindConnectionPoint(IID_ITTAPIEventNotification, &pCP);
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
return hr;
pCPC = (IConnectionPointContainer*) NULL;
CComPtr<IUnknown> pUnkEventHandler = pEventHandler;
ATLASSERT(pUnkEventHandler != NULL);
if (pUnkEventHandler == NULL)
return E_POINTER;
hr = pCP->Advise(pUnkEventHandler, &dwCookie);
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
return hr;
pUnkEventHandler = NULL;
return S_OK;
}
HRESULT UnadviseTAPI(
CComPtr<IConnectionPoint>& pCP,
const DWORD dwCookie
)
{
HRESULT hr = pCP->Unadvise(dwCookie);
pCP = NULL;
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
return hr;
return S_OK;
}