Commit 448dde9b authored by Vitaliy Margolen's avatar Vitaliy Margolen Committed by Alexandre Julliard

dinput: Keep the list of all the dinput devices created for each IDIrectInput object.

parent 06d6a03d
...@@ -688,6 +688,10 @@ ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface) ...@@ -688,6 +688,10 @@ ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
HeapFree(GetProcessHeap(), 0, This->data_format.wine_df); HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
release_DataFormat(&This->data_format); release_DataFormat(&This->data_format);
EnterCriticalSection( &This->dinput->crit );
list_remove( &This->entry );
LeaveCriticalSection( &This->dinput->crit );
IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput); IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
This->crit.DebugInfo->Spare[0] = 0; This->crit.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&This->crit); DeleteCriticalSection(&This->crit);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "dinput.h" #include "dinput.h"
#include "wine/list.h"
#include "dinput_private.h" #include "dinput_private.h"
typedef struct typedef struct
...@@ -55,6 +56,7 @@ struct IDirectInputDevice2AImpl ...@@ -55,6 +56,7 @@ struct IDirectInputDevice2AImpl
GUID guid; GUID guid;
CRITICAL_SECTION crit; CRITICAL_SECTION crit;
IDirectInputImpl *dinput; IDirectInputImpl *dinput;
struct list entry; /* entry into IDirectInput devices list */
HANDLE hEvent; HANDLE hEvent;
DWORD dwCoopLevel; DWORD dwCoopLevel;
HWND win; HWND win;
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "winuser.h" #include "winuser.h"
#include "winerror.h" #include "winerror.h"
#include "dinput_private.h" #include "dinput_private.h"
#include "device_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(dinput); WINE_DEFAULT_DEBUG_CHANNEL(dinput);
...@@ -129,6 +130,11 @@ HRESULT WINAPI DirectInputCreateEx( ...@@ -129,6 +130,11 @@ HRESULT WINAPI DirectInputCreateEx(
This->dwVersion = dwVersion; This->dwVersion = dwVersion;
This->evsequence = 1; This->evsequence = 1;
*ppDI = This; *ppDI = This;
InitializeCriticalSection(&This->crit);
This->crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDirectInputImpl*->crit");
list_init( &This->devices_list );
} }
return res; return res;
} }
...@@ -254,15 +260,19 @@ static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface) ...@@ -254,15 +260,19 @@ static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface)
static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT7A iface) static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT7A iface)
{ {
IDirectInputImpl *This = (IDirectInputImpl *)iface; IDirectInputImpl *This = (IDirectInputImpl *)iface;
ULONG ref; ULONG ref;
ref = InterlockedDecrement(&(This->ref));
if (ref == 0) ref = InterlockedDecrement( &This->ref );
{ if (ref) return ref;
HeapFree(GetProcessHeap(), 0, This);
release_hook_thread(); release_hook_thread();
}
return ref; This->crit.DebugInfo->Spare[0] = 0;
DeleteCriticalSection( &This->crit );
HeapFree( GetProcessHeap(), 0, This );
return 0;
} }
static HRESULT WINAPI IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface, REFIID riid, LPVOID *ppobj) { static HRESULT WINAPI IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface, REFIID riid, LPVOID *ppobj) {
...@@ -355,9 +365,15 @@ static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, R ...@@ -355,9 +365,15 @@ static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, R
/* Loop on all the devices to see if anyone matches the given GUID */ /* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < NB_DINPUT_DEVICES; i++) { for (i = 0; i < NB_DINPUT_DEVICES; i++) {
HRESULT ret; HRESULT ret;
if (!dinput_devices[i]->create_deviceA) continue; if (!dinput_devices[i]->create_deviceA) continue;
if ((ret = dinput_devices[i]->create_deviceA(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK) if ((ret = dinput_devices[i]->create_deviceA(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK)
{
EnterCriticalSection( &This->crit );
list_add_tail( &This->devices_list, &(*(IDirectInputDevice2AImpl**)pvOut)->entry );
LeaveCriticalSection( &This->crit );
return DI_OK; return DI_OK;
}
if (ret == DIERR_NOINTERFACE) if (ret == DIERR_NOINTERFACE)
ret_value = DIERR_NOINTERFACE; ret_value = DIERR_NOINTERFACE;
...@@ -380,9 +396,15 @@ static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, R ...@@ -380,9 +396,15 @@ static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, R
/* Loop on all the devices to see if anyone matches the given GUID */ /* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < NB_DINPUT_DEVICES; i++) { for (i = 0; i < NB_DINPUT_DEVICES; i++) {
HRESULT ret; HRESULT ret;
if (!dinput_devices[i]->create_deviceW) continue; if (!dinput_devices[i]->create_deviceW) continue;
if ((ret = dinput_devices[i]->create_deviceW(This, rguid, riid, (LPDIRECTINPUTDEVICEW*) pvOut)) == DI_OK) if ((ret = dinput_devices[i]->create_deviceW(This, rguid, riid, (LPDIRECTINPUTDEVICEW*) pvOut)) == DI_OK)
{
EnterCriticalSection( &This->crit );
list_add_tail( &This->devices_list, &(*(IDirectInputDevice2AImpl**)pvOut)->entry );
LeaveCriticalSection( &This->crit );
return DI_OK; return DI_OK;
}
if (ret == DIERR_NOINTERFACE) if (ret == DIERR_NOINTERFACE)
ret_value = DIERR_NOINTERFACE; ret_value = DIERR_NOINTERFACE;
......
...@@ -24,18 +24,20 @@ ...@@ -24,18 +24,20 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "dinput.h" #include "dinput.h"
#include "wine/list.h"
/* Implementation specification */ /* Implementation specification */
typedef struct IDirectInputImpl IDirectInputImpl; typedef struct IDirectInputImpl IDirectInputImpl;
struct IDirectInputImpl struct IDirectInputImpl
{ {
const void *lpVtbl; const void *lpVtbl;
LONG ref; LONG ref;
/* Used to have an unique sequence number for all the events */ CRITICAL_SECTION crit;
DWORD evsequence;
DWORD dwVersion; DWORD evsequence; /* unique sequence number for events */
DWORD dwVersion; /* direct input version number */
struct list devices_list; /* list of all created dinput devices */
}; };
/* Function called by all devices that Wine supports */ /* Function called by all devices that Wine supports */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment