我还没有找到任何文章或教程,可以吗?它试图调用一个 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();
}
}
}
}