Commit bed2b9c3 authored by Ove Kaaven's avatar Ove Kaaven Committed by Alexandre Julliard

Only install the keyboard hook on device creation.

parent fa05849e
...@@ -58,10 +58,8 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserv) ...@@ -58,10 +58,8 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserv)
{ {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
DINPUT_instance = inst; DINPUT_instance = inst;
keyboard_hook = SetWindowsHookExW( WH_KEYBOARD_LL, KeyboardCallback, inst, 0 );
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
UnhookWindowsHookEx(keyboard_hook);
break; break;
} }
return TRUE; return TRUE;
......
...@@ -42,10 +42,6 @@ typedef struct dinput_device { ...@@ -42,10 +42,6 @@ typedef struct dinput_device {
extern void dinput_register_device(dinput_device *device) ; extern void dinput_register_device(dinput_device *device) ;
HHOOK keyboard_hook;
LRESULT CALLBACK KeyboardCallback( int code, WPARAM wparam, LPARAM lparam );
extern HINSTANCE DINPUT_instance; extern HINSTANCE DINPUT_instance;
#endif /* __WINE_DLLS_DINPUT_DINPUT_PRIVATE_H */ #endif /* __WINE_DLLS_DINPUT_DINPUT_PRIVATE_H */
...@@ -70,7 +70,9 @@ but 'DI_LOSTFOCUS' and 'DI_UNACQUIRED' exist for a reason. ...@@ -70,7 +70,9 @@ but 'DI_LOSTFOCUS' and 'DI_UNACQUIRED' exist for a reason.
static BYTE DInputKeyState[256]; /* array for 'GetDeviceState' */ static BYTE DInputKeyState[256]; /* array for 'GetDeviceState' */
HHOOK keyboard_hook; static CRITICAL_SECTION keyboard_crit = CRITICAL_SECTION_INIT("dinput_keyboard");
static DWORD keyboard_users;
static HHOOK keyboard_hook;
LRESULT CALLBACK KeyboardCallback( int code, WPARAM wparam, LPARAM lparam ) LRESULT CALLBACK KeyboardCallback( int code, WPARAM wparam, LPARAM lparam )
{ {
...@@ -162,6 +164,11 @@ static SysKeyboardAImpl *alloc_device(REFGUID rguid, LPVOID kvt, IDirectInputAIm ...@@ -162,6 +164,11 @@ static SysKeyboardAImpl *alloc_device(REFGUID rguid, LPVOID kvt, IDirectInputAIm
memcpy(&(newDevice->guid),rguid,sizeof(*rguid)); memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
newDevice->dinput = dinput; newDevice->dinput = dinput;
EnterCriticalSection(&keyboard_crit);
if (!keyboard_users++)
keyboard_hook = SetWindowsHookExW( WH_KEYBOARD_LL, KeyboardCallback, DINPUT_instance, 0 );
LeaveCriticalSection(&keyboard_crit);
return newDevice; return newDevice;
} }
...@@ -193,6 +200,31 @@ static dinput_device keyboarddev = { ...@@ -193,6 +200,31 @@ static dinput_device keyboarddev = {
DECL_GLOBAL_CONSTRUCTOR(keyboarddev_register) { dinput_register_device(&keyboarddev); } DECL_GLOBAL_CONSTRUCTOR(keyboarddev_register) { dinput_register_device(&keyboarddev); }
static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
{
ICOM_THIS(SysKeyboardAImpl,iface);
This->ref--;
if (This->ref)
return This->ref;
EnterCriticalSection(&keyboard_crit);
if (!--keyboard_users) {
UnhookWindowsHookEx( keyboard_hook );
keyboard_hook = 0;
}
LeaveCriticalSection(&keyboard_crit);
/* Free the data queue */
if (This->buffer != NULL)
HeapFree(GetProcessHeap(),0,This->buffer);
DeleteCriticalSection(&(This->crit));
HeapFree(GetProcessHeap(),0,This);
return 0;
}
static HRESULT WINAPI SysKeyboardAImpl_SetProperty( static HRESULT WINAPI SysKeyboardAImpl_SetProperty(
LPDIRECTINPUTDEVICE8A iface,REFGUID rguid,LPCDIPROPHEADER ph LPDIRECTINPUTDEVICE8A iface,REFGUID rguid,LPCDIPROPHEADER ph
) )
...@@ -400,7 +432,7 @@ static ICOM_VTABLE(IDirectInputDevice8A) SysKeyboardAvt = ...@@ -400,7 +432,7 @@ static ICOM_VTABLE(IDirectInputDevice8A) SysKeyboardAvt =
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
IDirectInputDevice2AImpl_QueryInterface, IDirectInputDevice2AImpl_QueryInterface,
IDirectInputDevice2AImpl_AddRef, IDirectInputDevice2AImpl_AddRef,
IDirectInputDevice2AImpl_Release, SysKeyboardAImpl_Release,
SysKeyboardAImpl_GetCapabilities, SysKeyboardAImpl_GetCapabilities,
IDirectInputDevice2AImpl_EnumObjects, IDirectInputDevice2AImpl_EnumObjects,
IDirectInputDevice2AImpl_GetProperty, IDirectInputDevice2AImpl_GetProperty,
......
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