@@ -68,19 +68,20 @@ template HRESULT m_IDirectInput8::CreateDeviceT<IDirectInput8W, LPDIRECTINPUTDEV
6868template <class T , class V >
6969HRESULT m_IDirectInput8::CreateDeviceT (T* ProxyInterfaceT, REFGUID rguid, V lplpDirectInputDevice, LPUNKNOWN pUnkOuter)
7070{
71+ UNREFERENCED_PARAMETER (ProxyInterfaceT);
72+
7173 Logging::LogDebug () << __FUNCTION__ << " (" << this << " )" ;
7274
73- HRESULT hr = ProxyInterfaceT->CreateDevice (rguid, lplpDirectInputDevice, pUnkOuter);
75+ IDirectInputDevice8W* ProxyDevice;
76+ HRESULT hr = ProxyInterface->CreateDevice (rguid, &ProxyDevice, pUnkOuter);
7477
75- if (SUCCEEDED (hr) && lplpDirectInputDevice )
78+ if (SUCCEEDED (hr))
7679 {
77- m_IDirectInputDevice8* pAddressX = new m_IDirectInputDevice8 ((IDirectInputDevice8W*)*lplpDirectInputDevice);
78-
79- *lplpDirectInputDevice = pAddressX;
80+ m_IDirectInputDevice8* DIDevice = new m_IDirectInputDevice8 (ProxyDevice);
8081
8182 bool isMouse = false ;
8283
83- if (IsEqualGUID (GUID_SysMouse, rguid) || IsEqualIID (GUID_SysMouseEm, rguid) || IsEqualIID (GUID_SysMouseEm2, rguid))
84+ if (IsEqualGUID (GUID_SysMouse, rguid) || IsEqualGUID (GUID_SysMouseEm, rguid) || IsEqualGUID (GUID_SysMouseEm2, rguid))
8485 {
8586 isMouse = true ;
8687 }
@@ -89,7 +90,7 @@ HRESULT m_IDirectInput8::CreateDeviceT(T* ProxyInterfaceT, REFGUID rguid, V lplp
8990 DIDEVCAPS caps = {};
9091 caps.dwSize = sizeof (DIDEVCAPS);
9192
92- if (SUCCEEDED (pAddressX ->GetCapabilities (&caps)))
93+ if (SUCCEEDED (DIDevice ->GetCapabilities (&caps)))
9394 {
9495 if (GET_DIDEVICE_TYPE (caps.dwDevType ) == DI8DEVTYPE_MOUSE)
9596 {
@@ -100,8 +101,13 @@ HRESULT m_IDirectInput8::CreateDeviceT(T* ProxyInterfaceT, REFGUID rguid, V lplp
100101
101102 if (isMouse)
102103 {
103- pAddressX ->SetAsMouse ();
104+ DIDevice ->SetAsMouse ();
104105 }
106+
107+ REFGUID riid = std::is_same_v<T, IDirectInput8A> ? IID_IDirectInputDevice8A : IID_IDirectInputDevice8W;
108+
109+ hr = DIDevice->QueryInterface (riid, reinterpret_cast <LPVOID*>(lplpDirectInputDevice));
110+ DIDevice->Release ();
105111 }
106112
107113 return hr;
@@ -234,12 +240,35 @@ HRESULT m_IDirectInput8::EnumDevicesBySemanticsT(T* ProxyInterfaceT, V ptszUserN
234240
235241 if (lpdid)
236242 {
237- m_IDirectInputDevice8* WrapperDevice = ProxyAddressLookupTableDinput8.FindAddress <m_IDirectInputDevice8>(lpdid);
238- if (WrapperDevice == nullptr )
243+ m_IDirectInputDevice8* DIDevice = ProxyAddressLookupTableDinput8.FindAddress <m_IDirectInputDevice8>(lpdid);
244+ if (DIDevice == nullptr )
245+ {
246+ m_IDirectInputDevice8::proxy_type* ProxyDevice;
247+ HRESULT hr = lpdid->QueryInterface (m_IDirectInputDevice8::proxy_iid, reinterpret_cast <LPVOID*>(&ProxyDevice));
248+ if (FAILED (hr))
249+ {
250+ LOG_LIMIT (100 , __FUNCTION__ << " Error: could not query interface for: " << m_IDirectInputDevice8::proxy_iid);
251+ return DIENUM_CONTINUE;
252+ }
253+
254+ DIDevice = new m_IDirectInputDevice8 (ProxyDevice);
255+ lpdid->Release ();
256+
257+ REFGUID riid = std::is_same_v<T, IDirectInput8A> ? IID_IDirectInputDevice8A : IID_IDirectInputDevice8W;
258+
259+ hr = DIDevice->QueryInterface (riid, reinterpret_cast <LPVOID*>(lpdid));
260+ DIDevice->Release ();
261+
262+ if (FAILED (hr))
263+ {
264+ LOG_LIMIT (100 , __FUNCTION__ << " Error: failed to get interface for: " << riid);
265+ return DIENUM_CONTINUE;
266+ }
267+ }
268+ else
239269 {
240- WrapperDevice = new m_IDirectInputDevice8 (lpdid) ;
270+ lpdid = DIDevice ;
241271 }
242- lpdid = WrapperDevice;
243272 }
244273
245274 return self->lpCallback (lpddi, lpdid, dwFlags, dwRemaining, self->pvRef );
0 commit comments