diff --git a/NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp b/NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp index f1ec92c5..a213f41b 100644 --- a/NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp +++ b/NanaZip.Frieren/NanaZip.Frieren.DarkMode.cpp @@ -1,9 +1,9 @@ /* - * PROJECT: NanaZip - * FILE: NanaZip.Frieren.DarkMode.cpp - * PURPOSE: Implementation for NanaZip dark mode support + * PROJECT: NanaZip + * FILE: NanaZip.Frieren.DarkMode.cpp + * PURPOSE: Implementation for NanaZip dark mode support * - * LICENSE: The MIT License + * LICENSE: The MIT License * * MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com) */ @@ -35,222 +35,6 @@ EXTERN_C HTHEME WINAPI OpenNcThemeData( namespace { - static HMODULE GetSHCoreModuleHandle() - { - static HMODULE CachedResult = ::GetModuleHandleW(L"SHCore.dll"); - return CachedResult; - } - - static FARPROC GetGetDpiForMonitorProcAddress() - { - static FARPROC CachedResult = ([]() -> FARPROC - { - HMODULE ModuleHandle = ::GetSHCoreModuleHandle(); - if (ModuleHandle) - { - return ::GetProcAddress( - ModuleHandle, - "GetDpiForMonitor"); - } - return nullptr; - }()); - - return CachedResult; - } - - static HMODULE GetUser32ModuleHandle() - { - static HMODULE CachedResult = ::GetModuleHandleW(L"user32.dll"); - return CachedResult; - } - - static FARPROC GetGetDisplayConfigBufferSizesProcAddress() - { - static FARPROC CachedResult = ([]() -> FARPROC - { - HMODULE ModuleHandle = ::GetUser32ModuleHandle(); - if (ModuleHandle) - { - return ::GetProcAddress( - ModuleHandle, - "GetDisplayConfigBufferSizes"); - } - return nullptr; - }()); - - return CachedResult; - } - - static FARPROC GetQueryDisplayConfigProcAddress() - { - static FARPROC CachedResult = ([]() -> FARPROC - { - HMODULE ModuleHandle = ::GetUser32ModuleHandle(); - if (ModuleHandle) - { - return ::GetProcAddress( - ModuleHandle, - "QueryDisplayConfig"); - } - return nullptr; - }()); - - return CachedResult; - } - - static FARPROC GetDisplayConfigGetDeviceInfoProcAddress() - { - static FARPROC CachedResult = ([]() -> FARPROC - { - HMODULE ModuleHandle = ::GetUser32ModuleHandle(); - if (ModuleHandle) - { - return ::GetProcAddress( - ModuleHandle, - "DisplayConfigGetDeviceInfo"); - } - return nullptr; - }()); - - return CachedResult; - } - - static FARPROC GetGetDpiForWindowProcAddress() - { - static FARPROC CachedResult = ([]() -> FARPROC - { - HMODULE ModuleHandle = ::GetUser32ModuleHandle(); - if (ModuleHandle) - { - return ::GetProcAddress( - ModuleHandle, - "GetDpiForWindow"); - } - return nullptr; - }()); - - return CachedResult; - } - - static LONG WINAPI GetDisplayConfigBufferSizesWrapper( - _In_ UINT32 flags, - _Out_ UINT32* numPathArrayElements, - _Out_ UINT32* numModeInfoArrayElements) - { - using ProcType = decltype(::GetDisplayConfigBufferSizes)*; - - ProcType ProcAddress = reinterpret_cast( - ::GetGetDisplayConfigBufferSizesProcAddress()); - - if (ProcAddress) - { - return ProcAddress( - flags, - numPathArrayElements, - numModeInfoArrayElements); - } - - return ERROR_NOT_SUPPORTED; - } - - static LONG WINAPI QueryDisplayConfigWrapper( - _In_ UINT32 flags, - _Inout_ UINT32* numPathArrayElements, - _Out_ DISPLAYCONFIG_PATH_INFO* pathArray, - _Inout_ UINT32* numModeInfoArrayElements, - _Out_ DISPLAYCONFIG_MODE_INFO* modeInfoArray, - _Out_opt_ DISPLAYCONFIG_TOPOLOGY_ID* currentTopologyId) - { - using ProcType = decltype(::QueryDisplayConfig)*; - - ProcType ProcAddress = reinterpret_cast( - ::GetQueryDisplayConfigProcAddress()); - - if (ProcAddress) - { - return ProcAddress( - flags, - numPathArrayElements, - pathArray, - numModeInfoArrayElements, - modeInfoArray, - currentTopologyId); - } - - return ERROR_NOT_SUPPORTED; - } - - static LONG WINAPI DisplayConfigGetDeviceInfoWrapper( - _Inout_ DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket) - { - using ProcType = decltype(::DisplayConfigGetDeviceInfo)*; - - ProcType ProcAddress = reinterpret_cast( - ::GetDisplayConfigGetDeviceInfoProcAddress()); - - if (ProcAddress) - { - return ProcAddress(requestPacket); - } - - return ERROR_NOT_SUPPORTED; - } - - static UINT WINAPI GetDpiForWindowWrapper( - _In_ HWND hWnd) - { - { - using ProcType = decltype(::GetDpiForWindow)*; - - ProcType ProcAddress = reinterpret_cast( - ::GetGetDpiForWindowProcAddress()); - - if (ProcAddress) - { - return ProcAddress(hWnd); - } - } - - { - using ProcType = decltype(::GetDpiForMonitor)*; - - ProcType ProcAddress = reinterpret_cast( - ::GetGetDpiForMonitorProcAddress()); - - if (ProcAddress) - { - HMONITOR MonitorHandle = ::MonitorFromWindow( - hWnd, - MONITOR_DEFAULTTONEAREST); - if (MonitorHandle) - { - UINT DpiX = 0; - UINT DpiY = 0; - if (SUCCEEDED(ProcAddress( - MonitorHandle, - MDT_EFFECTIVE_DPI, - &DpiX, - &DpiY))) - { - return DpiX; - } - } - } - } - - UINT DpiValue = USER_DEFAULT_SCREEN_DPI; - { - HDC WindowContextHandle = ::GetDC(hWnd); - if (WindowContextHandle) - { - DpiValue = ::GetDeviceCaps(WindowContextHandle, LOGPIXELSX); - ::ReleaseDC(hWnd, WindowContextHandle); - } - } - - return DpiValue; - } - static bool IsStandardDynamicRangeMode() { static bool CachedResult = ([]() -> bool @@ -259,7 +43,7 @@ namespace UINT32 NumPathArrayElements = 0; UINT32 NumModeInfoArrayElements = 0; - if (ERROR_SUCCESS == ::GetDisplayConfigBufferSizesWrapper( + if (ERROR_SUCCESS == ::GetDisplayConfigBufferSizes( QDC_ONLY_ACTIVE_PATHS, &NumPathArrayElements, &NumModeInfoArrayElements)) @@ -268,7 +52,7 @@ namespace NumPathArrayElements); std::vector ModeInfoArray( NumModeInfoArrayElements); - if (ERROR_SUCCESS == ::QueryDisplayConfigWrapper( + if (ERROR_SUCCESS == ::QueryDisplayConfig( QDC_ONLY_ACTIVE_PATHS, &NumPathArrayElements, &PathArray[0], @@ -292,7 +76,7 @@ namespace AdvancedColorInfo.header.id = Path.targetInfo.id; if (ERROR_SUCCESS == - ::DisplayConfigGetDeviceInfoWrapper( + ::DisplayConfigGetDeviceInfo( &AdvancedColorInfo.header)) { if (AdvancedColorInfo.advancedColorEnabled) @@ -554,7 +338,7 @@ namespace } else if (::IsFileManagerWindow(hWnd)) { - UINT DpiValue = ::GetDpiForWindowWrapper(hWnd); + UINT DpiValue = ::GetDpiForWindow(hWnd); Margins.cyTopHeight = ::MulDiv(80, DpiValue, USER_DEFAULT_SCREEN_DPI); Margins.cyBottomHeight = @@ -606,7 +390,7 @@ namespace } else if (::IsFileManagerWindow(hWnd)) { - UINT DpiValue = ::GetDpiForWindowWrapper(hWnd); + UINT DpiValue = ::GetDpiForWindow(hWnd); MARGINS Margins = { 0 }; Margins.cyTopHeight = @@ -669,7 +453,7 @@ namespace g_MicaBackdropAvailable); if (!ShouldExtendFrame && ::IsFileManagerWindow(hWnd)) { - UINT DpiValue = ::GetDpiForWindowWrapper(hWnd); + UINT DpiValue = ::GetDpiForWindow(hWnd); MARGINS Margins = { 0 }; Margins.cyTopHeight = diff --git a/NanaZip.Frieren/NanaZip.Frieren.RuntimeObjectWrapper.cpp b/NanaZip.Frieren/NanaZip.Frieren.RuntimeObjectWrapper.cpp deleted file mode 100644 index af0562f3..00000000 --- a/NanaZip.Frieren/NanaZip.Frieren.RuntimeObjectWrapper.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/* - * PROJECT: NanaZip - * FILE: NanaZip.Frieren.RuntimeObjectWrapper.cpp - * PURPOSE: Implementation for Windows Runtime C API Wrapper - * - * LICENSE: The MIT License - * - * MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com) - */ - -#include - -#define _ROAPI_ -#include - -#include - -#include -#include - -// WINDOWS_RUNTIME_HSTRING_FLAGS - -#define WRHF_NONE 0x00000000 -#define WRHF_STRING_REFERENCE 0x00000001 -#define WRHF_VALID_UNICODE_FORMAT_INFO 0x00000002 -#define WRHF_WELL_FORMED_UNICODE 0x00000004 -#define WRHF_HAS_EMBEDDED_NULLS 0x00000008 -#define WRHF_EMBEDDED_NULLS_COMPUTED 0x00000010 -#define WRHF_RESERVED_FOR_PREALLOCATED_STRING_BUFFER 0x80000000 - -typedef struct _HSTRING_HEADER_INTERNAL -{ - UINT32 Flags; - UINT32 Length; - UINT32 Padding1; - UINT32 Padding2; - PCWSTR StringRef; -} HSTRING_HEADER_INTERNAL; - -#include - -namespace -{ - static HMODULE GetComBaseModuleHandle() - { - static HMODULE CachedResult = ::LoadLibraryExW( - L"combase.dll", - nullptr, - LOAD_LIBRARY_SEARCH_SYSTEM32); - return CachedResult; - } - - static FARPROC GetRoGetActivationFactoryProcAddress() - { - static FARPROC CachedResult = ([]() -> FARPROC - { - HMODULE ModuleHandle = ::GetComBaseModuleHandle(); - if (ModuleHandle) - { - return ::GetProcAddress( - ModuleHandle, - "RoGetActivationFactory"); - } - return nullptr; - }()); - - return CachedResult; - } - - static FARPROC GetRoOriginateLanguageExceptionProcAddress() - { - static FARPROC CachedResult = ([]() -> FARPROC - { - HMODULE ModuleHandle = ::GetComBaseModuleHandle(); - if (ModuleHandle) - { - return ::GetProcAddress( - ModuleHandle, - "RoOriginateLanguageException"); - } - return nullptr; - }()); - - return CachedResult; - } - - struct ErrorInfoFallback : public Mile::ComObject< - ErrorInfoFallback, - IErrorInfo, - IRestrictedErrorInfo> - { - private: - - HRESULT m_Code; - BSTR m_Message; - - public: - - ErrorInfoFallback( - _In_ HRESULT Code, - _In_opt_ HSTRING Message) : - m_Code(Code), - m_Message(::SysAllocString(Message - ? reinterpret_cast( - this->m_Message)->StringRef - : nullptr)) - { - - } - - ~ErrorInfoFallback() - { - ::SysFreeString(this->m_Message); - } - - HRESULT STDMETHODCALLTYPE GetGUID( - _Out_ GUID* pGUID) - { - std::memset(pGUID, 0, sizeof(GUID)); - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetSource( - _Out_ BSTR* pBstrSource) - { - *pBstrSource = nullptr; - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetDescription( - _Out_ BSTR* pBstrDescription) - { - *pBstrDescription = ::SysAllocString(this->m_Message); - return *pBstrDescription ? S_OK : E_OUTOFMEMORY; - } - - HRESULT STDMETHODCALLTYPE GetHelpFile( - _Out_ BSTR* pBstrHelpFile) - { - *pBstrHelpFile = nullptr; - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetHelpContext( - _Out_ DWORD* pdwHelpContext) - { - *pdwHelpContext = 0; - return S_OK; - } - - HRESULT STDMETHODCALLTYPE GetErrorDetails( - _Out_ BSTR* description, - _Out_ HRESULT* error, - _Out_ BSTR* restrictedDescription, - _Out_ BSTR* capabilitySid) - { - *description = nullptr; - *error = this->m_Code; - *capabilitySid = nullptr; - *restrictedDescription = ::SysAllocString(this->m_Message); - return *restrictedDescription ? S_OK : E_OUTOFMEMORY; - } - - virtual HRESULT STDMETHODCALLTYPE GetReference( - _Out_ BSTR* reference) - { - *reference = nullptr; - return S_OK; - } - }; - - static FARPROC GetRoFailFastWithErrorContextProcAddress() - { - static FARPROC CachedResult = ([]() -> FARPROC - { - HMODULE ModuleHandle = ::GetComBaseModuleHandle(); - if (ModuleHandle) - { - return ::GetProcAddress( - ModuleHandle, - "RoFailFastWithErrorContext"); - } - return nullptr; - }()); - - return CachedResult; - } -} - -EXTERN_C HRESULT WINAPI RoGetActivationFactory( - _In_ HSTRING activatableClassId, - _In_ REFIID iid, - _Out_ LPVOID* factory) -{ - using ProcType = decltype(::RoGetActivationFactory)*; - - ProcType ProcAddress = reinterpret_cast( - ::GetRoGetActivationFactoryProcAddress()); - - if (ProcAddress) - { - return ProcAddress(activatableClassId, iid, factory); - } - - *factory = nullptr; - return CLASS_E_CLASSNOTAVAILABLE; -} - -EXTERN_C BOOL WINAPI RoOriginateLanguageException( - _In_ HRESULT error, - _In_opt_ HSTRING message, - _In_opt_ IUnknown* languageException) -{ - using ProcType = decltype(::RoOriginateLanguageException)*; - - ProcType ProcAddress = reinterpret_cast( - ::GetRoOriginateLanguageExceptionProcAddress()); - - if (ProcAddress) - { - return ProcAddress(error, message, languageException); - } - - IErrorInfo* ErrorInfo = new ErrorInfoFallback(error, message); - ::SetErrorInfo(0, ErrorInfo); - return TRUE; -} - -EXTERN_C VOID WINAPI RoFailFastWithErrorContext( - _In_ HRESULT hrError) -{ - using ProcType = decltype(::RoFailFastWithErrorContext)*; - - ProcType ProcAddress = reinterpret_cast( - ::GetRoFailFastWithErrorContextProcAddress()); - - if (ProcAddress) - { - ProcAddress(hrError); - } - - std::abort(); -} diff --git a/NanaZip.Frieren/NanaZip.Frieren.cpp b/NanaZip.Frieren/NanaZip.Frieren.cpp index 524e14cf..97b94b13 100644 --- a/NanaZip.Frieren/NanaZip.Frieren.cpp +++ b/NanaZip.Frieren/NanaZip.Frieren.cpp @@ -1,9 +1,9 @@ /* - * PROJECT: NanaZip - * FILE: NanaZip.Frieren.cpp - * PURPOSE: Implementation for NanaZip.Frieren + * PROJECT: NanaZip + * FILE: NanaZip.Frieren.cpp + * PURPOSE: Implementation for NanaZip.Frieren * - * LICENSE: The MIT License + * LICENSE: The MIT License * * MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com) */ diff --git a/NanaZip.Frieren/NanaZip.Frieren.h b/NanaZip.Frieren/NanaZip.Frieren.h index b10af64c..2a844722 100644 --- a/NanaZip.Frieren/NanaZip.Frieren.h +++ b/NanaZip.Frieren/NanaZip.Frieren.h @@ -1,9 +1,9 @@ /* - * PROJECT: NanaZip - * FILE: NanaZip.Frieren.h - * PURPOSE: Definition for NanaZip.Frieren + * PROJECT: NanaZip + * FILE: NanaZip.Frieren.h + * PURPOSE: Definition for NanaZip.Frieren * - * LICENSE: The MIT License + * LICENSE: The MIT License * * MAINTAINER: MouriNaruto (Kenji.Mouri@outlook.com) */ diff --git a/NanaZip.Frieren/NanaZip.Frieren.props b/NanaZip.Frieren/NanaZip.Frieren.props index a8217b9b..53089ab8 100644 --- a/NanaZip.Frieren/NanaZip.Frieren.props +++ b/NanaZip.Frieren/NanaZip.Frieren.props @@ -14,7 +14,7 @@ - $(OutDir)NanaZip.Frieren.lib;%(AdditionalDependencies) + $(OutDir)NanaZip.Frieren.lib;runtimeobject.lib;%(AdditionalDependencies) diff --git a/NanaZip.Frieren/NanaZip.Frieren.vcxproj b/NanaZip.Frieren/NanaZip.Frieren.vcxproj index 18f4a5d7..46b1d83a 100644 --- a/NanaZip.Frieren/NanaZip.Frieren.vcxproj +++ b/NanaZip.Frieren/NanaZip.Frieren.vcxproj @@ -26,7 +26,6 @@ -