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.
Last suggestion is indeed the correct code. [in, out] in C++ almost always means you need a var for a reference but not when it's a pointer value! Note: The usual way when C/C++ hints to a pointer, is a parameter starting with pp (with some exceptions) starting with ppp is always a pointer value to be declared in Delphi and almost always when it points to an array.
Last edit: FactoryX 2019-12-24