[dinput] dedicated init method that allows implementations to
gather informations
Christoph Frick
frick at sc-networks.de
Thu Jul 20 03:21:28 CDT 2006
hi,
see the discussion yesterday about this - i get random crashes with IL2
since my dinput changes and the generall impression is, that this is a
race condition. so i added a init-hook to the list of methods and call
them in DllMain (like wined3d does its init). this fixes my problem -
for the mouse, keyboard and /dev/js.* there is no init (needed).
--
cu
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 9f93a52..9ae80c0 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -64,10 +64,15 @@ HINSTANCE DINPUT_instance = NULL;
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserv)
{
+ int i;
switch(reason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(inst);
+ for (i = 0; i < NB_DINPUT_DEVICES; i++) {
+ if (!dinput_devices[i]->init) continue;
+ dinput_devices[i]->init();
+ }
DINPUT_instance = inst;
break;
case DLL_PROCESS_DETACH:
diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h
index c23b048..01c4dba 100644
--- a/dlls/dinput/dinput_private.h
+++ b/dlls/dinput/dinput_private.h
@@ -41,6 +41,7 @@ struct IDirectInputImpl
/* Function called by all devices that Wine supports */
struct dinput_device {
const char *name;
+ void (*init)(void);
BOOL (*enum_deviceA)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id);
BOOL (*enum_deviceW)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id);
HRESULT (*create_deviceA)(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev);
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index d56271d..e38b37a 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -658,6 +658,7 @@ static HRESULT joydev_create_deviceW(IDi
const struct dinput_device joystick_linux_device = {
"Wine Linux joystick driver",
+ NULL,
joydev_enum_deviceA,
joydev_enum_deviceW,
joydev_create_deviceA,
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index c88ac78..d22a8ca 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -169,19 +169,13 @@ #define test_bit(arr,bit) (((BYTE*)(arr)
#define MAX_JOYDEV 64
-static int have_joydevs = -1;
+static int have_joydevs = 0;
static struct JoyDev *joydevs = NULL;
static void find_joydevs(void)
{
int i;
- if (have_joydevs!=-1) {
- return;
- }
-
- have_joydevs = 0;
-
for (i=0;i<MAX_JOYDEV;i++) {
char buf[MAX_PATH];
struct JoyDev joydev = {0};
@@ -293,10 +287,13 @@ #endif
}
}
-static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
+static void joydev_init(void)
{
- find_joydevs();
+ find_joydevs();
+}
+static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
+{
if (id >= have_joydevs) {
return FALSE;
}
@@ -330,8 +327,6 @@ #endif
static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
{
- find_joydevs();
-
if (id >= have_joydevs) {
return FALSE;
}
@@ -447,8 +442,6 @@ static HRESULT joydev_create_deviceA(IDi
{
int i;
- find_joydevs();
-
for (i=0; i<have_joydevs; i++) {
if (IsEqualGUID(&GUID_Joystick,rguid) ||
IsEqualGUID(&joydevs[i].guid,rguid)
@@ -479,8 +472,6 @@ static HRESULT joydev_create_deviceW(IDi
{
int i;
- find_joydevs();
-
for (i=0; i<have_joydevs; i++) {
if (IsEqualGUID(&GUID_Joystick,rguid) ||
IsEqualGUID(&joydevs[i].guid,rguid)
@@ -508,6 +499,7 @@ static HRESULT joydev_create_deviceW(IDi
const struct dinput_device joystick_linuxinput_device = {
"Wine Linux-input joystick driver",
+ joydev_init,
joydev_enum_deviceA,
joydev_enum_deviceW,
joydev_create_deviceA,
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index f6195b1..6bc16e5 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -276,6 +276,7 @@ static HRESULT keyboarddev_create_device
const struct dinput_device keyboard_device = {
"Wine keyboard driver",
+ NULL,
keyboarddev_enum_deviceA,
keyboarddev_enum_deviceW,
keyboarddev_create_deviceA,
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index e626bf6..844bcb9 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -308,6 +308,7 @@ static HRESULT mousedev_create_deviceW(I
const struct dinput_device mouse_device = {
"Wine mouse driver",
+ NULL,
mousedev_enum_deviceA,
mousedev_enum_deviceW,
mousedev_create_deviceA,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 163 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20060720/e45df32d/attachment.pgp
More information about the wine-patches
mailing list