|
| 1 | +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
| 3 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 | + |
| 7 | +#include "mozilla/mscom/COMWrappers.h" |
| 8 | + |
| 9 | +#include <objbase.h> |
| 10 | + |
| 11 | +#include "mozilla/Assertions.h" |
| 12 | +#include "mozilla/DynamicallyLinkedFunctionPtr.h" |
| 13 | + |
| 14 | +namespace mozilla::mscom::wrapped { |
| 15 | + |
| 16 | +HRESULT CoInitializeEx(LPVOID pvReserved, DWORD dwCoInit) { |
| 17 | + static const StaticDynamicallyLinkedFunctionPtr<decltype(&::CoInitializeEx)> |
| 18 | + pCoInitializeEx(L"combase.dll", "CoInitializeEx"); |
| 19 | + if (!pCoInitializeEx) { |
| 20 | + return ::CoInitializeEx(pvReserved, dwCoInit); |
| 21 | + } |
| 22 | + |
| 23 | + return pCoInitializeEx(pvReserved, dwCoInit); |
| 24 | +} |
| 25 | + |
| 26 | +void CoUninitialize() { |
| 27 | + static const StaticDynamicallyLinkedFunctionPtr<decltype(&::CoUninitialize)> |
| 28 | + pCoUninitialize(L"combase.dll", "CoUninitialize"); |
| 29 | + if (!pCoUninitialize) { |
| 30 | + return ::CoUninitialize(); |
| 31 | + } |
| 32 | + |
| 33 | + return pCoUninitialize(); |
| 34 | +} |
| 35 | + |
| 36 | +HRESULT CoIncrementMTAUsage(CO_MTA_USAGE_COOKIE* pCookie) { |
| 37 | + static const StaticDynamicallyLinkedFunctionPtr< |
| 38 | + decltype(&::CoIncrementMTAUsage)> |
| 39 | + pCoIncrementMTAUsage(L"combase.dll", "CoIncrementMTAUsage"); |
| 40 | + // This API is only available beginning with Windows 8. |
| 41 | + if (!pCoIncrementMTAUsage) { |
| 42 | + return E_NOTIMPL; |
| 43 | + } |
| 44 | + |
| 45 | + HRESULT hr = pCoIncrementMTAUsage(pCookie); |
| 46 | + MOZ_ASSERT(SUCCEEDED(hr)); |
| 47 | + return hr; |
| 48 | +} |
| 49 | + |
| 50 | +HRESULT CoGetApartmentType(APTTYPE* pAptType, APTTYPEQUALIFIER* pAptQualifier) { |
| 51 | + static const StaticDynamicallyLinkedFunctionPtr< |
| 52 | + decltype(&::CoGetApartmentType)> |
| 53 | + pCoGetApartmentType(L"combase.dll", "CoGetApartmentType"); |
| 54 | + if (!pCoGetApartmentType) { |
| 55 | + return ::CoGetApartmentType(pAptType, pAptQualifier); |
| 56 | + } |
| 57 | + |
| 58 | + return pCoGetApartmentType(pAptType, pAptQualifier); |
| 59 | +} |
| 60 | + |
| 61 | +HRESULT CoInitializeSecurity(PSECURITY_DESCRIPTOR pSecDesc, LONG cAuthSvc, |
| 62 | + SOLE_AUTHENTICATION_SERVICE* asAuthSvc, |
| 63 | + void* pReserved1, DWORD dwAuthnLevel, |
| 64 | + DWORD dwImpLevel, void* pAuthList, |
| 65 | + DWORD dwCapabilities, void* pReserved3) { |
| 66 | + static const StaticDynamicallyLinkedFunctionPtr< |
| 67 | + decltype(&::CoInitializeSecurity)> |
| 68 | + pCoInitializeSecurity(L"combase.dll", "CoInitializeSecurity"); |
| 69 | + if (!pCoInitializeSecurity) { |
| 70 | + return ::CoInitializeSecurity(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, |
| 71 | + dwAuthnLevel, dwImpLevel, pAuthList, |
| 72 | + dwCapabilities, pReserved3); |
| 73 | + } |
| 74 | + |
| 75 | + return pCoInitializeSecurity(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, |
| 76 | + dwAuthnLevel, dwImpLevel, pAuthList, |
| 77 | + dwCapabilities, pReserved3); |
| 78 | +} |
| 79 | + |
| 80 | +HRESULT CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, |
| 81 | + DWORD dwClsContext, REFIID riid, LPVOID* ppv) { |
| 82 | + static const StaticDynamicallyLinkedFunctionPtr<decltype(&::CoCreateInstance)> |
| 83 | + pCoCreateInstance(L"combase.dll", "CoCreateInstance"); |
| 84 | + if (!pCoCreateInstance) { |
| 85 | + return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv); |
| 86 | + } |
| 87 | + |
| 88 | + return pCoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv); |
| 89 | +} |
| 90 | + |
| 91 | +HRESULT CoCreateGuid(GUID* pguid) { |
| 92 | + static const StaticDynamicallyLinkedFunctionPtr<decltype(&::CoCreateGuid)> |
| 93 | + pCoCreateGuid(L"combase.dll", "CoCreateGuid"); |
| 94 | + if (!pCoCreateGuid) { |
| 95 | + return ::CoCreateGuid(pguid); |
| 96 | + } |
| 97 | + |
| 98 | + return pCoCreateGuid(pguid); |
| 99 | +} |
| 100 | + |
| 101 | +} // namespace mozilla::mscom::wrapped |
0 commit comments