Merge pull request #63 from AleBello7276/main

Implemented Wrapper for CoreApplication and ICoreApplicationResourceAvailabilityX
This commit is contained in:
Tyler Jaacks 2024-11-19 20:48:07 -06:00 committed by GitHub
commit 993f3e0cb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 340 additions and 433 deletions

View File

@ -1,19 +0,0 @@
#include "pch.h"
#include "CoreApplicationResourceAvailabilityX.h"
HRESULT CoreApplicationResourceAvailabilityX::_abi_get_ResourceAvailability(ResourceAvailability* resourceAvailability)
{
*resourceAvailability = ResourceAvailability_Full;
return S_OK;
}
HRESULT CoreApplicationResourceAvailabilityX::_abi_add_ResourceAvailabilityChanged(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token)
{
return S_OK;
}
HRESULT CoreApplicationResourceAvailabilityX::_abi_remove_ResourceAvailabilityChanged(EventRegistrationToken token)
{
return S_OK;
}

View File

@ -1,10 +0,0 @@
#pragma once
#include "ICoreApplicationResourceAvailabilityX.h"
class CoreApplicationResourceAvailabilityX : public ICoreApplicationResourceAvailabilityX
{
public:
virtual HRESULT _abi_get_ResourceAvailability(ResourceAvailability* resourceAvailability) override;
virtual HRESULT _abi_add_ResourceAvailabilityChanged(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token) override;
virtual HRESULT _abi_remove_ResourceAvailabilityChanged(EventRegistrationToken token) override;
};

View File

