Debian Codegraph @

src/win/ComSetup.h

raw symbols SCIP
1 /*
2 Copyright 2009 Last.fm Ltd.
3 - Primarily authored by Max Howell, Jono Cole and Doug Mansell
4
5 This file is part of liblastfm.
6
7 liblastfm is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 liblastfm is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifndef _WIN32_WINNT
21 // This means we are targetting Windows XP onwards
22 // bring in CoInitializeSecurity from objbase.h
23 #define _WIN32_WINNT 0x0501
24 #endif
25
26 #include <objbase.h>
27
28 #ifndef __MINGW32__
29 #include <atlbase.h>
30 #include <atlcom.h>
31 #endif
32
33
34 /** @brief WsConnectionMonitor needs Com to work as early as possible so we do this
35 * @author <[email protected]>
36 */
37 class ComSetup
38 {
39 public:
40 ComSetup()
41 {
42 HRESULT hr = CoInitialize(0);
43 m_bComInitialised = SUCCEEDED(hr);
44 _ASSERT(m_bComInitialised);
45 if (m_bComInitialised) {
46 setupSecurity();
47 }
48 }
49
50 void setupSecurity()
51 {
52 CSecurityDescriptor sd;
53 sd.InitializeFromThreadToken();
54 HRESULT hr = CoInitializeSecurity(sd, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
55 _ASSERT(SUCCEEDED(hr));
56 }
57
58 ~ComSetup()
59 {
60 if (m_bComInitialised) {
61 CoUninitialize();
62 }
63 }
64
65 private:
66 bool m_bComInitialised;
67 };