This should hopefully allow initailizing the joystick/haptic subsystems without calling SetVideoMode first. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Wed, 06 Aug 2008 09:52:51 +0000
branchgsoc2008_force_feedback
changeset 26236deba05725ac
parent 2622 446054caaa81
child 2624 c6476e26a783
This should hopefully allow initailizing the joystick/haptic subsystems without calling SetVideoMode first.
src/haptic/win32/SDL_syshaptic.c
src/joystick/win32/SDL_dxjoystick.c
     1.1 --- a/src/haptic/win32/SDL_syshaptic.c	Wed Aug 06 09:35:09 2008 +0000
     1.2 +++ b/src/haptic/win32/SDL_syshaptic.c	Wed Aug 06 09:52:51 2008 +0000
     1.3 @@ -91,7 +91,6 @@
     1.4  /*
     1.5   * External stuff.
     1.6   */
     1.7 -extern HINSTANCE SDL_Instance;
     1.8  extern HWND SDL_HelperWindow;
     1.9  
    1.10  
    1.11 @@ -146,6 +145,7 @@
    1.12  SDL_SYS_HapticInit(void)
    1.13  {
    1.14     HRESULT ret;
    1.15 +   HINSTANCE instance;
    1.16  
    1.17     if (dinput != NULL) { /* Already open. */
    1.18        SDL_SetError("Haptic: SubSystem already open.");
    1.19 @@ -171,7 +171,12 @@
    1.20     }
    1.21  
    1.22     /* Because we used CoCreateInstance, we need to Initialize it, first. */
    1.23 -   ret = IDirectInput_Initialize(dinput, SDL_Instance, DIRECTINPUT_VERSION);
    1.24 +   instance = GetModuleHandle(NULL);
    1.25 +   if (instance == NULL) {
    1.26 +      SDL_SetError("GetModuleHandle() failed with error code %d.", GetLastError());
    1.27 +      return -1;
    1.28 +   }
    1.29 +   ret = IDirectInput_Initialize(dinput, instance, DIRECTINPUT_VERSION);
    1.30     if (FAILED(ret)) {
    1.31        DI_SetError("Initializing DirectInput device",ret);
    1.32        return -1;
     2.1 --- a/src/joystick/win32/SDL_dxjoystick.c	Wed Aug 06 09:35:09 2008 +0000
     2.2 +++ b/src/joystick/win32/SDL_dxjoystick.c	Wed Aug 06 09:52:51 2008 +0000
     2.3 @@ -52,7 +52,6 @@
     2.4  #define JOY_AXIS_THRESHOLD	(((AXIS_MAX)-(AXIS_MIN))/100)   /* 1% motion */
     2.5  
     2.6  /* external variables referenced. */
     2.7 -extern HINSTANCE SDL_Instance;
     2.8  extern HWND SDL_HelperWindow;
     2.9  
    2.10  
    2.11 @@ -117,8 +116,13 @@
    2.12      }
    2.13  
    2.14      /* Because we used CoCreateInstance, we need to Initialize it, first. */
    2.15 +    instance = GetModuleHandle(NULL);
    2.16 +    if (instance == NULL) {
    2.17 +        SDL_SetError("GetModuleHandle() failed with error code %d.", GetLastError());
    2.18 +        return (-1);
    2.19 +    }
    2.20      result =
    2.21 -        IDirectInput_Initialize(dinput, SDL_Instance, DIRECTINPUT_VERSION);
    2.22 +        IDirectInput_Initialize(dinput, instance, DIRECTINPUT_VERSION);
    2.23  
    2.24      if (FAILED(result)) {
    2.25          SetDIerror("IDirectInput::Initialize", result);