Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
wine
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Mayr
wine
Commits
ad045d6e
Commit
ad045d6e
authored
18 years ago
by
Vitaliy Margolen
Committed by
Alexandre Julliard
18 years ago
Browse files
Options
Downloads
Patches
Plain Diff
dinput: Create/destroy hook thread from DirectInput.
parent
61c1dd2b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dlls/dinput/dinput_main.c
+53
-25
53 additions, 25 deletions
dlls/dinput/dinput_main.c
with
53 additions
and
25 deletions
dlls/dinput/dinput_main.c
+
53
−
25
View file @
ad045d6e
...
...
@@ -76,6 +76,8 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserv)
return
TRUE
;
}
static
BOOL
create_hook_thread
(
void
);
static
void
release_hook_thread
(
void
);
/******************************************************************************
* DirectInputCreateEx (DINPUT.@)
...
...
@@ -118,6 +120,7 @@ HRESULT WINAPI DirectInputCreateEx(
res
=
DI_OK
;
}
if
(
res
==
DI_OK
&&
!
create_hook_thread
())
res
=
DIERR_GENERIC
;
if
(
res
==
DI_OK
)
{
This
=
HeapAlloc
(
GetProcessHeap
(),
0
,
sizeof
(
IDirectInputImpl
));
...
...
@@ -255,7 +258,10 @@ static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT7A iface)
ULONG
ref
;
ref
=
InterlockedDecrement
(
&
(
This
->
ref
));
if
(
ref
==
0
)
HeapFree
(
GetProcessHeap
(),
0
,
This
);
{
HeapFree
(
GetProcessHeap
(),
0
,
This
);
release_hook_thread
();
}
return
ref
;
}
...
...
@@ -732,15 +738,21 @@ static LRESULT CALLBACK dinput_hook_WndProc(HWND hWnd, UINT message, WPARAM wPar
return
res
;
}
}
else
if
(
!
wParam
&&
!
lParam
)
DestroyWindow
(
hWnd
);
return
0
;
case
WM_DESTROY
:
if
(
kbd_hook
)
UnhookWindowsHookEx
(
kbd_hook
);
if
(
mouse_hook
)
UnhookWindowsHookEx
(
mouse_hook
);
PostQuitMessage
(
0
);
}
return
DefWindowProcW
(
hWnd
,
message
,
wParam
,
lParam
);
}
static
HANDLE
signal_event
;
static
HWND
hook_thread_hwnd
;
static
LONG
hook_thread_refcount
;
static
DWORD
WINAPI
hook_thread_proc
(
void
*
param
)
{
...
...
@@ -757,9 +769,9 @@ static DWORD WINAPI hook_thread_proc(void *param)
if
(
!
RegisterClassExW
(
&
wcex
))
ERR
(
"Error registering window class
\n
"
);
hwnd
=
CreateWindowExW
(
0
,
classW
,
NULL
,
0
,
0
,
0
,
0
,
0
,
HWND_MESSAGE
,
NULL
,
NULL
,
0
);
*
(
HWND
*
)
param
=
hwnd
;
hook_thread_hwnd
=
hwnd
;
SetEvent
(
signal_event
);
SetEvent
(
*
(
LPHANDLE
)
param
);
if
(
hwnd
)
{
while
(
GetMessageW
(
&
msg
,
0
,
0
,
0
))
...
...
@@ -767,10 +779,10 @@ static DWORD WINAPI hook_thread_proc(void *param)
TranslateMessage
(
&
msg
);
DispatchMessageW
(
&
msg
);
}
DestroyWindow
(
hwnd
);
}
else
ERR
(
"Error creating message window
\n
"
);
DestroyWindow
(
hwnd
);
UnregisterClassW
(
wcex
.
lpszClassName
,
wcex
.
hInstance
);
return
0
;
}
...
...
@@ -784,41 +796,57 @@ static CRITICAL_SECTION_DEBUG dinput_critsect_debug =
};
static
CRITICAL_SECTION
dinput_hook_crit
=
{
&
dinput_critsect_debug
,
-
1
,
0
,
0
,
0
,
0
};
static
HWND
get
_thread
_hwnd
(
void
)
static
BOOL
create_hook
_thread
(
void
)
{
static
HANDLE
hook_thread
;
static
HWND
hook_thread_hwnd
;
LONG
ref
;
EnterCriticalSection
(
&
dinput_hook_crit
);
if
(
!
hook_thread
)
ref
=
++
hook_thread_refcount
;
TRACE
(
"Refcount %ld
\n
"
,
ref
);
if
(
ref
==
1
)
{
DWORD
tid
;
H
W
ND
hwnd
;
H
A
ND
LE
thread
,
event
;
signal_
event
=
CreateEventW
(
NULL
,
FALSE
,
FALSE
,
NULL
);
hook_
thread
=
CreateThread
(
NULL
,
0
,
hook_thread_proc
,
&
hwnd
,
0
,
&
tid
);
if
(
signal_
event
&&
hook_
thread
)
event
=
CreateEventW
(
NULL
,
FALSE
,
FALSE
,
NULL
);
thread
=
CreateThread
(
NULL
,
0
,
hook_thread_proc
,
&
event
,
0
,
&
tid
);
if
(
event
&&
thread
)
{
HANDLE
handles
[
2
];
handles
[
0
]
=
signal_
event
;
handles
[
1
]
=
hook_
thread
;
handles
[
0
]
=
event
;
handles
[
1
]
=
thread
;
WaitForMultipleObjects
(
2
,
handles
,
FALSE
,
INFINITE
);
}
CloseHandle
(
signal_event
);
if
(
!
(
hook_thread_hwnd
=
hwnd
))
{
/* Thread failed to create window - reset things so we could try again later */
CloseHandle
(
hook_thread
);
hook_thread
=
0
;
}
CloseHandle
(
event
);
CloseHandle
(
thread
);
}
LeaveCriticalSection
(
&
dinput_hook_crit
);
return
hook_thread_hwnd
;
return
hook_thread_hwnd
!=
0
;
}
static
void
release_hook_thread
(
void
)
{
LONG
ref
;
EnterCriticalSection
(
&
dinput_hook_crit
);
ref
=
--
hook_thread_refcount
;
TRACE
(
"Releasing to %ld
\n
"
,
ref
);
if
(
ref
==
0
)
{
HWND
hwnd
=
hook_thread_hwnd
;
hook_thread_hwnd
=
0
;
SendMessageW
(
hwnd
,
WM_USER
+
0x10
,
0
,
0
);
}
LeaveCriticalSection
(
&
dinput_hook_crit
);
}
HHOOK
set_dinput_hook
(
int
hook_id
,
LPVOID
proc
)
{
return
(
HHOOK
)
SendMessageW
(
get_thread_hwnd
(),
WM_USER
+
0x10
,
(
WPARAM
)
hook_id
,
(
LPARAM
)
proc
);
HWND
hwnd
;
EnterCriticalSection
(
&
dinput_hook_crit
);
hwnd
=
hook_thread_hwnd
;
LeaveCriticalSection
(
&
dinput_hook_crit
);
return
(
HHOOK
)
SendMessageW
(
hwnd
,
WM_USER
+
0x10
,
(
WPARAM
)
hook_id
,
(
LPARAM
)
proc
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment