Factory.h (1398B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <hstring.h> 5 #include <inspectable.h> 6 #include <winrt/Windows.Foundation.h> 7 #include <atomic> 8 9 namespace Microsoft::Management::Deployment::OutOfProc 10 { 11 struct Factory : winrt::implements<Factory, IClassFactory, winrt::Windows::Foundation::IActivationFactory> 12 { 13 Factory(const GUID& clsid); 14 Factory(HSTRING clsid); 15 ~Factory(); 16 17 // Returns true if the reference count is not 0; false if it is. 18 static bool HasReferences(); 19 20 // Forcibly destroys any static objects. 21 static void Terminate(); 22 23 // Determines if the given CLSID is the CLSID for the factory. 24 static bool IsCLSID(const GUID& clsid); 25 26 // Determines if the given CLSID is the CLSID for the factory. 27 static bool IsCLSID(HSTRING clsid); 28 29 // IActivationFactory 30 winrt::Windows::Foundation::IInspectable ActivateInstance(); 31 32 // IClassFactory 33 HRESULT STDMETHODCALLTYPE CreateInstance(::IUnknown *pUnkOuter, REFIID riid, void **ppvObject); 34 HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock); 35 36 private: 37 static void IncrementRefCount(); 38 static void DecrementRefCount(); 39 40 static std::atomic<int32_t> s_referenceCount; 41 42 GUID m_clsid; 43 }; 44 }