winget-cli

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

dllmain.cpp (1583B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "Factory.h"
      5 #include <hstring.h>
      6 
      7 using namespace Microsoft::Management::Configuration::OutOfProc;
      8 
      9 EXTERN_C BOOL WINAPI DllMain(
     10     HMODULE /* hModule */,
     11     DWORD reason,
     12     LPVOID /* lpReserved */)
     13 {
     14     switch (reason)
     15     {
     16     case DLL_PROCESS_DETACH:
     17         Factory::Terminate();
     18         break;
     19     }
     20 
     21     return TRUE;
     22 }
     23 
     24 _Check_return_
     25 STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID FAR* ppv) try
     26 {
     27     RETURN_HR_IF(E_POINTER, !ppv);
     28     *ppv = nullptr;
     29 
     30     winrt::Windows::Foundation::IUnknown result;
     31 
     32     if (Factory::IsCLSID(rclsid))
     33     {
     34         result = winrt::make<Factory>().as<winrt::Windows::Foundation::IUnknown>();
     35     }
     36 
     37     if (result)
     38     {
     39         return result.as(riid, ppv);
     40     }
     41 
     42     return REGDB_E_CLASSNOTREG;
     43 }
     44 CATCH_RETURN();
     45 
     46 __control_entrypoint(DllExport)
     47 STDAPI DllCanUnloadNow()
     48 {
     49     return Factory::HasReferences() ? S_FALSE : S_OK;
     50 }
     51 
     52 STDAPI DllGetActivationFactory(HSTRING classId, void** factory) try
     53 {
     54     RETURN_HR_IF(E_POINTER, !factory);
     55     *factory = nullptr;
     56 
     57     winrt::Windows::Foundation::IUnknown result;
     58 
     59     if (Factory::IsCLSID(classId))
     60     {
     61         result = winrt::make<Factory>().as<winrt::Windows::Foundation::IUnknown>();
     62     }
     63 
     64     if (result)
     65     {
     66         return result.as(winrt::guid_of<winrt::Windows::Foundation::IActivationFactory>(), factory);
     67     }
     68 
     69     return REGDB_E_CLASSNOTREG;
     70 }
     71 CATCH_RETURN();