1
0
mirror of https://github.com/valinet/ExplorerPatcher.git synced 2024-12-18 02:16:00 +01:00
ExplorerPatcher/ep_startmenu/ep_sm_main_cpp.cpp

90 lines
3.4 KiB
C++
Raw Normal View History

#include <Windows.h>
#include <windows.foundation.h>
#include <windows.applicationmodel.resources.core.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>
namespace ABI::Windows::ApplicationModel::Resources::Core::Internal
{
MIDL_INTERFACE("4a8eac58-b652-459d-8de1-239471e8b22b")
IResourceManagerStaticInternal : IInspectable
{
virtual HRESULT STDMETHODCALLTYPE GetResourceManagerForSystemProfile(IResourceManager** result) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentResourceManagerForSystemProfile(IResourceManager** result) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentResourceManagerState(DWORD* result) = 0;
};
MIDL_INTERFACE("c408a1f1-3ede-41e9-9a38-c203678c2df7")
ISystemResourceManagerExtensions : IInspectable
{
virtual HRESULT STDMETHODCALLTYPE GetDefaultResourceContextForCurrentThread(IResourceContext**) = 0;
virtual HRESULT STDMETHODCALLTYPE GetMrtResourceManagerForResourceManager(IInspectable**) = 0;
};
MIDL_INTERFACE("8c25e859-1042-4da0-9232-bf2aa8ff3726")
ISystemResourceManagerExtensions2 : IInspectable
{
virtual HRESULT STDMETHODCALLTYPE LoadPriFileForSystemUse(const WCHAR* path) = 0;
};
}
using namespace Microsoft::WRL;
extern "C" HRESULT LoadOurShellCommonPri()
{
using namespace ABI::Windows::Foundation;
ComPtr<IInspectable> pInspectable;
HRESULT hr = Windows::Foundation::GetActivationFactory(
Wrappers::HStringReference(L"Windows.ApplicationModel.Resources.Core.ResourceManager").Get(),
pInspectable.GetAddressOf()
);
if (FAILED(hr))
return hr;
ComPtr<ABI::Windows::ApplicationModel::Resources::Core::Internal::IResourceManagerStaticInternal> pResourceManagerStaticInternal;
hr = pInspectable.As(&pResourceManagerStaticInternal);
if (FAILED(hr))
return hr;
ComPtr<ABI::Windows::ApplicationModel::Resources::Core::IResourceManager> pResourceManager;
hr = pResourceManagerStaticInternal->GetCurrentResourceManagerForSystemProfile(&pResourceManager);
if (FAILED(hr))
return hr;
ComPtr<ABI::Windows::ApplicationModel::Resources::Core::Internal::ISystemResourceManagerExtensions2> pSystemResourceManagerExtensions2;
pResourceManager.As(&pSystemResourceManagerExtensions2);
WCHAR wszPath[MAX_PATH] = {};
wcscat_s(wszPath, MAX_PATH, L"C:\\Program Files\\ExplorerPatcher\\Windows.UI.ShellCommon.pri");
hr = pSystemResourceManagerExtensions2->LoadPriFileForSystemUse(wszPath);
return hr;
}
extern "C" WCHAR g_szStartUIName[MAX_PATH];
extern "C" HRESULT GetActivationFactoryByPCWSTR_InStartUI(PCWSTR activatableClassId, REFIID riid, void** ppv)
{
typedef HRESULT (WINAPI* DllGetActivationFactory_t)(HSTRING, IActivationFactory**);
static DllGetActivationFactory_t pfnGetActivationFactory;
if (!pfnGetActivationFactory)
{
HMODULE hModule = GetModuleHandleW(g_szStartUIName);
if (hModule)
{
pfnGetActivationFactory = (DllGetActivationFactory_t)GetProcAddress(hModule, "DllGetActivationFactory");
}
}
if (!pfnGetActivationFactory)
return E_FAIL;
ComPtr<IActivationFactory> activationFactory;
HRESULT hr = pfnGetActivationFactory(Wrappers::HStringReference(activatableClassId).Get(), &activationFactory);
if (FAILED(hr))
return hr;
return activationFactory.CopyTo(riid, ppv);
}