Build a static list of devices instead of relying on ELF
constructors.

diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 4b2df7f..2920e22 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -51,10 +51,14 @@
 static IDirectInput8AVtbl ddi8avt;
 static IDirectInput8WVtbl ddi8wvt;
 
-/* This array will be filled a dinput.so loading */
-#define MAX_WINE_DINPUT_DEVICES 4
-static dinput_device * dinput_devices[MAX_WINE_DINPUT_DEVICES];
-static int nrof_dinput_devices = 0;
+static const struct dinput_device *dinput_devices[] =
+{
+    &mouse_device,
+    &keyboard_device,
+    &joystick_linuxinput_device,
+    &joystick_linux_device
+};
+#define NB_DINPUT_DEVICES (sizeof(dinput_devices)/sizeof(dinput_devices[0]))
 
 HINSTANCE DINPUT_instance = NULL;
 
@@ -73,29 +77,6 @@
 }
 
 
-/* register a direct draw driver. We better not use malloc for we are in
- * the ELF startup initialisation at this point.
- */
-void dinput_register_device(dinput_device *device) {
-    int	i;
-
-    /* insert according to priority */
-    for (i=0;i<nrof_dinput_devices;i++) {
-	if (dinput_devices[i]->pref <= device->pref) {
-	    memcpy(dinput_devices+i+1,dinput_devices+i,sizeof(dinput_devices[0])*(nrof_dinput_devices-i));
-	    dinput_devices[i] = device;
-	    break;
-	}
-    }
-    if (i==nrof_dinput_devices)	/* not found, or too low priority */
-	dinput_devices[nrof_dinput_devices] = device;
-
-    nrof_dinput_devices++;
-
-    /* increase MAX_DDRAW_DRIVERS if the line below triggers */
-    assert(nrof_dinput_devices <= MAX_WINE_DINPUT_DEVICES);
-}
-
 /******************************************************************************
  *	DirectInputCreateEx (DINPUT.@)
  */
@@ -247,7 +228,8 @@
 	  lpCallback, pvRef, dwFlags);
     TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
     
