winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

CoCreatableMicrosoftManagementDeploymentClass.h (1325B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <AppInstallerErrors.h>
      5 #include <winget/GroupPolicy.h>
      6 #include <wil\cppwinrt_wrl.h>
      7 
      8 namespace winrt::Microsoft::Management::Deployment::implementation
      9 {
     10     // Enable custom code to run before creating any object through the factory.
     11     // Currently that means requiring the overall WinGet policy to be enabled.
     12     template <typename TCppWinRTClass>
     13     class wrl_factory_for_winrt_com_class : public ::wil::wrl_factory_for_winrt_com_class<TCppWinRTClass>
     14     {
     15     public:
     16         IFACEMETHODIMP CreateInstance(_In_opt_::IUnknown* unknownOuter, REFIID riid, _COM_Outptr_ void** object) noexcept try
     17         {
     18             *object = nullptr;
     19             RETURN_HR_IF(APPINSTALLER_CLI_ERROR_BLOCKED_BY_POLICY, !::AppInstaller::Settings::GroupPolicies().IsEnabled(::AppInstaller::Settings::TogglePolicy::Policy::WinGet));
     20 
     21             return ::wil::wrl_factory_for_winrt_com_class<TCppWinRTClass>::CreateInstance(unknownOuter, riid, object);
     22         }
     23         CATCH_RETURN()
     24     };
     25 
     26 #define CoCreatableMicrosoftManagementDeploymentClass(className) \
     27     CoCreatableClassWithFactory(className, ::winrt::Microsoft::Management::Deployment::implementation::wrl_factory_for_winrt_com_class<className>)
     28 }