#2 XInputSetState Access Violation Error

open
nobody
None
5
2010-03-28
2010-03-28
TOC
No

Hello Clootie!

There is an definition in the Delphi7-XInput.pas I don´t understand and it produces a very bad address violation:

Line # 353 in XInput.pas, Delphi7 Version:

function XInputSetState(
dwUserIndex: DWORD;
// [in] Index of the gamer associated with the device
const pVibration: TXInputVibration // <-- Possibly an Type Error
//[in, out] The vibration information to send to the controller
): DWORD; stdcall; external XINPUT_DLL;

Whenever I call this function with the values of TXInputVibration.wLeftMotorSpeed or TXInputVibration.wRightMotorSpeed set to something not equal to 0 it results in an address violation error! And even with 0 values the rumble motors don´t respond.

I figured out that changing that definition to:

Function XInputSetState(
dwUserIndex: DWORD;
Const pVibration: PXInputVibration // <-- Changed type to pointer here
): DWORD; StdCall; External XINPUT_DLL;

...solves that issue. But I´m not very satisfied with that solution.

Anyway, within the comment of Your original code You define:

Const pVibration: TXInputVibration // <-- Possible Error
//[in, out] The vibration information to send to the controller

Well, If it should be a [in, out] parameter I suggest to change that definition to:

Function XInputSetState(
dwUserIndex: DWORD;
Var pVibration:TPXInputVibration // <-- I Changed "Const" to "Var" here
): DWORD; StdCall;
External XINPUT_DLL;

This seems to be a better solution for that issue for Me.
With that change the both rumble motor of My XBox 360 controller respond and no more access violations will occur.

Best Regards.

Discussion