diff --git a/dev/WindowsAppRuntime_DLL/dllmain.cpp b/dev/WindowsAppRuntime_DLL/dllmain.cpp index 60c61157c6..210cccf7b2 100644 --- a/dev/WindowsAppRuntime_DLL/dllmain.cpp +++ b/dev/WindowsAppRuntime_DLL/dllmain.cpp @@ -13,10 +13,13 @@ #include <../Detours/detours.h> +static bool isPackaged = AppModel::Identity::IsPackagedProcess(); +static bool is19H1OrGreater = WindowsVersion::IsWindows10_19H1OrGreater(); + static HRESULT DetoursInitialize() { - // Only detour APIs for not-packaged processes - if (AppModel::Identity::IsPackagedProcess()) + // Detours needed for Lifted Reg-Free WinRT Activation before 19H1, and Dynamic Dependencies in unpackaged apps + if (isPackaged && is19H1OrGreater) { return S_OK; } @@ -30,16 +33,22 @@ static HRESULT DetoursInitialize() // Detour APIs to our implementation DetourRestoreAfterWith(); FAIL_FAST_IF_WIN32_ERROR(DetourTransactionBegin()); - FAIL_FAST_IF_FAILED(MddDetourPackageGraphInitialize()); - FAIL_FAST_IF_FAILED(UrfwInitialize()); + if (!isPackaged) + { + FAIL_FAST_IF_FAILED(MddDetourPackageGraphInitialize()); + } + if (!is19H1OrGreater) + { + FAIL_FAST_IF_FAILED(UrfwInitialize()); + } FAIL_FAST_IF_WIN32_ERROR(DetourTransactionCommit()); return S_OK; } static HRESULT DetoursShutdown() { - // Only detour APIs for not-packaged processes - if (AppModel::Identity::IsPackagedProcess()) + // Detours needed for Lifted Reg-Free WinRT Activation before 19H1, and Dynamic Dependencies in unpackaged apps + if (isPackaged && is19H1OrGreater) { return S_OK; } @@ -53,8 +62,14 @@ static HRESULT DetoursShutdown() // Stop Detour'ing APIs to our implementation FAIL_FAST_IF_WIN32_ERROR(DetourTransactionBegin()); FAIL_FAST_IF_WIN32_ERROR(DetourUpdateThread(GetCurrentThread())); - UrfwShutdown(); - MddDetourPackageGraphShutdown(); + if (!is19H1OrGreater) + { + UrfwShutdown(); + } + if (!isPackaged) + { + MddDetourPackageGraphShutdown(); + } FAIL_FAST_IF_WIN32_ERROR(DetourTransactionCommit()); return S_OK; }