From 1af0dbe36e135dce25ac0b39907550a7434c5ecc Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Sun, 17 Mar 2024 11:55:19 +0900 Subject: [PATCH] [MSUTB][SDK] Use QISearch for QueryInterface (#6631) Simplify code and reduce binary size. JIRA issue: CORE-19363 - Use shlwapi!QISearch for QueryInterface implementation. - Add delay link to shlwapi. - Define QITABENT macro in . --- dll/win32/msutb/CMakeLists.txt | 2 +- dll/win32/msutb/msutb.cpp | 68 ++++++++++++---------------------- sdk/include/psdk/shlwapi.h | 3 ++ 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/dll/win32/msutb/CMakeLists.txt b/dll/win32/msutb/CMakeLists.txt index c63dbb11cb2..df523425cff 100644 --- a/dll/win32/msutb/CMakeLists.txt +++ b/dll/win32/msutb/CMakeLists.txt @@ -15,5 +15,5 @@ set_module_type(msutb win32dll UNICODE) add_dependencies(msutb msctf psdk) target_link_libraries(msutb wine uuid atl_classes cicero) add_importlibs(msutb user32 gdi32 advapi32 msvcrt kernel32 ntdll) -add_delay_importlibs(msutb uxtheme imm32 comctl32 msctf ole32 oleacc oleaut32 shell32) +add_delay_importlibs(msutb uxtheme imm32 shlwapi comctl32 msctf ole32 oleacc oleaut32 shell32) add_cd_file(TARGET msutb DESTINATION reactos/system32 FOR all) diff --git a/dll/win32/msutb/msutb.cpp b/dll/win32/msutb/msutb.cpp index b81e2e23ba1..4f307c3e82d 100644 --- a/dll/win32/msutb/msutb.cpp +++ b/dll/win32/msutb/msutb.cpp @@ -1887,13 +1887,12 @@ CCicLibMenu::~CCicLibMenu() STDMETHODIMP CCicLibMenu::QueryInterface(REFIID riid, LPVOID *ppvObj) { - if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfMenu)) + static const QITAB c_tab[] = { - *ppvObj = this; - AddRef(); - return S_OK; - } - return E_NOINTERFACE; + QITABENT(CCicLibMenu, ITfMenu), + { NULL } + }; + return ::QISearch(this, c_tab, riid, ppvObj); } STDMETHODIMP_(ULONG) CCicLibMenu::AddRef() @@ -2191,15 +2190,13 @@ STDMETHODIMP CTipbarAccessible::QueryInterface( REFIID riid, void **ppvObject) { - if (IsEqualIID(riid, IID_IUnknown) || - IsEqualIID(riid, IID_IDispatch) || - IsEqualIID(riid, IID_IAccessible)) + static const QITAB c_tab[] = { - *ppvObject = this; - AddRef(); - return S_OK; - } - return E_NOINTERFACE; + QITABENT(CTipbarAccessible, IDispatch), + QITABENT(CTipbarAccessible, IAccessible), + { NULL } + }; + return ::QISearch(this, c_tab, riid, ppvObject); } STDMETHODIMP_(ULONG) CTipbarAccessible::AddRef() @@ -3667,25 +3664,14 @@ CLBarItemButtonBase::~CLBarItemButtonBase() STDMETHODIMP CLBarItemButtonBase::QueryInterface(REFIID riid, void **ppvObject) { - if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfLangBarItem)) + static const QITAB c_tab[] = { - *ppvObject = static_cast(this); - AddRef(); - return S_OK; - } - if (IsEqualIID(riid, IID_ITfLangBarItemButton)) - { - *ppvObject = static_cast(this); - AddRef(); - return S_OK; - } - if (IsEqualIID(riid, IID_ITfSource)) - { - *ppvObject = static_cast(this); - AddRef(); - return S_OK; - } - return E_NOINTERFACE; + QITABENT(CLBarItemButtonBase, ITfLangBarItem), + QITABENT(CLBarItemButtonBase, ITfLangBarItemButton), + QITABENT(CLBarItemButtonBase, ITfSource), + { NULL } + }; + return ::QISearch(this, c_tab, riid, ppvObject); } STDMETHODIMP_(ULONG) CLBarItemButtonBase::AddRef() @@ -5148,19 +5134,13 @@ void CTipbarWnd::TerminateAllThreads(BOOL bFlag) STDMETHODIMP CTipbarWnd::QueryInterface(REFIID riid, void **ppvObj) { - if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfLangBarEventSink)) + static const QITAB c_tab[] = { - *ppvObj = this; - AddRef(); - return S_OK; - } - if (IsEqualIID(riid, IID_ITfLangBarEventSink_P)) - { - *ppvObj = static_cast(this); - AddRef(); - return S_OK; - } - return E_NOINTERFACE; + QITABENT(CTipbarWnd, ITfLangBarEventSink), + QITABENT(CTipbarWnd, ITfLangBarEventSink_P), + { NULL } + }; + return ::QISearch(this, c_tab, riid, ppvObj); } STDMETHODIMP_(ULONG) CTipbarWnd::AddRef() diff --git a/sdk/include/psdk/shlwapi.h b/sdk/include/psdk/shlwapi.h index 801928fff4b..84b95db43ff 100644 --- a/sdk/include/psdk/shlwapi.h +++ b/sdk/include/psdk/shlwapi.h @@ -2090,6 +2090,9 @@ QISearch( #define OFFSETOFCLASS(base, derived) \ ((DWORD)(DWORD_PTR)(static_cast((derived*)8))-8) +#define QITABENTMULTI(Cthis, Ifoo, Iimpl) { &IID_##Ifoo, OFFSETOFCLASS(Iimpl, Cthis) } +#define QITABENT(Cthis, Ifoo) QITABENTMULTI(Cthis, Ifoo, Ifoo) + #include #ifdef __cplusplus