From 001d1a4319dfb46a4383758a446203350c91edc1 Mon Sep 17 00:00:00 2001 From: Shaun Ren Date: Wed, 7 Feb 2024 20:01:11 -0500 Subject: [PATCH] sapi: Implement ISpeechObjectToken::Invoke. --- dlls/sapi/Makefile.in | 1 + dlls/sapi/dispatch.c | 85 ++++++++++++++++++++++++++++++++++++++++ dlls/sapi/sapi_private.h | 9 +++++ dlls/sapi/tests/token.c | 20 ++++++++++ dlls/sapi/token.c | 14 ++++++- 5 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 dlls/sapi/dispatch.c diff --git a/dlls/sapi/Makefile.in b/dlls/sapi/Makefile.in index 24a1e055766..a6c4d86037e 100644 --- a/dlls/sapi/Makefile.in +++ b/dlls/sapi/Makefile.in @@ -5,6 +5,7 @@ DELAYIMPORTS = winmm SOURCES = \ async.c \ automation.c \ + dispatch.c \ main.c \ mmaudio.c \ resource.c \ diff --git a/dlls/sapi/dispatch.c b/dlls/sapi/dispatch.c new file mode 100644 index 00000000000..df0c6c9bf9c --- /dev/null +++ b/dlls/sapi/dispatch.c @@ -0,0 +1,85 @@ +/* + * ITypeInfo cache for IDispatch + * + * Copyright 2019 Zebediah Figura + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "wine/debug.h" + +#define COBJMACROS + +#include "objbase.h" +#include "sapiddk.h" + +#include "sapi_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(sapi); + +static ITypeLib *typelib; +static ITypeInfo *typeinfos[last_tid]; + +static REFIID tid_id[] = +{ + &IID_ISpeechObjectToken, +}; + +HRESULT get_typeinfo(enum type_id tid, ITypeInfo **ret) +{ + HRESULT hr; + + if (!typelib) + { + ITypeLib *tl; + + hr = LoadRegTypeLib(&LIBID_SpeechLib, 5, 4, LOCALE_SYSTEM_DEFAULT, &tl); + if (FAILED(hr)) + { + ERR("Failed to load typelib, hr %#lx.\n", hr); + return hr; + } + if (InterlockedCompareExchangePointer((void **)&typelib, tl, NULL)) + ITypeLib_Release(tl); + } + if (!typeinfos[tid]) + { + ITypeInfo *typeinfo; + + hr = ITypeLib_GetTypeInfoOfGuid(typelib, tid_id[tid], &typeinfo); + if (FAILED(hr)) + { + ERR("Failed to get type info for %s, hr %#lx.\n", debugstr_guid(tid_id[tid]), hr); + return hr; + } + if (InterlockedCompareExchangePointer((void **)(typeinfos + tid), typeinfo, NULL)) + ITypeInfo_Release(typeinfo); + } + ITypeInfo_AddRef(*ret = typeinfos[tid]); + return S_OK; +} + +void release_typelib(void) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(typeinfos); ++i) + { + if (typeinfos[i]) + ITypeInfo_Release(typeinfos[i]); + } + if (typelib) + ITypeLib_Release(typelib); +} diff --git a/dlls/sapi/sapi_private.h b/dlls/sapi/sapi_private.h index f6a5e966461..9a3c92cc4dc 100644 --- a/dlls/sapi/sapi_private.h +++ b/dlls/sapi/sapi_private.h @@ -52,3 +52,12 @@ HRESULT mmaudio_out_create( IUnknown *outer, REFIID iid, void **obj ); HRESULT token_category_create( IUnknown *outer, REFIID iid, void **obj ); HRESULT token_enum_create( IUnknown *outer, REFIID iid, void **obj ); HRESULT token_create( IUnknown *outer, REFIID iid, void **obj ); + +enum type_id +{ + ISpeechObjectToken_tid, + last_tid +}; + +HRESULT get_typeinfo( enum type_id tid, ITypeInfo **typeinfo ); +void release_typelib( void ); diff --git a/dlls/sapi/tests/token.c b/dlls/sapi/tests/token.c index a651eb47c62..ec8a101fea4 100644 --- a/dlls/sapi/tests/token.c +++ b/dlls/sapi/tests/token.c @@ -26,6 +26,8 @@ #include "wine/test.h" +DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); + static void test_data_key(void) { ISpRegDataKey *data_key; @@ -669,6 +671,8 @@ static void test_object_token(void) ISpObjectTokenCategory *cat; DWORD regid; IUnknown *obj; + DISPPARAMS params; + VARIANT arg, ret; hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER, &IID_ISpObjectToken, (void **)&token ); @@ -915,6 +919,22 @@ static void test_object_token(void) ok( tempB && !wcscmp( tempB, L"TestToken" ), "got %s\n", wine_dbgstr_w( tempB ) ); SysFreeString( tempB ); + memset( ¶ms, 0, sizeof(params) ); + params.cArgs = 1; + params.cNamedArgs = 0; + params.rgvarg = &arg; + VariantInit( &arg ); + V_VT( &arg ) = VT_I4; + V_I4( &arg ) = 0x409; + VariantInit( &ret ); + hr = ISpeechObjectToken_Invoke( speech_token, DISPID_SOTGetDescription, &IID_NULL, + 0, DISPATCH_METHOD, ¶ms, &ret, NULL, NULL ); + ok( hr == S_OK, "got %08lx\n", hr ); + ok( V_VT( &ret ) == VT_BSTR, "got %#x\n", V_VT( &ret ) ); + ok( V_BSTR( &ret ) && !wcscmp( V_BSTR( &ret ), L"409 - TestToken" ), + "got %s\n", wine_dbgstr_w( V_BSTR( &ret ) ) ); + VariantClear( &ret ); + ISpeechObjectToken_Release( speech_token ); ISpObjectToken_Release( test_class_token ); diff --git a/dlls/sapi/token.c b/dlls/sapi/token.c index e5d87505e34..c8cb806bbae 100644 --- a/dlls/sapi/token.c +++ b/dlls/sapi/token.c @@ -1801,8 +1801,18 @@ static HRESULT WINAPI speech_token_Invoke( ISpeechObjectToken *iface, EXCEPINFO *excepinfo, UINT *argerr ) { - FIXME( "stub\n" ); - return E_NOTIMPL; + ITypeInfo *ti; + HRESULT hr; + + TRACE( "(%p)->(%ld %s %#lx %#x %p %p %p %p)\n", iface, dispid, + debugstr_guid( iid ), lcid, flags, params, result, excepinfo, argerr ); + + if (FAILED(hr = get_typeinfo( ISpeechObjectToken_tid, &ti ))) + return hr; + hr = ITypeInfo_Invoke( ti, iface, dispid, flags, params, result, excepinfo, argerr ); + ITypeInfo_Release( ti ); + + return hr; } static HRESULT WINAPI speech_token_get_Id( ISpeechObjectToken *iface,