1 /* WinRT Windows.Gaming.Input implementation
3 * Copyright 2021 RĂ©mi Bernon for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "winstring.h"
26 #include "wine/debug.h"
30 #include "activation.h"
32 #define WIDL_using_Windows_Foundation
33 #define WIDL_using_Windows_Foundation_Collections
34 #include "windows.foundation.h"
35 #define WIDL_using_Windows_Gaming_Input
36 #include "windows.gaming.input.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(input
);
40 static const char *debugstr_hstring(HSTRING hstr
)
44 if (hstr
&& !((ULONG_PTR
)hstr
>> 16)) return "(invalid)";
45 str
= WindowsGetStringRawBuffer(hstr
, &len
);
46 return wine_dbgstr_wn(str
, len
);
51 IVectorView_Gamepad IVectorView_Gamepad_iface
;
55 static inline struct gamepad_vector
*impl_from_IVectorView_Gamepad(IVectorView_Gamepad
*iface
)
57 return CONTAINING_RECORD(iface
, struct gamepad_vector
, IVectorView_Gamepad_iface
);
60 static HRESULT STDMETHODCALLTYPE
vector_view_gamepad_QueryInterface(
61 IVectorView_Gamepad
*iface
, REFIID iid
, void **out
)
63 TRACE("iface %p, iid %s, out %p stub!\n", iface
, debugstr_guid(iid
), out
);
65 if (IsEqualGUID(iid
, &IID_IUnknown
) ||
66 IsEqualGUID(iid
, &IID_IInspectable
) ||
67 IsEqualGUID(iid
, &IID_IAgileObject
) ||
68 IsEqualGUID(iid
, &IID_IVectorView_Gamepad
))
70 IUnknown_AddRef(iface
);
75 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
80 static ULONG STDMETHODCALLTYPE
vector_view_gamepad_AddRef(
81 IVectorView_Gamepad
*iface
)
83 struct gamepad_vector
*impl
= impl_from_IVectorView_Gamepad(iface
);
84 ULONG ref
= InterlockedIncrement(&impl
->ref
);
85 TRACE("iface %p, ref %u.\n", iface
, ref
);
89 static ULONG STDMETHODCALLTYPE
vector_view_gamepad_Release(
90 IVectorView_Gamepad
*iface
)
92 struct gamepad_vector
*impl
= impl_from_IVectorView_Gamepad(iface
);
93 ULONG ref
= InterlockedDecrement(&impl
->ref
);
94 TRACE("iface %p, ref %u.\n", iface
, ref
);
98 static HRESULT STDMETHODCALLTYPE
vector_view_gamepad_GetIids(
99 IVectorView_Gamepad
*iface
, ULONG
*iid_count
, IID
**iids
)
101 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface
, iid_count
, iids
);
105 static HRESULT STDMETHODCALLTYPE
vector_view_gamepad_GetRuntimeClassName(
106 IVectorView_Gamepad
*iface
, HSTRING
*class_name
)
108 FIXME("iface %p, class_name %p stub!\n", iface
, class_name
);
112 static HRESULT STDMETHODCALLTYPE
vector_view_gamepad_GetTrustLevel(
113 IVectorView_Gamepad
*iface
, TrustLevel
*trust_level
)
115 FIXME("iface %p, trust_level %p stub!\n", iface
, trust_level
);
119 static HRESULT STDMETHODCALLTYPE
vector_view_gamepad_GetAt(
120 IVectorView_Gamepad
*iface
, ULONG index
, IGamepad
**value
)
122 FIXME("iface %p, index %#x, value %p stub!\n", iface
, index
, value
);
127 static HRESULT STDMETHODCALLTYPE
vector_view_gamepad_get_Size(
128 IVectorView_Gamepad
*iface
, ULONG
*value
)
130 FIXME("iface %p, value %p stub!\n", iface
, value
);
135 static HRESULT STDMETHODCALLTYPE
vector_view_gamepad_IndexOf(
136 IVectorView_Gamepad
*iface
, IGamepad
*element
, ULONG
*index
, BOOLEAN
*found
)
138 FIXME("iface %p, element %p, index %p, found %p stub!\n", iface
, element
, index
, found
);
144 static HRESULT STDMETHODCALLTYPE
vector_view_gamepad_GetMany(
145 IVectorView_Gamepad
*iface
, ULONG start_index
, IGamepad
**items
, UINT
*value
)
147 FIXME("iface %p, start_index %#x, items %p, value %p stub!\n", iface
, start_index
, items
, value
);
151 static const struct IVectorView_GamepadVtbl vector_view_gamepad_vtbl
=
153 vector_view_gamepad_QueryInterface
,
154 vector_view_gamepad_AddRef
,
155 vector_view_gamepad_Release
,
156 /* IInspectable methods */
157 vector_view_gamepad_GetIids
,
158 vector_view_gamepad_GetRuntimeClassName
,
159 vector_view_gamepad_GetTrustLevel
,
160 /* IVectorView<VoiceInformation> methods */
161 vector_view_gamepad_GetAt
,
162 vector_view_gamepad_get_Size
,
163 vector_view_gamepad_IndexOf
,
164 vector_view_gamepad_GetMany
,
167 static struct gamepad_vector gamepads
=
169 {&vector_view_gamepad_vtbl
},
173 struct windows_gaming_input
175 IActivationFactory IActivationFactory_iface
;
176 IGamepadStatics IGamepadStatics_iface
;
180 static inline struct windows_gaming_input
*impl_from_IActivationFactory(IActivationFactory
*iface
)
182 return CONTAINING_RECORD(iface
, struct windows_gaming_input
, IActivationFactory_iface
);
185 static inline struct windows_gaming_input
*impl_from_IGamepadStatics(IGamepadStatics
*iface
)
187 return CONTAINING_RECORD(iface
, struct windows_gaming_input
, IGamepadStatics_iface
);
190 static HRESULT STDMETHODCALLTYPE
windows_gaming_input_QueryInterface(
191 IActivationFactory
*iface
, REFIID iid
, void **out
)
193 struct windows_gaming_input
*impl
= impl_from_IActivationFactory(iface
);
195 TRACE("iface %p, iid %s, out %p stub!\n", iface
, debugstr_guid(iid
), out
);
197 if (IsEqualGUID(iid
, &IID_IUnknown
) ||
198 IsEqualGUID(iid
, &IID_IInspectable
) ||
199 IsEqualGUID(iid
, &IID_IAgileObject
) ||
200 IsEqualGUID(iid
, &IID_IActivationFactory
))
202 IUnknown_AddRef(iface
);
207 if (IsEqualGUID(iid
, &IID_IGamepadStatics
))
209 IUnknown_AddRef(iface
);
210 *out
= &impl
->IGamepadStatics_iface
;
214 FIXME("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
216 return E_NOINTERFACE
;
219 static ULONG STDMETHODCALLTYPE
windows_gaming_input_AddRef(
220 IActivationFactory
*iface
)
222 struct windows_gaming_input
*impl
= impl_from_IActivationFactory(iface
);
223 ULONG ref
= InterlockedIncrement(&impl
->ref
);
224 TRACE("iface %p, ref %u.\n", iface
, ref
);
228 static ULONG STDMETHODCALLTYPE
windows_gaming_input_Release(
229 IActivationFactory
*iface
)
231 struct windows_gaming_input
*impl
= impl_from_IActivationFactory(iface
);
232 ULONG ref
= InterlockedDecrement(&impl
->ref
);
233 TRACE("iface %p, ref %u.\n", iface
, ref
);
237 static HRESULT STDMETHODCALLTYPE
windows_gaming_input_GetIids(
238 IActivationFactory
*iface
, ULONG
*iid_count
, IID
**iids
)
240 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface
, iid_count
, iids
);
244 static HRESULT STDMETHODCALLTYPE
windows_gaming_input_GetRuntimeClassName(
245 IActivationFactory
*iface
, HSTRING
*class_name
)
247 FIXME("iface %p, class_name %p stub!\n", iface
, class_name
);
251 static HRESULT STDMETHODCALLTYPE
windows_gaming_input_GetTrustLevel(
252 IActivationFactory
*iface
, TrustLevel
*trust_level
)
254 FIXME("iface %p, trust_level %p stub!\n", iface
, trust_level
);
258 static HRESULT STDMETHODCALLTYPE
windows_gaming_input_ActivateInstance(
259 IActivationFactory
*iface
, IInspectable
**instance
)
261 FIXME("iface %p, instance %p stub!\n", iface
, instance
);
265 static const struct IActivationFactoryVtbl activation_factory_vtbl
=
267 windows_gaming_input_QueryInterface
,
268 windows_gaming_input_AddRef
,
269 windows_gaming_input_Release
,
270 /* IInspectable methods */
271 windows_gaming_input_GetIids
,
272 windows_gaming_input_GetRuntimeClassName
,
273 windows_gaming_input_GetTrustLevel
,
274 /* IActivationFactory methods */
275 windows_gaming_input_ActivateInstance
,
278 static HRESULT STDMETHODCALLTYPE
gamepad_statics_QueryInterface(
279 IGamepadStatics
*iface
, REFIID iid
, void **out
)
281 struct windows_gaming_input
*impl
= impl_from_IGamepadStatics(iface
);
282 return windows_gaming_input_QueryInterface(&impl
->IActivationFactory_iface
, iid
, out
);
285 static ULONG STDMETHODCALLTYPE
gamepad_statics_AddRef(
286 IGamepadStatics
*iface
)
288 struct windows_gaming_input
*impl
= impl_from_IGamepadStatics(iface
);
289 return windows_gaming_input_AddRef(&impl
->IActivationFactory_iface
);
292 static ULONG STDMETHODCALLTYPE
gamepad_statics_Release(
293 IGamepadStatics
*iface
)
295 struct windows_gaming_input
*impl
= impl_from_IGamepadStatics(iface
);
296 return windows_gaming_input_Release(&impl
->IActivationFactory_iface
);
299 static HRESULT STDMETHODCALLTYPE
gamepad_statics_GetIids(
300 IGamepadStatics
*iface
, ULONG
*iid_count
, IID
**iids
)
302 FIXME("iface %p, iid_count %p, iids %p stub!\n", iface
, iid_count
, iids
);
306 static HRESULT STDMETHODCALLTYPE
gamepad_statics_GetRuntimeClassName(
307 IGamepadStatics
*iface
, HSTRING
*class_name
)
309 FIXME("iface %p, class_name %p stub!\n", iface
, class_name
);
313 static HRESULT STDMETHODCALLTYPE
gamepad_statics_GetTrustLevel(
314 IGamepadStatics
*iface
, TrustLevel
*trust_level
)
316 FIXME("iface %p, trust_level %p stub!\n", iface
, trust_level
);
320 static HRESULT STDMETHODCALLTYPE
gamepad_statics_add_GamepadAdded(
321 IGamepadStatics
*iface
, IEventHandler_Gamepad
*value
, EventRegistrationToken
* token
)
323 FIXME("iface %p, value %p, token %p stub!\n", iface
, value
, token
);
327 static HRESULT STDMETHODCALLTYPE
gamepad_statics_remove_GamepadAdded(
328 IGamepadStatics
*iface
, EventRegistrationToken token
)
330 FIXME("iface %p, token %#I64x stub!\n", iface
, token
.value
);
334 static HRESULT STDMETHODCALLTYPE
gamepad_statics_add_GamepadRemoved(
335 IGamepadStatics
*iface
, IEventHandler_Gamepad
*value
, EventRegistrationToken
* token
)
337 FIXME("iface %p, value %p, token %p stub!\n", iface
, value
, token
);
341 static HRESULT STDMETHODCALLTYPE
gamepad_statics_remove_GamepadRemoved(
342 IGamepadStatics
*iface
, EventRegistrationToken token
)
344 FIXME("iface %p, token %#I64x stub!\n", iface
, token
.value
);
348 static HRESULT STDMETHODCALLTYPE
gamepad_statics_get_Gamepads(
349 IGamepadStatics
*iface
, IVectorView_Gamepad
**value
)
351 TRACE("iface %p, value %p.\n", iface
, value
);
352 *value
= &gamepads
.IVectorView_Gamepad_iface
;
353 IVectorView_Gamepad_AddRef(*value
);
357 static const struct IGamepadStaticsVtbl gamepad_statics_vtbl
=
359 gamepad_statics_QueryInterface
,
360 gamepad_statics_AddRef
,
361 gamepad_statics_Release
,
362 /* IInspectable methods */
363 gamepad_statics_GetIids
,
364 gamepad_statics_GetRuntimeClassName
,
365 gamepad_statics_GetTrustLevel
,
366 /* IGamepadStatics methods */
367 gamepad_statics_add_GamepadAdded
,
368 gamepad_statics_remove_GamepadAdded
,
369 gamepad_statics_add_GamepadRemoved
,
370 gamepad_statics_remove_GamepadRemoved
,
371 gamepad_statics_get_Gamepads
,
374 static struct windows_gaming_input windows_gaming_input
=
376 {&activation_factory_vtbl
},
377 {&gamepad_statics_vtbl
},
381 HRESULT WINAPI
DllCanUnloadNow(void)
386 HRESULT WINAPI
DllGetClassObject(REFCLSID clsid
, REFIID riid
, void **out
)
388 FIXME("clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid
), debugstr_guid(riid
), out
);
389 return CLASS_E_CLASSNOTAVAILABLE
;
392 HRESULT WINAPI
DllGetActivationFactory(HSTRING classid
, IActivationFactory
**factory
)
394 TRACE("classid %s, factory %p.\n", debugstr_hstring(classid
), factory
);
395 *factory
= &windows_gaming_input
.IActivationFactory_iface
;
396 IUnknown_AddRef(*factory
);