src/haptic/windows/SDL_syshaptic.c
changeset 5591 17beb16fa838
parent 5539 b305e3c2d2e7
child 6138 4c64952a58fb
equal deleted inserted replaced
5590:db152c9f31c3 5591:17beb16fa838
    66 
    66 
    67 
    67 
    68 /*
    68 /*
    69  * Internal stuff.
    69  * Internal stuff.
    70  */
    70  */
       
    71 static SDL_bool coinitialized = SDL_FALSE;
    71 static LPDIRECTINPUT dinput = NULL;
    72 static LPDIRECTINPUT dinput = NULL;
    72 
    73 
    73 
    74 
    74 /*
    75 /*
    75  * External stuff.
    76  * External stuff.
   145     /* Clear all the memory. */
   146     /* Clear all the memory. */
   146     SDL_memset(SDL_hapticlist, 0, sizeof(SDL_hapticlist));
   147     SDL_memset(SDL_hapticlist, 0, sizeof(SDL_hapticlist));
   147 
   148 
   148     SDL_numhaptics = 0;
   149     SDL_numhaptics = 0;
   149 
   150 
   150     ret = CoInitialize(NULL);
   151     ret = WIN_CoInitialize();
   151     if (FAILED(ret)) {
   152     if (FAILED(ret)) {
   152         DI_SetError("Coinitialize", ret);
   153         DI_SetError("Coinitialize", ret);
   153         return -1;
   154         return -1;
   154     }
   155     }
       
   156 
       
   157     coinitialized = SDL_TRUE;
   155 
   158 
   156     ret = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER,
   159     ret = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER,
   157                            &IID_IDirectInput, (LPVOID) & dinput);
   160                            &IID_IDirectInput, (LPVOID) & dinput);
   158     if (FAILED(ret)) {
   161     if (FAILED(ret)) {
       
   162         SDL_SYS_HapticQuit();
   159         DI_SetError("CoCreateInstance", ret);
   163         DI_SetError("CoCreateInstance", ret);
   160         return -1;
   164         return -1;
   161     }
   165     }
   162 
   166 
   163     /* Because we used CoCreateInstance, we need to Initialize it, first. */
   167     /* Because we used CoCreateInstance, we need to Initialize it, first. */
   164     instance = GetModuleHandle(NULL);
   168     instance = GetModuleHandle(NULL);
   165     if (instance == NULL) {
   169     if (instance == NULL) {
       
   170         SDL_SYS_HapticQuit();
   166         SDL_SetError("GetModuleHandle() failed with error code %d.",
   171         SDL_SetError("GetModuleHandle() failed with error code %d.",
   167                      GetLastError());
   172                      GetLastError());
   168         return -1;
   173         return -1;
   169     }
   174     }
   170     ret = IDirectInput_Initialize(dinput, instance, DIRECTINPUT_VERSION);
   175     ret = IDirectInput_Initialize(dinput, instance, DIRECTINPUT_VERSION);
   171     if (FAILED(ret)) {
   176     if (FAILED(ret)) {
       
   177         SDL_SYS_HapticQuit();
   172         DI_SetError("Initializing DirectInput device", ret);
   178         DI_SetError("Initializing DirectInput device", ret);
   173         return -1;
   179         return -1;
   174     }
   180     }
   175 
   181 
   176     /* Look for haptic devices. */
   182     /* Look for haptic devices. */
   179                                    EnumHapticsCallback,
   185                                    EnumHapticsCallback,
   180                                    NULL,
   186                                    NULL,
   181                                    DIEDFL_FORCEFEEDBACK |
   187                                    DIEDFL_FORCEFEEDBACK |
   182                                    DIEDFL_ATTACHEDONLY);
   188                                    DIEDFL_ATTACHEDONLY);
   183     if (FAILED(ret)) {
   189     if (FAILED(ret)) {
       
   190         SDL_SYS_HapticQuit();
   184         DI_SetError("Enumerating DirectInput devices", ret);
   191         DI_SetError("Enumerating DirectInput devices", ret);
   185         return -1;
   192         return -1;
   186     }
   193     }
   187 
   194 
   188     return SDL_numhaptics;
   195     return SDL_numhaptics;
   662             SDL_free(SDL_hapticlist[i].name);
   669             SDL_free(SDL_hapticlist[i].name);
   663             SDL_hapticlist[i].name = NULL;
   670             SDL_hapticlist[i].name = NULL;
   664         }
   671         }
   665     }
   672     }
   666 
   673 
   667     IDirectInput_Release(dinput);
   674     if (dinput != NULL) {
   668     dinput = NULL;
   675         IDirectInput_Release(dinput);
       
   676         dinput = NULL;
       
   677     }
       
   678 
       
   679     if (coinitialized) {
       
   680         WIN_CoUninitialize();
       
   681         coinitialized = SDL_FALSE;
       
   682     }
   669 }
   683 }
   670 
   684 
   671 
   685 
   672 /*
   686 /*
   673  * Converts an SDL trigger button to an DIEFFECT trigger button.
   687  * Converts an SDL trigger button to an DIEFFECT trigger button.