記事やチュートリアルが見つかりませんでした。可能ですか? Effect クラスを呼び出そうとしましたが、得られるのは
E_INVALIDARG: 返される関数に無効なパラメーターが渡されました (-2147024809)
コード
[TestClass]
public class ForceFeedbackTest
{
[TestMethod]
public void Test()
{
using (var form = new Form())
{
var directInput = new DirectInput();
foreach (var device in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
var controller = new Joystick(directInput, device.InstanceGuid);
controller.SetCooperativeLevel(form.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
controller.Acquire();
int xAxisOffset = 0, yAxisOffset = 0;
int nextOffset = 0;
foreach (DeviceObjectInstance d in controller.GetObjects())
{
if ((d.ObjectType & ObjectDeviceType.ForceFeedbackActuator)
!= 0)
{
if (nextOffset == 0)
xAxisOffset = d.Offset;
else
yAxisOffset = d.Offset;
nextOffset++;
}
}
int[] offsets = new int[2];
offsets[0] = xAxisOffset;
offsets[1] = yAxisOffset;
int[] coords = { 0, 0 };
var info = controller.GetEffects(EffectType.All).First();
var args = new EffectParameters();
args.Flags = EffectFlags.ObjectOffsets | EffectFlags.Cartesian;
var typeSpec = new ConstantForce();
args.Duration = 1000;
args.SamplePeriod = controller.Capabilities.ForceFeedbackSamplePeriod;
args.Parameters = typeSpec;
args.Gain = 5000;
args.SetAxes(offsets, coords);
args.StartDelay = 500;
var effect = new Effect(controller, info.Guid);
effect.SetParameters(args); //This is the line i get the error on.
effect.Start();
}
}
}
}