本文整理汇总了C++中DI_SetError函数的典型用法代码示例。如果您正苦于以下问题:C++ DI_SetError函数的具体用法?C++ DI_SetError怎么用?C++ DI_SetError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DI_SetError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SDL_SYS_HapticOpenFromInstance
/*
* Opens the haptic device from the file descriptor.
*
* Steps:
* - Open temporary DirectInputDevice interface.
* - Create DirectInputDevice8 interface.
* - Release DirectInputDevice interface.
* - Call SDL_SYS_HapticOpenFromDevice8
*/
static int
SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance)
{
HRESULT ret;
int ret2;
LPDIRECTINPUTDEVICE8 device;
LPDIRECTINPUTDEVICE8 device8;
/* Open the device */
ret = IDirectInput8_CreateDevice(dinput, &instance.guidInstance,
&device, NULL);
if (FAILED(ret)) {
DI_SetError("Creating DirectInput device", ret);
return -1;
}
/* Now get the IDirectInputDevice8 interface, instead. */
ret = IDirectInputDevice8_QueryInterface(device,
&IID_IDirectInputDevice8,
(LPVOID *) &device8);
/* Done with the temporary one now. */
IDirectInputDevice8_Release(device);
if (FAILED(ret)) {
DI_SetError("Querying DirectInput interface", ret);
return -1;
}
ret2 = SDL_SYS_HapticOpenFromDevice8(haptic, device8, SDL_FALSE);
if (ret2 < 0) {
IDirectInputDevice8_Release(device8);
return -1;
}
return 0;
}
示例2: SDL_DINPUT_HapticOpen
int
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
{
HRESULT ret;
LPDIRECTINPUTDEVICE8 device;
LPDIRECTINPUTDEVICE8 device8;
/* Open the device */
ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance,
&device, NULL);
if (FAILED(ret)) {
DI_SetError("Creating DirectInput device", ret);
return -1;
}
/* Now get the IDirectInputDevice8 interface, instead. */
ret = IDirectInputDevice8_QueryInterface(device,
&IID_IDirectInputDevice8,
(LPVOID *)&device8);
/* Done with the temporary one now. */
IDirectInputDevice8_Release(device);
if (FAILED(ret)) {
DI_SetError("Querying DirectInput interface", ret);
return -1;
}
if (SDL_DINPUT_HapticOpenFromDevice(haptic, device8, SDL_FALSE) < 0) {
IDirectInputDevice8_Release(device8);
return -1;
}
return 0;
}
示例3: SDL_SYS_HapticInit
/*
* Initializes the haptic subsystem.
*/
int
SDL_SYS_HapticInit(void)
{
HRESULT ret;
HINSTANCE instance;
if (dinput != NULL) { /* Already open. */
SDL_SetError("Haptic: SubSystem already open.");
return -1;
}
/* Clear all the memory. */
SDL_memset(SDL_hapticlist, 0, sizeof(SDL_hapticlist));
SDL_numhaptics = 0;
ret = CoInitialize(NULL);
if (FAILED(ret)) {
DI_SetError("Coinitialize", ret);
return -1;
}
ret = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER,
&IID_IDirectInput, (LPVOID) & dinput);
if (FAILED(ret)) {
DI_SetError("CoCreateInstance", ret);
return -1;
}
/* Because we used CoCreateInstance, we need to Initialize it, first. */
instance = GetModuleHandle(NULL);
if (instance == NULL) {
SDL_SetError("GetModuleHandle() failed with error code %d.",
GetLastError());
return -1;
}
ret = IDirectInput_Initialize(dinput, instance, DIRECTINPUT_VERSION);
if (FAILED(ret)) {
DI_SetError("Initializing DirectInput device", ret);
return -1;
}
/* Look for haptic devices. */
ret = IDirectInput_EnumDevices(dinput,
0,
EnumHapticsCallback,
NULL,
DIEDFL_FORCEFEEDBACK |
DIEDFL_ATTACHEDONLY);
if (FAILED(ret)) {
DI_SetError("Enumerating DirectInput devices", ret);
return -1;
}
return SDL_numhaptics;
}
示例4: SDL_SYS_HapticOpenFromInstance
/*
* Opens the haptic device from the file descriptor.
*
* Steps:
* - Open temporary DirectInputDevice interface.
* - Create DirectInputDevice2 interface.
* - Release DirectInputDevice interface.
* - Call SDL_SYS_HapticOpenFromDevice2
*/
static int
SDL_SYS_HapticOpenFromInstance(SDL_Haptic * haptic, DIDEVICEINSTANCE instance)
{
HRESULT ret;
int ret2;
LPDIRECTINPUTDEVICE device;
/* Allocate the hwdata */
haptic->hwdata = (struct haptic_hwdata *)
SDL_malloc(sizeof(*haptic->hwdata));
if (haptic->hwdata == NULL) {
SDL_OutOfMemory();
goto creat_err;
}
SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
/* Open the device */
ret = IDirectInput_CreateDevice(dinput, &instance.guidInstance,
&device, NULL);
if (FAILED(ret)) {
DI_SetError("Creating DirectInput device", ret);
goto creat_err;
}
/* Now get the IDirectInputDevice2 interface, instead. */
ret = IDirectInputDevice_QueryInterface(device,
&IID_IDirectInputDevice2,
(LPVOID *) & haptic->hwdata->
device);
/* Done with the temporary one now. */
IDirectInputDevice_Release(device);
if (FAILED(ret)) {
DI_SetError("Querying DirectInput interface", ret);
goto creat_err;
}
ret2 = SDL_SYS_HapticOpenFromDevice2(haptic, haptic->hwdata->device);
if (ret2 < 0) {
goto query_err;
}
return 0;
query_err:
IDirectInputDevice2_Release(haptic->hwdata->device);
creat_err:
if (haptic->hwdata != NULL) {
SDL_free(haptic->hwdata);
haptic->hwdata = NULL;
}
return -1;
}
示例5: SDL_DINPUT_HapticInit
int
SDL_DINPUT_HapticInit(void)
{
HRESULT ret;
HINSTANCE instance;
if (dinput != NULL) { /* Already open. */
return SDL_SetError("Haptic: SubSystem already open.");
}
ret = WIN_CoInitialize();
if (FAILED(ret)) {
return DI_SetError("Coinitialize", ret);
}
coinitialized = SDL_TRUE;
ret = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
&IID_IDirectInput8, (LPVOID)& dinput);
if (FAILED(ret)) {
SDL_SYS_HapticQuit();
return DI_SetError("CoCreateInstance", ret);
}
/* Because we used CoCreateInstance, we need to Initialize it, first. */
instance = GetModuleHandle(NULL);
if (instance == NULL) {
SDL_SYS_HapticQuit();
return SDL_SetError("GetModuleHandle() failed with error code %lu.",
GetLastError());
}
ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
if (FAILED(ret)) {
SDL_SYS_HapticQuit();
return DI_SetError("Initializing DirectInput device", ret);
}
/* Look for haptic devices. */
ret = IDirectInput8_EnumDevices(dinput,
0,
EnumHapticsCallback,
NULL,
DIEDFL_FORCEFEEDBACK |
DIEDFL_ATTACHEDONLY);
if (FAILED(ret)) {
SDL_SYS_HapticQuit();
return DI_SetError("Enumerating DirectInput devices", ret);
}
return 0;
}
示例6: SDL_DINPUT_HapticNewEffect
int
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
{
HRESULT ret;
REFGUID type = SDL_SYS_HapticEffectType(base);
if (type == NULL) {
SDL_SetError("Haptic: Unknown effect type.");
return -1;
}
/* Get the effect. */
if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
goto err_effectdone;
}
/* Create the actual effect. */
ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
&effect->hweffect->effect,
&effect->hweffect->ref, NULL);
if (FAILED(ret)) {
DI_SetError("Unable to create effect", ret);
goto err_effectdone;
}
return 0;
err_effectdone:
SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type);
return -1;
}
示例7: SDL_SYS_HapticRunEffect
/*
* Runs an effect.
*/
int
SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
Uint32 iterations)
{
HRESULT ret;
DWORD iter;
if (haptic->hwdata->bXInputHaptic) {
XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
SDL_assert(effect->effect.type == SDL_HAPTIC_SINE); /* should catch this at higher level */
SDL_LockMutex(haptic->hwdata->mutex);
haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.periodic.length * iterations);
SDL_UnlockMutex(haptic->hwdata->mutex);
return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;
}
/* Check if it's infinite. */
if (iterations == SDL_HAPTIC_INFINITY) {
iter = INFINITE;
} else
iter = iterations;
/* Run the effect. */
ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0);
if (FAILED(ret)) {
return DI_SetError("Running the effect", ret);
}
return 0;
}
示例8: SDL_SYS_HapticUpdateEffect
/*
* Updates an effect.
*/
int
SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
struct haptic_effect *effect,
SDL_HapticEffect * data)
{
HRESULT ret;
DWORD flags;
DIEFFECT temp;
if (haptic->hwdata->bXInputHaptic) {
/* !!! FIXME: this isn't close to right. We only support "sine" effects,
* !!! FIXME: we ignore most of the parameters, and we probably get
* !!! FIXME: the ones we don't ignore wrong, too.
* !!! FIXME: if I had a better understanding of how the two motors
* !!! FIXME: could be used in unison, perhaps I could implement other
* !!! FIXME: effect types?
*/
/* From MSDN:
"Note that the right motor is the high-frequency motor, the left
motor is the low-frequency motor. They do not always need to be
set to the same amount, as they provide different effects." */
XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
SDL_assert(data->type == SDL_HAPTIC_SINE);
vib->wLeftMotorSpeed = vib->wRightMotorSpeed = data->periodic.magnitude * 2;
return 0;
}
/* Get the effect. */
SDL_memset(&temp, 0, sizeof(DIEFFECT));
if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) {
goto err_update;
}
/* Set the flags. Might be worthwhile to diff temp with loaded effect and
* only change those parameters. */
flags = DIEP_DIRECTION |
DIEP_DURATION |
DIEP_ENVELOPE |
DIEP_STARTDELAY |
DIEP_TRIGGERBUTTON |
DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
/* Create the actual effect. */
ret =
IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
if (FAILED(ret)) {
DI_SetError("Unable to update effect", ret);
goto err_update;
}
/* Copy it over. */
SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type);
SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT));
return 0;
err_update:
SDL_SYS_HapticFreeDIEFFECT(&temp, data->type);
return -1;
}
示例9: SDL_DINPUT_HapticDestroyEffect
void
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
{
HRESULT ret;
ret = IDirectInputEffect_Unload(effect->hweffect->ref);
if (FAILED(ret)) {
DI_SetError("Removing effect from the device", ret);
}
SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, effect->effect.type);
}
示例10: SDL_DINPUT_HapticStopEffect
int
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
{
HRESULT ret;
ret = IDirectInputEffect_Stop(effect->hweffect->ref);
if (FAILED(ret)) {
return DI_SetError("Unable to stop effect", ret);
}
return 0;
}
示例11: SDL_DINPUT_HapticUpdateEffect
int
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
{
HRESULT ret;
DWORD flags;
DIEFFECT temp;
/* Get the effect. */
SDL_memset(&temp, 0, sizeof(DIEFFECT));
if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) {
goto err_update;
}
/* Set the flags. Might be worthwhile to diff temp with loaded effect and
* only change those parameters. */
flags = DIEP_DIRECTION |
DIEP_DURATION |
DIEP_ENVELOPE |
DIEP_STARTDELAY |
DIEP_TRIGGERBUTTON |
DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
/* Create the actual effect. */
ret =
IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
if (ret == DIERR_NOTEXCLUSIVEACQUIRED) {
IDirectInputDevice8_Unacquire(haptic->hwdata->device);
ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND);
if (SUCCEEDED(ret)) {
ret = DIERR_NOTACQUIRED;
}
}
if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED) {
ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
if (SUCCEEDED(ret)) {
ret = IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
}
}
if (FAILED(ret)) {
DI_SetError("Unable to update effect", ret);
goto err_update;
}
/* Copy it over. */
SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type);
SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT));
return 0;
err_update:
SDL_SYS_HapticFreeDIEFFECT(&temp, data->type);
return -1;
}
示例12: SDL_DINPUT_HapticStopAll
int
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
{
HRESULT ret;
/* Try to stop the effects. */
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
DISFFC_STOPALL);
if (FAILED(ret)) {
return DI_SetError("Stopping the device", ret);
}
return 0;
}
示例13: SDL_DINPUT_HapticUnpause
int
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
{
HRESULT ret;
/* Unpause the device. */
ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
DISFFC_CONTINUE);
if (FAILED(ret)) {
return DI_SetError("Pausing the device", ret);
}
return 0;
}
示例14: SDL_SYS_HapticNewEffect
/*
* Creates a new haptic effect.
*/
int
SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
SDL_HapticEffect * base)
{
HRESULT ret;
REFGUID type = SDL_SYS_HapticEffectType(base);
if (type == NULL) {
goto err_hweffect;
}
/* Alloc the effect. */
effect->hweffect = (struct haptic_hweffect *)
SDL_malloc(sizeof(struct haptic_hweffect));
if (effect->hweffect == NULL) {
SDL_OutOfMemory();
goto err_hweffect;
}
SDL_zerop(effect->hweffect);
if (haptic->hwdata->bXInputHaptic) {
SDL_assert(base->type == SDL_HAPTIC_SINE); /* should catch this at higher level */
return SDL_SYS_HapticUpdateEffect(haptic, effect, base);
}
/* Get the effect. */
if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
goto err_effectdone;
}
/* Create the actual effect. */
ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
&effect->hweffect->effect,
&effect->hweffect->ref, NULL);
if (FAILED(ret)) {
DI_SetError("Unable to create effect", ret);
goto err_effectdone;
}
return 0;
err_effectdone:
SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type);
err_hweffect:
if (effect->hweffect != NULL) {
SDL_free(effect->hweffect);
effect->hweffect = NULL;
}
return -1;
}
示例15: SDL_DINPUT_HapticGetEffectStatus
int
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
{
HRESULT ret;
DWORD status;
ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status);
if (FAILED(ret)) {
return DI_SetError("Getting effect status", ret);
}
if (status == 0)
return SDL_FALSE;
return SDL_TRUE;
}