@ -0,0 +1,194 @@
#include "pch.h"
#include "CoreApplicationWrapperX.h"
HRESULT CoreApplicationWrapperX::GetIids(ULONG* iidCount, IID** iids)
{
return m_coreWindow->GetIids(iidCount, iids);
}
HRESULT CoreApplicationWrapperX::GetRuntimeClassName(HSTRING* className)
{
return m_coreWindow->GetRuntimeClassName(className);
}
HRESULT CoreApplicationWrapperX::GetTrustLevel(TrustLevel* trustLevel)
{
return m_coreWindow->GetTrustLevel(trustLevel);
}
INT32 CoreApplicationWrapperX::_abi_add_Resuming(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token)
{
return m_IapplicationCore->add_Resuming(handler, token);
}
INT32 CoreApplicationWrapperX::_abi_remove_Resuming(EventRegistrationToken token)
{
return m_IapplicationCore->remove_Resuming(token);
}
INT32 CoreApplicationWrapperX::_abi_add_Suspending(__FIEventHandler_1_Windows__CApplicationModel__CSuspendingEventArgs* handler, EventRegistrationToken* token)
{
return m_IapplicationCore->add_Suspending(handler, token);
}
INT32 CoreApplicationWrapperX::_abi_remove_Suspending(EventRegistrationToken token)
{
return m_IapplicationCore->remove_Suspending(token);
}
HRESULT CoreApplicationWrapperX::_abi_get_ResourceAvailability(ResourceAvailability* resourceAvailability)
{
// TODO: Stubbed for now.
*resourceAvailability = ResourceAvailability_Full;
return S_OK;
}
INT32 CoreApplicationWrapperX::_abi_get_ResourceAvailability()
{
return S_OK;
}
HRESULT CoreApplicationWrapperX::_abi_add_ResourceAvailabilityChanged(winrt::Windows::Foundation::EventHandler<IInspectable>* handler, EventRegistrationToken* token)
{
//Stubbed at this moment.
return 0;
}
HRESULT CoreApplicationWrapperX::_abi_remove_ResourceAvailabilityChanged(EventRegistrationToken token)
{
//Stubbed at this moment.
return 0;
}
INT32 CoreApplicationWrapperX::_abi_get_CoreWindow(ABI::Windows::UI::Core::ICoreWindow** Window)
{
return m_IapplicationCoreView->get_CoreWindow(Window);
}
INT32 CoreApplicationWrapperX::_abi_add_Activated(__FITypedEventHandler_2_Windows__CApplicationModel__CCore__CCoreApplicationView_Windows__CApplicationModel__CActivation__CIActivatedEventArgs* handler, EventRegistrationToken* token)
{
return m_IapplicationCoreView->add_Activated(handler, token);
}
INT32 CoreApplicationWrapperX::_abi_remove_Activated(EventRegistrationToken token)
{
return m_IapplicationCoreView->remove_Activated(token);
}
INT32 CoreApplicationWrapperX::_abi_Exit()
{
return m_applicationCoreExit->Exit();
}
INT32 CoreApplicationWrapperX::_abi_add_Exiting(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token)
{
return m_applicationCoreExit->add_Exiting(handler, token);
}
INT32 CoreApplicationWrapperX::_abi_remove_Exiting(EventRegistrationToken token)
{
return m_applicationCoreExit->remove_Exiting(token);
}
INT32 CoreApplicationWrapperX::_abi_RunWithActivationFactories(ABI::Windows::Foundation::IGetActivationFactory* activationFactoryCallback)
{
return m_IapplicationCore->RunWithActivationFactories(activationFactoryCallback);
}
INT32 CoreApplicationWrapperX::_abi_GetCurrentView(ABI::Windows::ApplicationModel::Core::ICoreApplicationView** value)
{
return m_IapplicationCore->GetCurrentView(value);
}
INT32 CoreApplicationWrapperX::_abi_Run(ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* viewSource)
{
return m_IapplicationCore->Run(viewSource);
}
INT32 CoreApplicationWrapperX::Run(ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* viewSource)
{
return m_IapplicationCore->Run(viewSource);
}
INT32 CoreApplicationWrapperX::_abi_get_Id(HSTRING* value)
{
return m_IapplicationCore->get_Id(value);
}
INT32 CoreApplicationWrapperX::_abi_get_Properties(ABI::Windows::Foundation::Collections::IPropertySet** value)
{
return m_IapplicationCore->get_Properties(value);
}
INT32 CoreApplicationWrapperX::_abi_Initialize(ABI::Windows::ApplicationModel::Core::ICoreApplicationView* application)
{
return m_IFrameworkView->Initialize(application);
}
INT32 CoreApplicationWrapperX::_abi_SetWindow(ICoreWindow* window)
{
return m_IFrameworkView->SetWindow(window);
}
INT32 CoreApplicationWrapperX::_abi_Load(HSTRING string)
{
return m_IFrameworkView->Load(string);
}
INT32 CoreApplicationWrapperX::__abi_Run()
{
return m_IFrameworkView->Run();
}
INT32 CoreApplicationWrapperX::_abi_Uninitialize()
{
return m_IFrameworkView->Uninitialize();
}
INT32 CoreApplicationWrapperX::_abi_CreateView(ABI::Windows::ApplicationModel::Core::IFrameworkView** view)
{
return m_IFrameworkViewSource->CreateView(view);
}
HRESULT CoreApplicationWrapperX::QueryInterface(const IID& riid, void** ppvObject)
{
if (riid == __uuidof(IActivationFactory) || riid == __uuidof(IUnknown))
{
*ppvObject = static_cast<IActivationFactory*>(this);
AddRef();
return S_OK;
}
else if (riid == __uuidof(ICoreApplicationResourceAvailabilityX)) // allow ICoreApplicationResourceAvailabilityX interface
{
*ppvObject = static_cast<ICoreApplicationResourceAvailabilityX*>(this);
AddRef();
return S_OK;
}
return m_realFactory->QueryInterface(riid, ppvObject);
}
ULONG CoreApplicationWrapperX::AddRef()
{
return InterlockedIncrement(&m_refCount);
}
ULONG CoreApplicationWrapperX::Release()
{
ULONG refCount = InterlockedDecrement(&m_refCount);
if (refCount == 0)
delete this;
return refCount;
}
HRESULT CoreApplicationWrapperX::ActivateInstance(IInspectable** instance)
{
HRESULT hr = m_realFactory->ActivateInstance(instance);
if (FAILED(hr))
{
return hr;
}
return S_OK;
}

View File

