Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- configure.ac | 2 + dlls/windows.gaming.input/Makefile.in | 9 + dlls/windows.gaming.input/classes.idl | 23 +++ dlls/windows.gaming.input/main.c | 159 ++++++++++++++++++ dlls/windows.gaming.input/tests/Makefile.in | 5 + dlls/windows.gaming.input/tests/statics.c | 150 +++++++++++++++++ .../windows.gaming.input.spec | 3 + include/Makefile.in | 1 + 8 files changed, 352 insertions(+) create mode 100644 dlls/windows.gaming.input/Makefile.in create mode 100644 dlls/windows.gaming.input/classes.idl create mode 100644 dlls/windows.gaming.input/main.c create mode 100644 dlls/windows.gaming.input/tests/Makefile.in create mode 100644 dlls/windows.gaming.input/tests/statics.c create mode 100644 dlls/windows.gaming.input/windows.gaming.input.spec
diff --git a/configure.ac b/configure.ac index 8c092fb020c..6c2e9fa57ad 100644 --- a/configure.ac +++ b/configure.ac @@ -3801,6 +3801,8 @@ WINE_CONFIG_MAKEFILE(dlls/win32s16.dll16,enable_win16) WINE_CONFIG_MAKEFILE(dlls/win87em.dll16,enable_win16) WINE_CONFIG_MAKEFILE(dlls/winaspi.dll16,enable_win16) WINE_CONFIG_MAKEFILE(dlls/windebug.dll16,enable_win16) +WINE_CONFIG_MAKEFILE(dlls/windows.gaming.input) +WINE_CONFIG_MAKEFILE(dlls/windows.gaming.input/tests) WINE_CONFIG_MAKEFILE(dlls/windows.media.speech) WINE_CONFIG_MAKEFILE(dlls/windows.media.speech/tests) WINE_CONFIG_MAKEFILE(dlls/windowscodecs) diff --git a/dlls/windows.gaming.input/Makefile.in b/dlls/windows.gaming.input/Makefile.in new file mode 100644 index 00000000000..1673eaabaa7 --- /dev/null +++ b/dlls/windows.gaming.input/Makefile.in @@ -0,0 +1,9 @@ +MODULE = windows.gaming.input.dll +IMPORTS = combase uuid + +EXTRADLLFLAGS = -mno-cygwin + +C_SRCS = \ + main.c + +IDL_SRCS = classes.idl diff --git a/dlls/windows.gaming.input/classes.idl b/dlls/windows.gaming.input/classes.idl new file mode 100644 index 00000000000..c9cb91e3182 --- /dev/null +++ b/dlls/windows.gaming.input/classes.idl @@ -0,0 +1,23 @@ +/* + * Runtime Classes for windows.gaming.input.dll + * + * Copyright 2021 Rémi Bernon for CodeWeavers + * + * 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 + */ + +#pragma makedep register + +#include "windows.gaming.input.idl" diff --git a/dlls/windows.gaming.input/main.c b/dlls/windows.gaming.input/main.c new file mode 100644 index 00000000000..05ef844893b --- /dev/null +++ b/dlls/windows.gaming.input/main.c @@ -0,0 +1,159 @@ +/* WinRT Windows.Gaming.Input implementation + * + * Copyright 2021 Rémi Bernon for CodeWeavers + * + * 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 <stdarg.h> + +#define COBJMACROS +#include "windef.h" +#include "winbase.h" +#include "winstring.h" +#include "wine/debug.h" +#include "objbase.h" + +#include "initguid.h" +#include "activation.h" + +#include "windows.foundation.h" +#include "windows.gaming.input.h" + +WINE_DEFAULT_DEBUG_CHANNEL(input); + +static const char *debugstr_hstring(HSTRING hstr) +{ + const WCHAR *str; + UINT32 len; + if (hstr && !((ULONG_PTR)hstr >> 16)) return "(invalid)"; + str = WindowsGetStringRawBuffer(hstr, &len); + return wine_dbgstr_wn(str, len); +} + +struct windows_gaming_input +{ + IActivationFactory IActivationFactory_iface; + LONG ref; +}; + +static inline struct windows_gaming_input *impl_from_IActivationFactory(IActivationFactory *iface) +{ + return CONTAINING_RECORD(iface, struct windows_gaming_input, IActivationFactory_iface); +} + +static HRESULT STDMETHODCALLTYPE windows_gaming_input_QueryInterface( + IActivationFactory *iface, REFIID iid, void **out) +{ + TRACE("iface %p, iid %s, out %p stub!\n", iface, debugstr_guid(iid), out); + + if (IsEqualGUID(iid, &IID_IUnknown) || + IsEqualGUID(iid, &IID_IInspectable) || + IsEqualGUID(iid, &IID_IAgileObject) || + IsEqualGUID(iid, &IID_IActivationFactory)) + { + IUnknown_AddRef(iface); + *out = iface; + return S_OK; + } + + FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG STDMETHODCALLTYPE windows_gaming_input_AddRef( + IActivationFactory *iface) +{ + struct windows_gaming_input *impl = impl_from_IActivationFactory(iface); + ULONG ref = InterlockedIncrement(&impl->ref); + TRACE("iface %p, ref %u.\n", iface, ref); + return ref; +} + +static ULONG STDMETHODCALLTYPE windows_gaming_input_Release( + IActivationFactory *iface) +{ + struct windows_gaming_input *impl = impl_from_IActivationFactory(iface); + ULONG ref = InterlockedDecrement(&impl->ref); + TRACE("iface %p, ref %u.\n", iface, ref); + return ref; +} + +static HRESULT STDMETHODCALLTYPE windows_gaming_input_GetIids( + IActivationFactory *iface, ULONG *iid_count, IID **iids) +{ + FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE windows_gaming_input_GetRuntimeClassName( + IActivationFactory *iface, HSTRING *class_name) +{ + FIXME("iface %p, class_name %p stub!\n", iface, class_name); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE windows_gaming_input_GetTrustLevel( + IActivationFactory *iface, TrustLevel *trust_level) +{ + FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE windows_gaming_input_ActivateInstance( + IActivationFactory *iface, IInspectable **instance) +{ + FIXME("iface %p, instance %p stub!\n", iface, instance); + return E_NOTIMPL; +} + +static const struct IActivationFactoryVtbl activation_factory_vtbl = +{ + windows_gaming_input_QueryInterface, + windows_gaming_input_AddRef, + windows_gaming_input_Release, + /* IInspectable methods */ + windows_gaming_input_GetIids, + windows_gaming_input_GetRuntimeClassName, + windows_gaming_input_GetTrustLevel, + /* IActivationFactory methods */ + windows_gaming_input_ActivateInstance, +}; + +static struct windows_gaming_input windows_gaming_input = +{ + {&activation_factory_vtbl}, + 1 +}; + +HRESULT WINAPI DllCanUnloadNow(void) +{ + return S_FALSE; +} + +HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void **out) +{ + FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid), debugstr_guid(riid), out); + return CLASS_E_CLASSNOTAVAILABLE; +} + +HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **factory) +{ + TRACE("classid %s, factory %p.\n", debugstr_hstring(classid), factory); + *factory = &windows_gaming_input.IActivationFactory_iface; + IUnknown_AddRef(*factory); + return S_OK; +} diff --git a/dlls/windows.gaming.input/tests/Makefile.in b/dlls/windows.gaming.input/tests/Makefile.in new file mode 100644 index 00000000000..08c8368e883 --- /dev/null +++ b/dlls/windows.gaming.input/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = windows.gaming.input.dll +IMPORTS = uuid + +C_SRCS = \ + statics.c diff --git a/dlls/windows.gaming.input/tests/statics.c b/dlls/windows.gaming.input/tests/statics.c new file mode 100644 index 00000000000..8144a3fb8e8 --- /dev/null +++ b/dlls/windows.gaming.input/tests/statics.c @@ -0,0 +1,150 @@ +/* + * Copyright 2021 Rémi Bernon for CodeWeavers + * + * 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 + */ +#define COBJMACROS +#include <stdarg.h> + +#include "windef.h" +#include "winbase.h" +#include "winerror.h" +#include "winstring.h" + +#include "initguid.h" +#include "roapi.h" + +#define WIDL_using_Windows_Foundation +#define WIDL_using_Windows_Foundation_Collections +#include "windows.foundation.h" +#define WIDL_using_Windows_Gaming_Input +#include "windows.gaming.input.h" + +#include "wine/test.h" + +static HRESULT (WINAPI *pRoActivateInstance)(HSTRING, IInspectable **); +static HRESULT (WINAPI *pRoGetActivationFactory)(HSTRING, REFIID, void **); +static HRESULT (WINAPI *pRoInitialize)(RO_INIT_TYPE); +static void (WINAPI *pRoUninitialize)(void); +static HRESULT (WINAPI *pWindowsCreateString)(LPCWSTR, UINT32, HSTRING *); +static HRESULT (WINAPI *pWindowsDeleteString)(HSTRING); + +static void test_Gamepad(void) +{ + static const WCHAR *gamepad_name = L"Windows.Gaming.Input.Gamepad"; + + IVectorView_Gamepad *gamepads = NULL; + IActivationFactory *factory = NULL; + IGamepadStatics *gamepad_statics = NULL; + IInspectable *inspectable = NULL, *tmp_inspectable = NULL; + IAgileObject *agile_object = NULL, *tmp_agile_object = NULL; + HSTRING str; + HRESULT hr; + ULONG rc, size; + + hr = pRoInitialize(RO_INIT_MULTITHREADED); + ok(SUCCEEDED(hr), "RoInitialize failed, hr %#x\n", hr); + + hr = pWindowsCreateString(gamepad_name, wcslen(gamepad_name), &str); + ok(SUCCEEDED(hr), "WindowsCreateString failed, hr %#x\n", hr); + + hr = pRoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory); + ok(SUCCEEDED(hr) || broken(hr == REGDB_E_CLASSNOTREG), "RoGetActivationFactory failed, hr %#x\n", hr); + if (hr == REGDB_E_CLASSNOTREG) + { + win_skip("%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w(gamepad_name)); + return; + } + + hr = IActivationFactory_QueryInterface(factory, &IID_IInspectable, (void **)&inspectable); + ok(SUCCEEDED(hr), "IActivationFactory_QueryInterface IID_IInspectable failed, hr %#x\n", hr); + + hr = IActivationFactory_QueryInterface(factory, &IID_IAgileObject, (void **)&agile_object); + ok(SUCCEEDED(hr), "IActivationFactory_QueryInterface IID_IAgileObject failed, hr %#x\n", hr); + + hr = IActivationFactory_QueryInterface(factory, &IID_IGamepadStatics, (void **)&gamepad_statics); + todo_wine ok(SUCCEEDED(hr), "IActivationFactory_QueryInterface IID_IGamepadStatics failed, hr %#x\n", hr); + if (FAILED(hr)) goto done; + + hr = IGamepadStatics_QueryInterface(gamepad_statics, &IID_IInspectable, (void **)&tmp_inspectable); + ok(SUCCEEDED(hr), "IGamepadStatics_QueryInterface IID_IInspectable failed, hr %#x\n", hr); + ok(tmp_inspectable == inspectable, "IGamepadStatics_QueryInterface IID_IInspectable returned %p, expected %p\n", tmp_inspectable, inspectable); + IInspectable_Release(tmp_inspectable); + + hr = IGamepadStatics_QueryInterface(gamepad_statics, &IID_IAgileObject, (void **)&tmp_agile_object); + ok(SUCCEEDED(hr), "IGamepadStatics_QueryInterface IID_IAgileObject failed, hr %#x\n", hr); + ok(tmp_agile_object == agile_object, "IGamepadStatics_QueryInterface IID_IAgileObject returned %p, expected %p\n", tmp_agile_object, agile_object); + IAgileObject_Release(tmp_agile_object); + + hr = IGamepadStatics_get_Gamepads(gamepad_statics, &gamepads); + ok(SUCCEEDED(hr), "IGamepadStatics_get_Gamepads failed, hr %#x\n", hr); + + hr = IVectorView_Gamepad_QueryInterface(gamepads, &IID_IInspectable, (void **)&tmp_inspectable); + ok(SUCCEEDED(hr), "IVectorView_Gamepad_QueryInterface failed, hr %#x\n", hr); + ok(tmp_inspectable != inspectable, "IVectorView_Gamepad_QueryInterface returned %p, expected %p\n", tmp_inspectable, inspectable); + IInspectable_Release(tmp_inspectable); + + hr = IVectorView_Gamepad_QueryInterface(gamepads, &IID_IAgileObject, (void **)&tmp_agile_object); + ok(SUCCEEDED(hr), "IVectorView_Gamepad_QueryInterface failed, hr %#x\n", hr); + ok(tmp_agile_object != agile_object, "IVectorView_Gamepad_QueryInterface IID_IAgileObject returned agile_object\n"); + IAgileObject_Release(tmp_agile_object); + + size = 0xdeadbeef; + hr = IVectorView_Gamepad_get_Size(gamepads, &size); + ok(SUCCEEDED(hr), "IVectorView_Gamepad_QueryInterface failed, hr %#x\n", hr); + todo_wine ok(size != 0xdeadbeef, "IVectorView_Gamepad_get_Size returned %u\n", size); + + rc = IVectorView_Gamepad_Release(gamepads); + todo_wine ok(rc == 1, "IVectorView_Gamepad_Release returned unexpected refcount %d\n", rc); + + IGamepadStatics_Release(gamepad_statics); + +done: + IAgileObject_Release(agile_object); + IInspectable_Release(inspectable); + IActivationFactory_Release(factory); + + pWindowsDeleteString(str); + + pRoUninitialize(); +} + +START_TEST(statics) +{ + HMODULE combase; + + if (!(combase = LoadLibraryW(L"combase.dll"))) + { + win_skip("Failed to load combase.dll, skipping tests\n"); + return; + } + +#define LOAD_FUNCPTR(x) \ + if (!(p##x = (void*)GetProcAddress(combase, #x))) \ + { \ + win_skip("Failed to find %s in combase.dll, skipping tests.\n", #x); \ + return; \ + } + + LOAD_FUNCPTR(RoActivateInstance); + LOAD_FUNCPTR(RoGetActivationFactory); + LOAD_FUNCPTR(RoInitialize); + LOAD_FUNCPTR(RoUninitialize); + LOAD_FUNCPTR(WindowsCreateString); + LOAD_FUNCPTR(WindowsDeleteString); +#undef LOAD_FUNCPTR + + test_Gamepad(); +} diff --git a/dlls/windows.gaming.input/windows.gaming.input.spec b/dlls/windows.gaming.input/windows.gaming.input.spec new file mode 100644 index 00000000000..20a8bfa98ea --- /dev/null +++ b/dlls/windows.gaming.input/windows.gaming.input.spec @@ -0,0 +1,3 @@ +@ stdcall -private DllCanUnloadNow() +@ stdcall -private DllGetActivationFactory(ptr ptr) +@ stdcall -private DllGetClassObject(ptr ptr ptr) diff --git a/include/Makefile.in b/include/Makefile.in index 6c98f6d6c8b..1c80421ef6f 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -750,6 +750,7 @@ SOURCES = \ windns.h \ windows.foundation.collections.idl \ windows.foundation.idl \ + windows.gaming.input.idl \ windows.h \ windows.media.speechsynthesis.idl \ windowscontracts.idl \