Skip to content

Commit

Permalink
sapi: Implement ISpeechObjectToken::Invoke.
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunren authored and julliard committed Feb 13, 2024
1 parent b6c1760 commit 001d1a4
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 2 deletions.
1 change: 1 addition & 0 deletions dlls/sapi/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DELAYIMPORTS = winmm
SOURCES = \
async.c \
automation.c \
dispatch.c \
main.c \
mmaudio.c \
resource.c \
Expand Down
85 changes: 85 additions & 0 deletions dlls/sapi/dispatch.c
Original file line number Diff line number Diff line change
@@ -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);
}
9 changes: 9 additions & 0 deletions dlls/sapi/sapi_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
20 changes: 20 additions & 0 deletions dlls/sapi/tests/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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( &params, 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, &params, &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 );
Expand Down
14 changes: 12 additions & 2 deletions dlls/sapi/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 001d1a4

Please sign in to comment.