@ -1,64 +1,71 @@
#pragma once
#include "ICoreApplicationX.h"
class CoreApplicationX : public ICoreApplicationX
{
public:
CoreApplicationX(winrt::Windows::ApplicationModel::Core::CoreApplication* application)
{
m_applicationCore = reinterpret_cast<winrt::Windows::ApplicationModel::Core::CoreApplication*>(application);
m_IapplicationCore = reinterpret_cast<ABI::Windows::ApplicationModel::Core::ICoreApplication*>(application);
m_IapplicationCoreView = reinterpret_cast<ABI::Windows::ApplicationModel::Core::ICoreApplicationView*>(application);
m_applicationCoreView = reinterpret_cast<ABI::Windows::ApplicationModel::Core::CoreApplicationView*>(application);
m_applicationCoreExit = reinterpret_cast<ABI::Windows::ApplicationModel::Core::ICoreApplicationExit*>(application);
m_coreWindow = reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow*>(application);
m_IFrameworkView = reinterpret_cast<ABI::Windows::ApplicationModel::Core::IFrameworkView*>(application);
m_IFrameworkViewSource = reinterpret_cast<ABI::Windows::ApplicationModel::Core::IFrameworkViewSource*>(application);
}
public:
HRESULT GetIids(ULONG* iidCount, IID** iids) override;
HRESULT GetRuntimeClassName(HSTRING* className) override;
HRESULT GetTrustLevel(TrustLevel* trustLevel) override;
INT32 _abi_add_Resuming(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_Resuming(EventRegistrationToken token) override;
INT32 _abi_add_Suspending(__FIEventHandler_1_Windows__CApplicationModel__CSuspendingEventArgs* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_Suspending(EventRegistrationToken token) override;
INT32 _abi_get_ResourceAvailability(ResourceAvailability* resourceAvailability) override;
INT32 _abi_get_ResourceAvailability() override;
INT32 _abi_add_ResourceAvailabilityChanged(winrt::Windows::Foundation::EventHandler<IInspectable>* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_ResourceAvailabilityChanged(EventRegistrationToken token) override;
INT32 _abi_get_CoreWindow(ABI::Windows::UI::Core::ICoreWindow**) override;
INT32 _abi_add_Activated(__FITypedEventHandler_2_Windows__CApplicationModel__CCore__CCoreApplicationView_Windows__CApplicationModel__CActivation__CIActivatedEventArgs* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_Activated(EventRegistrationToken token) override;
INT32 _abi_Exit() override;
INT32 _abi_add_Exiting(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_Exiting(EventRegistrationToken token) override;
INT32 _abi_RunWithActivationFactories(ABI::Windows::Foundation::IGetActivationFactory* activationFactoryCallback) override;
INT32 _abi_GetCurrentView(ABI::Windows::ApplicationModel::Core::ICoreApplicationView** value) override;
INT32 _abi_Run(ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* viewSource) override;
INT32 Run(ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* viewSource) override;
INT32 _abi_get_Id(HSTRING* value) override;
INT32 _abi_get_Properties(ABI::Windows::Foundation::Collections::IPropertySet** value) override;
INT32 _abi_Initialize(ABI::Windows::ApplicationModel::Core::ICoreApplicationView* application) override;
INT32 _abi_SetWindow(ICoreWindow* window) override;
INT32 _abi_Load(HSTRING string) override;
INT32 __abi_Run() override;
INT32 _abi_Uninitialize() override;
INT32 _abi_CreateView(ABI::Windows::ApplicationModel::Core::IFrameworkView** view) override;
HRESULT QueryInterface(const IID& riid, void** ppvObject) override;
ULONG AddRef() override;
ULONG Release() override;
private:
winrt::Windows::ApplicationModel::Core::CoreApplication* m_applicationCore;
ABI::Windows::ApplicationModel::Core::ICoreApplication* m_IapplicationCore;
ABI::Windows::ApplicationModel::Core::ICoreApplicationView* m_IapplicationCoreView;
ABI::Windows::ApplicationModel::Core::CoreApplicationView* m_applicationCoreView;
ABI::Windows::ApplicationModel::Core::ICoreApplicationExit* m_applicationCoreExit;
ABI::Windows::UI::Core::ICoreWindow* m_coreWindow;
ABI::Windows::ApplicationModel::Core::IFrameworkView* m_IFrameworkView;
ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* m_IFrameworkViewSource;
#pragma once
#include "ICoreApplicationX.h"
class CoreApplicationWrapperX : public ICoreApplicationX
{
public:
CoreApplicationWrapperX(winrt::Windows::ApplicationModel::Core::CoreApplication* application)
{
m_applicationCore = reinterpret_cast<winrt::Windows::ApplicationModel::Core::CoreApplication*>(application);
m_IapplicationCore = reinterpret_cast<ABI::Windows::ApplicationModel::Core::ICoreApplication*>(application);
m_IapplicationCoreView = reinterpret_cast<ABI::Windows::ApplicationModel::Core::ICoreApplicationView*>(application);
m_applicationCoreView = reinterpret_cast<ABI::Windows::ApplicationModel::Core::CoreApplicationView*>(application);
m_applicationCoreExit = reinterpret_cast<ABI::Windows::ApplicationModel::Core::ICoreApplicationExit*>(application);
m_coreWindow = reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow*>(application);
m_IFrameworkView = reinterpret_cast<ABI::Windows::ApplicationModel::Core::IFrameworkView*>(application);
m_IFrameworkViewSource = reinterpret_cast<ABI::Windows::ApplicationModel::Core::IFrameworkViewSource*>(application);
}
CoreApplicationWrapperX(ComPtr<IActivationFactory> realFactory)
: m_realFactory(realFactory)
{}
public:
HRESULT ActivateInstance(IInspectable** instance) override;
HRESULT GetIids(ULONG* iidCount, IID** iids) override;
HRESULT GetRuntimeClassName(HSTRING* className) override;
HRESULT GetTrustLevel(TrustLevel* trustLevel) override;
INT32 _abi_add_Resuming(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_Resuming(EventRegistrationToken token) override;
INT32 _abi_add_Suspending(__FIEventHandler_1_Windows__CApplicationModel__CSuspendingEventArgs* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_Suspending(EventRegistrationToken token) override;
HRESULT _abi_get_ResourceAvailability(ResourceAvailability* resourceAvailability) override;
INT32 _abi_get_ResourceAvailability() override;
HRESULT _abi_add_ResourceAvailabilityChanged(winrt::Windows::Foundation::EventHandler<IInspectable>* handler, EventRegistrationToken* token) override;
HRESULT _abi_remove_ResourceAvailabilityChanged(EventRegistrationToken token) override;
INT32 _abi_get_CoreWindow(ABI::Windows::UI::Core::ICoreWindow**) override;
INT32 _abi_add_Activated(__FITypedEventHandler_2_Windows__CApplicationModel__CCore__CCoreApplicationView_Windows__CApplicationModel__CActivation__CIActivatedEventArgs* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_Activated(EventRegistrationToken token) override;
INT32 _abi_Exit() override;
INT32 _abi_add_Exiting(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token) override;
INT32 _abi_remove_Exiting(EventRegistrationToken token) override;
INT32 _abi_RunWithActivationFactories(ABI::Windows::Foundation::IGetActivationFactory* activationFactoryCallback) override;
INT32 _abi_GetCurrentView(ABI::Windows::ApplicationModel::Core::ICoreApplicationView** value) override;
INT32 _abi_Run(ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* viewSource) override;
INT32 Run(ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* viewSource) override;
INT32 _abi_get_Id(HSTRING* value) override;
INT32 _abi_get_Properties(ABI::Windows::Foundation::Collections::IPropertySet** value) override;
INT32 _abi_Initialize(ABI::Windows::ApplicationModel::Core::ICoreApplicationView* application) override;
INT32 _abi_SetWindow(ICoreWindow* window) override;
INT32 _abi_Load(HSTRING string) override;
INT32 __abi_Run() override;
INT32 _abi_Uninitialize() override;
INT32 _abi_CreateView(ABI::Windows::ApplicationModel::Core::IFrameworkView** view) override;
HRESULT QueryInterface(const IID& riid, void** ppvObject) override;
ULONG AddRef() override;
ULONG Release() override;
private:
long m_refCount = 1;
ComPtr<IActivationFactory> m_realFactory;
winrt::Windows::ApplicationModel::Core::CoreApplication* m_applicationCore;
ABI::Windows::ApplicationModel::Core::ICoreApplication* m_IapplicationCore;
ABI::Windows::ApplicationModel::Core::ICoreApplicationView* m_IapplicationCoreView;
ABI::Windows::ApplicationModel::Core::CoreApplicationView* m_applicationCoreView;
ABI::Windows::ApplicationModel::Core::ICoreApplicationExit* m_applicationCoreExit;
ABI::Windows::UI::Core::ICoreWindow* m_coreWindow;
ABI::Windows::ApplicationModel::Core::IFrameworkView* m_IFrameworkView;
ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* m_IFrameworkViewSource;
};

View File

@ -1,167 +0,0 @@
#include "pch.h"
#include "CoreApplicationX.h"
HRESULT CoreApplicationX::GetIids(ULONG* iidCount, IID** iids)
{
return m_coreWindow->GetIids(iidCount, iids);
}
HRESULT CoreApplicationX::GetRuntimeClassName(HSTRING* className)
{
return m_coreWindow->GetRuntimeClassName(className);
}
HRESULT CoreApplicationX::GetTrustLevel(TrustLevel* trustLevel)
{
return m_coreWindow->GetTrustLevel(trustLevel);
}
INT32 CoreApplicationX::_abi_add_Resuming(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token)
{
return m_IapplicationCore->add_Resuming(handler, token);
}
INT32 CoreApplicationX::_abi_remove_Resuming(EventRegistrationToken token)
{
return m_IapplicationCore->remove_Resuming(token);
}
INT32 CoreApplicationX::_abi_add_Suspending(__FIEventHandler_1_Windows__CApplicationModel__CSuspendingEventArgs* handler, EventRegistrationToken* token)
{
return m_IapplicationCore->add_Suspending(handler, token);
}
INT32 CoreApplicationX::_abi_remove_Suspending(EventRegistrationToken token)
{
return m_IapplicationCore->remove_Suspending(token);
}
INT32 CoreApplicationX::_abi_get_ResourceAvailability(ResourceAvailability* resourceAvailability)
{
// TODO: Stubbed for now.
*resourceAvailability = ResourceAvailability_Full;
return S_OK;
}
INT32 CoreApplicationX::_abi_get_ResourceAvailability()
{
return S_OK;
}
INT32 CoreApplicationX::_abi_add_ResourceAvailabilityChanged(winrt::Windows::Foundation::EventHandler<IInspectable>* handler, EventRegistrationToken* token)
{
//Stubbed at this moment.
return 0;
}
INT32 CoreApplicationX::_abi_remove_ResourceAvailabilityChanged(EventRegistrationToken token)
{
//Stubbed at this moment.
return 0;
}
INT32 CoreApplicationX::_abi_get_CoreWindow(ABI::Windows::UI::Core::ICoreWindow** Window)
{
return m_IapplicationCoreView->get_CoreWindow(Window);
}
INT32 CoreApplicationX::_abi_add_Activated(__FITypedEventHandler_2_Windows__CApplicationModel__CCore__CCoreApplicationView_Windows__CApplicationModel__CActivation__CIActivatedEventArgs* handler, EventRegistrationToken* token)
{
return m_IapplicationCoreView->add_Activated(handler, token);
}
INT32 CoreApplicationX::_abi_remove_Activated(EventRegistrationToken token)
{
return m_IapplicationCoreView->remove_Activated(token);
}
INT32 CoreApplicationX::_abi_Exit()
{
return m_applicationCoreExit->Exit();
}
INT32 CoreApplicationX::_abi_add_Exiting(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token)
{
return m_applicationCoreExit->add_Exiting(handler, token);
}
INT32 CoreApplicationX::_abi_remove_Exiting(EventRegistrationToken token)
{
return m_applicationCoreExit->remove_Exiting(token);
}
INT32 CoreApplicationX::_abi_RunWithActivationFactories(ABI::Windows::Foundation::IGetActivationFactory* activationFactoryCallback)
{
return m_IapplicationCore->RunWithActivationFactories(activationFactoryCallback);
}
INT32 CoreApplicationX::_abi_GetCurrentView(ABI::Windows::ApplicationModel::Core::ICoreApplicationView** value)
{
return m_IapplicationCore->GetCurrentView(value);
}
INT32 CoreApplicationX::_abi_Run(ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* viewSource)
{
return m_IapplicationCore->Run(viewSource);
}
INT32 CoreApplicationX::Run(ABI::Windows::ApplicationModel::Core::IFrameworkViewSource* viewSource)
{
return m_IapplicationCore->Run(viewSource);
}
INT32 CoreApplicationX::_abi_get_Id(HSTRING* value)
{
return m_IapplicationCore->get_Id(value);
}
INT32 CoreApplicationX::_abi_get_Properties(ABI::Windows::Foundation::Collections::IPropertySet** value)
{
return m_IapplicationCore->get_Properties(value);
}
INT32 CoreApplicationX::_abi_Initialize(ABI::Windows::ApplicationModel::Core::ICoreApplicationView* application)
{
return m_IFrameworkView->Initialize(application);
}
INT32 CoreApplicationX::_abi_SetWindow(ICoreWindow* window)
{
return m_IFrameworkView->SetWindow(window);
}
INT32 CoreApplicationX::_abi_Load(HSTRING string)
{
return m_IFrameworkView->Load(string);
}
INT32 CoreApplicationX::__abi_Run()
{
return m_IFrameworkView->Run();
}
INT32 CoreApplicationX::_abi_Uninitialize()
{
return m_IFrameworkView->Uninitialize();
}
INT32 CoreApplicationX::_abi_CreateView(ABI::Windows::ApplicationModel::Core::IFrameworkView** view)
{
return m_IFrameworkViewSource->CreateView(view);
}
HRESULT CoreApplicationX::QueryInterface(const IID& riid, void** ppvObject)
{
return m_coreWindow->QueryInterface(riid, ppvObject);
}
ULONG CoreApplicationX::AddRef()
{
return m_coreWindow->AddRef();
}
ULONG CoreApplicationX::Release()
{
return m_coreWindow->Release();
}

View File

@ -20,6 +20,6 @@ ICoreApplicationResourceAvailabilityX : public IInspectable
{
public:
STDMETHOD(_abi_get_ResourceAvailability)(ResourceAvailability *) PURE;
STDMETHOD(_abi_add_ResourceAvailabilityChanged)(__FIEventHandler_1_IInspectable *, EventRegistrationToken *) PURE;
STDMETHOD(_abi_add_ResourceAvailabilityChanged)(winrt::Windows::Foundation::EventHandler<IInspectable>* handler, EventRegistrationToken* token) PURE;
STDMETHOD(_abi_remove_ResourceAvailabilityChanged)(EventRegistrationToken) PURE;
};

View File

@ -10,17 +10,17 @@ using namespace ABI::Windows::ApplicationModel::Core;
using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::System;
class ICoreApplicationX : public IInspectable
class ICoreApplicationX : public RuntimeClass<IActivationFactory, ICoreApplicationResourceAvailabilityX>
{
public:
virtual INT32 _abi_add_Resuming(__FIEventHandler_1_IInspectable* handler, EventRegistrationToken* token) = 0;
virtual INT32 _abi_remove_Resuming(EventRegistrationToken token) = 0;
virtual INT32 _abi_add_Suspending(__FIEventHandler_1_Windows__CApplicationModel__CSuspendingEventArgs* handler, EventRegistrationToken* token) = 0;
virtual INT32 _abi_remove_Suspending(EventRegistrationToken token) = 0;
virtual INT32 _abi_get_ResourceAvailability(ResourceAvailability* resourceAvailability) = 0;
virtual HRESULT _abi_get_ResourceAvailability(ResourceAvailability* resourceAvailability) = 0;
virtual INT32 _abi_get_ResourceAvailability() = 0;
virtual INT32 _abi_add_ResourceAvailabilityChanged(winrt::Windows::Foundation::EventHandler<IInspectable>* handler, EventRegistrationToken* token) = 0;
virtual INT32 _abi_remove_ResourceAvailabilityChanged(EventRegistrationToken token) = 0;
virtual HRESULT _abi_add_ResourceAvailabilityChanged(winrt::Windows::Foundation::EventHandler<IInspectable>* handler, EventRegistrationToken* token) = 0;
virtual HRESULT _abi_remove_ResourceAvailabilityChanged(EventRegistrationToken token) = 0;
virtual INT32 _abi_get_CoreWindow(ABI::Windows::UI::Core::ICoreWindow**) = 0;
virtual INT32 _abi_add_Activated(__FITypedEventHandler_2_Windows__CApplicationModel__CCore__CCoreApplicationView_Windows__CApplicationModel__CActivation__CIActivatedEventArgs* handler, EventRegistrationToken* token) = 0;
virtual INT32 _abi_remove_Activated(EventRegistrationToken token) = 0;

View File

@ -11,7 +11,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID reserved)
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&reinterpret_cast<PVOID&>(TrueRoGetActivationFactory), RoGetActivationFactory_Hook);
DetourTransactionCommit();
}
else if (dwReason == DLL_PROCESS_DETACH)

View File

@ -1,98 +1,9 @@
#pragma once
#include <winrt/Windows.ApplicationModel.h>
#include "CoreApplicationX.h"
/* Concrete class for the CoreApplicationResourceAvailability.
* This class is required because the Windows does not provide a
* concrete implementation for this interface or the interface itself.
*/
class CCoreApplicationResourceAvailabilityX : public ICoreApplicationResourceAvailabilityX
{
LONG m_RefCount = 1;
#include "CoreApplicationWrapperX.h"
public:
IFACEMETHOD(QueryInterface)(REFIID iid, void** ppv)
{
if (ppv == nullptr) return E_POINTER;
if (iid == __uuidof(IUnknown) || iid == __uuidof(IInspectable) || iid == __uuidof(ICoreApplicationResourceAvailabilityX))
{
this->AddRef();
*ppv = this;
return S_OK;
}
*ppv = nullptr;
return E_NOINTERFACE;
}
IFACEMETHOD_(ULONG, AddRef)()
{
return InterlockedIncrement(&this->m_RefCount);
}
IFACEMETHOD_(ULONG, Release)()
{
const auto refCount = InterlockedDecrement(&this->m_RefCount);
if (refCount == 0) delete this;
return refCount;
}
IFACEMETHOD(_abi_get_ResourceAvailability)(ResourceAvailability *value)
{
if (value == nullptr) return E_POINTER;
*value = ResourceAvailability_Full;
return S_OK();
}
IFACEMETHOD(_abi_add_ResourceAvailabilityChanged)(__FIEventHandler_1_IInspectable *handler, EventRegistrationToken *token)
{
if (token == nullptr) return E_POINTER;
*token = {};
return S_OK();
}
IFACEMETHOD(_abi_remove_ResourceAvailabilityChanged)(EventRegistrationToken token)
{
return S_OK();
}
IFACEMETHOD(GetIids)(ULONG* iidCount, IID** iids)
{
// TODO: Implement this method.
return S_OK();
}
IFACEMETHOD(GetRuntimeClassName)(HSTRING* className)
{
if (className == nullptr) return E_POINTER;
HSTRING _className = nullptr;
WindowsCreateString(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication, sizeof(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication), &_className);
*className = _className;
return S_OK();
}
IFACEMETHOD(GetTrustLevel)(TrustLevel* trustLevel)
{
*trustLevel = FullTrust;
return S_OK();
}
};
/* This function is used to compare the class name of the classId with the classIdName. */
inline bool IsClassName(HSTRING classId, const char* classIdName)
@ -117,8 +28,6 @@ typedef HRESULT(*DllGetActivationFactoryFunc) (HSTRING, IActivationFactory**);
DllGetForCurrentThreadFunc pDllGetForCurrentThread = nullptr;
/* Function pointers for the DllGetForCurrentThread */
DllGetForCurrentThreadFunc_App pDllGetForCurrentThread_App = nullptr;
/* Function pointers for the CoreApplicationFactory's QueryInterface */
CoreApplicationFactory_QueryInterface pCoreApplicationFactory_QueryInterface = nullptr;
/* Function pointers for the DllGetActivationFactory */
DllGetActivationFactoryFunc pDllGetActivationFactory = nullptr;
@ -126,8 +35,6 @@ DllGetActivationFactoryFunc pDllGetActivationFactory = nullptr;
HRESULT(STDMETHODCALLTYPE* TrueGetForCurrentThread)(ICoreWindowStatic* staticWindow, CoreWindow** window);
/* Function pointers for the DllGetForCurrentThread */
HRESULT(STDMETHODCALLTYPE* TrueGetForCurrentThread_App)(ICoreApplication* application, winrt::Windows::ApplicationModel::Core::CoreApplication** Application);
/* Function pointers for the CoreApplicationFactory's QueryInterface */
HRESULT(STDMETHODCALLTYPE* TrueCoreApplicationFactory_QueryInterface)(IUnknown* factory, REFIID iid, void** ppv);
/* Function pointers for the WinRT RoGetActivationFactory function. */
HRESULT(WINAPI* TrueRoGetActivationFactory)(HSTRING classId, REFIID iid, void** factory) = RoGetActivationFactory;
@ -148,89 +55,90 @@ inline HRESULT STDMETHODCALLTYPE GetForCurrentThread_Hook(ICoreWindowStatic* par
/* Hook for CoreApplication's GetForCurrentThread function. */
inline HRESULT STDMETHODCALLTYPE GetForCurrentThreadCoreApplication_Hook(ICoreApplication* paramThis, winrt::Windows::ApplicationModel::Core::CoreApplication** Application)
{
wprintf(L"SAsa");
// ReSharper disable once CppLocalVariableMayBeConst
HRESULT hrApp = TrueGetForCurrentThread_App(paramThis, Application);
auto pApp = *reinterpret_cast<void**>(Application);
pApp = new CoreApplicationX(*Application);
//pApp = new CoreApplicationWrapperX(*Application);
return hrApp;
}
/* Hook for CoreApplicationFactory's QueryInterface function. */
inline HRESULT STDMETHODCALLTYPE CoreApplicationFactory_QueryInterface_Hook(IUnknown* pFactory, REFIID iid, void** ppv)
{
if (ppv == nullptr)
return E_POINTER;
if (iid == __uuidof(ICoreApplicationResourceAvailabilityX))
{
*ppv = new CCoreApplicationResourceAvailabilityX;
return S_OK();
}
return TrueCoreApplicationFactory_QueryInterface(pFactory, iid, ppv);
}
/* Hook for the WinRT RoGetActivationFactory function. */
inline HRESULT WINAPI RoGetActivationFactory_Hook(HSTRING classId, REFIID iid, void** factory)
{
auto hr = TrueRoGetActivationFactory(classId, iid, factory);
// Get the raw buffer from the HSTRING
const wchar_t* rawString = WindowsGetStringRawBuffer(classId, nullptr);
if (rawString) {
// Print the string using wprintf
wprintf(L"%ls\n", rawString);
}
auto hr = 0;
if (IsClassName(classId, "Windows.ApplicationModel.Core.CoreApplication"))
{
ComPtr<IActivationFactory> realFactory;
hr = TrueRoGetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), IID_PPV_ARGS(&realFactory));
if (FAILED(hr))
return hr;
//ComPtr<ICoreApplicationX> wrappedFactory = Make<ICoreApplicationX>(realFactory.Get());
ComPtr<CoreApplicationWrapperX> wrappedFactory = Make<CoreApplicationWrapperX>(realFactory);
return wrappedFactory.CopyTo(iid, factory);
}
else if (IsClassName(classId, "Windows.UI.Core.CoreWindow"))
{
/*ComPtr<ICoreWindowStatic> coreWindowStatic;
hr = RoGetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Core_CoreWindow).Get(), IID_PPV_ARGS(&coreWindowStatic));
*reinterpret_cast<void**>(&TrueGetForCurrentThread) = (*reinterpret_cast<void***>(coreWindowStatic.Get()))[6];
DetourAttach(&TrueGetForCurrentThread, GetForCurrentThread_Hook);*/
}
// After WinDurango overrides try to load the rest
hr = TrueRoGetActivationFactory(classId, iid, factory);
if (FAILED(hr))
{
auto library = LoadPackagedLibrary(L"winrt_x.dll", 0);
if (!library) library = LoadLibraryW(L"winrt_x.dll");
if (!library) return hr;
pDllGetActivationFactory = reinterpret_cast<DllGetActivationFactoryFunc>
(GetProcAddress(library, "DllGetActivationFactory"));
if (!pDllGetActivationFactory)
{
auto library = LoadPackagedLibrary(L"winrt_x.dll", 0);
if (!library) library = LoadLibraryW(L"winrt_x.dll");
if (!library) return hr;
pDllGetActivationFactory = reinterpret_cast<DllGetActivationFactoryFunc>
(GetProcAddress(library, "DllGetActivationFactory"));
if (!pDllGetActivationFactory)
return hr;
}
// fallback
ComPtr<IActivationFactory> fallbackFactory;
hr = pDllGetActivationFactory(classId, fallbackFactory.GetAddressOf());
if (FAILED(hr))
return hr;
ComPtr<IActivationFactory> _factory;
if (IsClassName(classId, "Windows.ApplicationModel.Core.ICoreApplicationResourceAvailability"))
{
hr = RoGetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), IID_PPV_ARGS(&_factory));
*reinterpret_cast<void**>(&TrueCoreApplicationFactory_QueryInterface) = (*reinterpret_cast<void***>(_factory.Get()))[0];
DetourAttach(&TrueCoreApplicationFactory_QueryInterface, CoreApplicationFactory_QueryInterface_Hook);
}
else if (IsClassName(classId, "Windows.ApplicationModel.Core.CoreApplication"))
{
ComPtr<ICoreApplication> ICoreApplicationPtr;
hr = RoGetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), IID_PPV_ARGS(&ICoreApplicationPtr));
*reinterpret_cast<void**>(&TrueGetForCurrentThread_App) = (*reinterpret_cast<void***>(ICoreApplicationPtr.Get()))[6];
DetourAttach(&TrueGetForCurrentThread_App, GetForCurrentThreadCoreApplication_Hook);
}
else if (IsClassName(classId, "Windows.UI.Core.CoreWindow"))
{
ComPtr<ICoreWindowStatic> coreWindowStatic;
hr = RoGetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Core_CoreWindow).Get(), IID_PPV_ARGS(&coreWindowStatic));
*reinterpret_cast<void**>(&TrueGetForCurrentThread) = (*reinterpret_cast<void***>(coreWindowStatic.Get()))[6];
DetourAttach(&TrueGetForCurrentThread, GetForCurrentThread_Hook);
}
else
{
hr = pDllGetActivationFactory(classId, _factory.GetAddressOf());
}
if (FAILED(hr)) return hr;
return _factory.CopyTo(iid, factory);
return fallbackFactory.CopyTo(iid, factory);
}
return hr;

View File

@ -93,8 +93,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="CoreApplicationResourceAvailabilityX.h" />
<ClInclude Include="CoreApplicationX.h" />
<ClInclude Include="CoreApplicationWrapperX.h" />
<ClInclude Include="CoreWindowX.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="hooks.h" />
@ -106,8 +105,7 @@
<ClInclude Include="utils.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="CoreApplicationResourceAvailabilityX.cpp" />
<ClCompile Include="CoreApplicationX.cpp" />
<ClCompile Include="CoreApplicationWrapperX.cpp" />
<ClCompile Include="CoreWindowX.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="kernelx.cpp" />
@ -118,6 +116,7 @@
</ItemGroup>
<ItemGroup>
<None Include=".editorconfig" />
<None Include="cpp.hint" />
<None Include="Exports.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -7,12 +7,9 @@
<ClCompile Include="CoreWindowX.cpp">
<Filter>Windows.UI.Core</Filter>
</ClCompile>
<ClCompile Include="CoreApplicationX.cpp">
<ClCompile Include="CoreApplicationWrapperX.cpp">
<Filter>Windows.ApplicationModel.Core\CoreApplication</Filter>
</ClCompile>
<ClCompile Include="CoreApplicationResourceAvailabilityX.cpp">
<Filter>Windows.ApplicationModel.Core</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
@ -29,19 +26,17 @@
<ClInclude Include="ICoreApplicationX.h">
<Filter>Windows.ApplicationModel.Core\CoreApplication</Filter>
</ClInclude>
<ClInclude Include="CoreApplicationX.h">
<ClInclude Include="CoreApplicationWrapperX.h">
<Filter>Windows.ApplicationModel.Core\CoreApplication</Filter>
</ClInclude>
<ClInclude Include="ICoreApplicationResourceAvailabilityX.h">
<Filter>Windows.ApplicationModel.Core</Filter>
</ClInclude>
<ClInclude Include="CoreApplicationResourceAvailabilityX.h">
<Filter>Windows.ApplicationModel.Core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Exports.def" />
<None Include=".editorconfig" />
<None Include="cpp.hint" />
</ItemGroup>
<ItemGroup>
<Filter Include="Headers">