Austin Orion | 0bb354c | 2020-10-29 11:30:10 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | namespace 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 | |
| 27 | bool ResolveCoreWinRTDelayload(); |
| 28 | |
| 29 | HRESULT RoGetActivationFactoryProxy(HSTRING class_id, |
| 30 | const IID& iid, |
| 31 | void** out_factory); |
| 32 | |
| 33 | // Retrieves an activation factory for the type specified. |
| 34 | template <typename InterfaceType, wchar_t const* runtime_class_id> |
| 35 | HRESULT 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 Orion | d19d0cf | 2021-01-27 09:40:21 -0800 | [diff] [blame] | 43 | if (FAILED(hr)) { |
| 44 | DeleteHstring(class_id_hstring); |
Austin Orion | 0bb354c | 2020-10-29 11:30:10 -0700 | [diff] [blame] | 45 | return hr; |
Austin Orion | d19d0cf | 2021-01-27 09:40:21 -0800 | [diff] [blame] | 46 | } |
Austin Orion | 0bb354c | 2020-10-29 11:30:10 -0700 | [diff] [blame] | 47 | |
| 48 | return DeleteHstring(class_id_hstring); |
| 49 | } |
| 50 | |
| 51 | } // namespace webrtc |
| 52 | |
| 53 | #endif // RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_ |