blob: 08f602f0c478fdba730d6e571ba901f38318f9dd [file] [log] [blame]
Austin Orion0bb354c2020-10-29 11:30:10 -07001/*
2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_
12#define RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_
13
14#include <winerror.h>
15
16#include "rtc_base/win/hstring.h"
17
18namespace webrtc {
19
20// Provides access to Core WinRT functions which may not be available on
21// Windows 7. Loads functions dynamically at runtime to prevent library
22// dependencies.
23
24// Callers must check the return value of ResolveCoreWinRTDelayLoad() before
25// using these functions.
26
27bool ResolveCoreWinRTDelayload();
28
29HRESULT RoGetActivationFactoryProxy(HSTRING class_id,
30 const IID& iid,
31 void** out_factory);
32
33// Retrieves an activation factory for the type specified.
34template <typename InterfaceType, wchar_t const* runtime_class_id>
35HRESULT GetActivationFactory(InterfaceType** factory) {
36 HSTRING class_id_hstring;
37 HRESULT hr = CreateHstring(runtime_class_id, wcslen(runtime_class_id),
38 &class_id_hstring);
39 if (FAILED(hr))
40 return hr;
41
42 hr = RoGetActivationFactoryProxy(class_id_hstring, IID_PPV_ARGS(factory));
Austin Oriond19d0cf2021-01-27 09:40:21 -080043 if (FAILED(hr)) {
44 DeleteHstring(class_id_hstring);
Austin Orion0bb354c2020-10-29 11:30:10 -070045 return hr;
Austin Oriond19d0cf2021-01-27 09:40:21 -080046 }
Austin Orion0bb354c2020-10-29 11:30:10 -070047
48 return DeleteHstring(class_id_hstring);
49}
50
51} // namespace webrtc
52
53#endif // RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_