-    for (i = 0; i < nrof_dinput_devices; i++) {
+    for (i = 0; i < NB_DINPUT_DEVICES; i++) {
+        if (!dinput_devices[i]->enum_deviceA) continue;
         for (j = 0, r = -1; r != 0; j++) {
 	    devInstance.dwSize = sizeof(devInstance);
 	    TRACE("  - checking device %d ('%s')\n", i, dinput_devices[i]->name);
@@ -276,7 +258,8 @@
 	  lpCallback, pvRef, dwFlags);
     TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
     
-    for (i = 0; i < nrof_dinput_devices; i++) {
+    for (i = 0; i < NB_DINPUT_DEVICES; i++) {
+        if (!dinput_devices[i]->enum_deviceW) continue;
         for (j = 0, r = -1; r != 0; j++) {
 	    devInstance.dwSize = sizeof(devInstance);
 	    TRACE("  - checking device %d ('%s')\n", i, dinput_devices[i]->name);
@@ -349,8 +332,9 @@
 	TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
 
 	/* Loop on all the devices to see if anyone matches the given GUID */
-	for (i = 0; i < nrof_dinput_devices; i++) {
+	for (i = 0; i < NB_DINPUT_DEVICES; i++) {
 	  HRESULT ret;
+	  if (!dinput_devices[i]->create_deviceA) continue;
 	  if ((ret = dinput_devices[i]->create_deviceA(This, rguid, NULL, pdev)) == DI_OK)
 	    return DI_OK;
 
@@ -370,8 +354,9 @@
 	TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
 
 	/* Loop on all the devices to see if anyone matches the given GUID */
-	for (i = 0; i < nrof_dinput_devices; i++) {
+	for (i = 0; i < NB_DINPUT_DEVICES; i++) {
 	  HRESULT ret;
+	  if (!dinput_devices[i]->create_deviceW) continue;
 	  if ((ret = dinput_devices[i]->create_deviceW(This, rguid, NULL, pdev)) == DI_OK)
 	    return DI_OK;
 
@@ -430,8 +415,9 @@
   TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
 
   /* Loop on all the devices to see if anyone matches the given GUID */
-  for (i = 0; i < nrof_dinput_devices; i++) {
+  for (i = 0; i < NB_DINPUT_DEVICES; i++) {
     HRESULT ret;
+    if (!dinput_devices[i]->create_deviceA) continue;
     if ((ret = dinput_devices[i]->create_deviceA(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK)
       return DI_OK;
 
@@ -452,8 +438,9 @@
   TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
 
   /* Loop on all the devices to see if anyone matches the given GUID */
-  for (i = 0; i < nrof_dinput_devices; i++) {
+  for (i = 0; i < NB_DINPUT_DEVICES; i++) {
     HRESULT ret;
+    if (!dinput_devices[i]->create_deviceW) continue;
     if ((ret = dinput_devices[i]->create_deviceW(This, rguid, riid, (LPDIRECTINPUTDEVICEW*) pvOut)) == DI_OK)
       return DI_OK;
 
diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h
index 393d125..98e8add 100644
--- a/dlls/dinput/dinput_private.h
+++ b/dlls/dinput/dinput_private.h
@@ -39,16 +39,18 @@
 };
 
 /* Function called by all devices that Wine supports */
-typedef struct dinput_device {
-    INT pref;
+struct dinput_device {
     const char *name;
     BOOL (*enum_deviceA)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version, int id);
     BOOL (*enum_deviceW)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version, int id);
     HRESULT (*create_deviceA)(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev);
     HRESULT (*create_deviceW)(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev);
-} dinput_device;
+};
 
-extern void dinput_register_device(dinput_device *device);
+extern const struct dinput_device mouse_device;
+extern const struct dinput_device keyboard_device;
+extern const struct dinput_device joystick_linux_device;
+extern const struct dinput_device joystick_linuxinput_device;
 
 extern HINSTANCE DINPUT_instance;
 
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 4562ed5..77578c6 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -28,8 +28,6 @@
 #include "config.h"
 #include "wine/port.h"
 
-#ifdef HAVE_LINUX_22_JOYSTICK_API
-
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
@@ -55,7 +53,6 @@
 #ifdef HAVE_LINUX_JOYSTICK_H
 # include <linux/joystick.h>
 #endif
-#define JOYDEV	"/dev/js"
 
 #include "wine/debug.h"
 #include "wine/unicode.h"
@@ -70,6 +67,10 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
 
+#ifdef HAVE_LINUX_22_JOYSTICK_API
+
+#define JOYDEV "/dev/js"
+
 typedef struct {
     LONG lMin;
     LONG lMax;
@@ -646,8 +647,7 @@
   return DIERR_DEVICENOTREG;
 }
 
-static dinput_device joydev = {
-  10,
+const struct dinput_device joystick_linux_device = {
   "Wine Linux joystick driver",
   joydev_enum_deviceA,
   joydev_enum_deviceW,
@@ -655,8 +655,6 @@
   joydev_create_deviceW
 };
 
-DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
-
 /******************************************************************************
  *	Joystick
  */
@@ -1695,4 +1693,14 @@
 };
 #undef XCAST
 
+#else  /* HAVE_LINUX_22_JOYSTICK_API */
+
+const struct dinput_device joystick_linux_device = {
+  "Wine Linux joystick driver",
+  NULL,
+  NULL,
+  NULL,
+  NULL
+};
+
 #endif  /* HAVE_LINUX_22_JOYSTICK_API */
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 4200abe..efb5af2 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -22,8 +22,6 @@
 #include "config.h"
 #include "wine/port.h"
 
-#ifdef HAVE_LINUX_INPUT_H
-
 #include <assert.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -43,16 +41,10 @@
 #ifdef HAVE_SYS_ERRNO_H
 # include <sys/errno.h>
 #endif
-
-#ifdef HAVE_CORRECT_LINUXINPUT_H
-
 #ifdef HAVE_LINUX_INPUT_H
 # include <linux/input.h>
 #endif
 
-
-#define EVDEVPREFIX	"/dev/input/event"
-
 #include "wine/debug.h"
 #include "wine/unicode.h"
 #include "windef.h"
@@ -65,6 +57,10 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
 
+#ifdef HAVE_CORRECT_LINUXINPUT_H
+
+#define EVDEVPREFIX	"/dev/input/event"
+
 /* Wine joystick driver object instances */
 #define WINE_JOYSTICK_AXIS_BASE   0
 #define WINE_JOYSTICK_BUTTON_BASE 8
@@ -322,8 +318,7 @@
   return DIERR_DEVICENOTREG;
 }
 
-static dinput_device joydev = {
-  20,
+const struct dinput_device joystick_linuxinput_device = {
   "Wine Linux-input joystick driver",
   joydev_enum_deviceA,
   joydev_enum_deviceW,
@@ -331,8 +326,6 @@
   joydev_create_deviceW
 };
 
-DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
-
 /******************************************************************************
  *	Joystick
  */
@@ -1094,6 +1087,14 @@
 };
 #undef XCAST
 
-#endif  /* HAVE_LINUX_INPUT_H */
+#else  /* HAVE_CORRECT_LINUXINPUT_H */
 
-#endif
+struct dinput_device joystick_linuxinput_device = {
+  "Wine Linux-input joystick driver",
+  NULL,
+  NULL,
+  NULL,
+  NULL
+};
+
+#endif  /* HAVE_CORRECT_LINUXINPUT_H */
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 36628da..ceee1f5 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -289,8 +289,7 @@
   return DIERR_DEVICENOTREG;
 }
 
-static dinput_device keyboarddev = {
-  100,
+const struct dinput_device keyboard_device = {
   "Wine keyboard driver",
   keyboarddev_enum_deviceA,
   keyboarddev_enum_deviceW,
@@ -298,8 +297,6 @@
   keyboarddev_create_deviceW
 };
 
-DECL_GLOBAL_CONSTRUCTOR(keyboarddev_register) { dinput_register_device(&keyboarddev); }
-
 static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
 {
 	SysKeyboardImpl *This = (SysKeyboardImpl *)iface;
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 9086e1c..3394142 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -305,8 +305,8 @@
     
     return DIERR_DEVICENOTREG;
 }
-static dinput_device mousedev = {
-    100,
+
+const struct dinput_device mouse_device = {
     "Wine mouse driver",
     mousedev_enum_deviceA,
     mousedev_enum_deviceW,
@@ -314,8 +314,6 @@
     mousedev_create_deviceW
 };
 
-DECL_GLOBAL_CONSTRUCTOR(mousedev_register) { dinput_register_device(&mousedev); }
-
 /******************************************************************************
  *	SysMouseA (DInput Mouse support)
  */