How to use DirectX.DirectInput in XNA

joystick.cs

using System; using Microsoft.DirectX.DirectInput; namespace gameproject { /// <summary> /// Description of device. /// </summary> class joysticks { public static Device joystick; public static JoystickState state; public static void InitDevices() //Function of initialize device { //create joystick device. foreach (DeviceInstance di in Manager.GetDevices( DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)) { joystick = new Device(di.InstanceGuid); break; } if (joystick == null) { //Throw exception if joystick not found. } //Set joystick axis ranges. else { foreach (DeviceObjectInstance doi in joystick.Objects) { if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0) { joystick.Properties.SetRange( ParameterHow.ById, doi.ObjectId, new InputRange(-5000, 5000)); } } joystick.Properties.AxisModeAbsolute = true; joystick.SetCooperativeLevel(null,CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background); //Acquire devices for capturing. joystick.Acquire(); state = joystick.CurrentJoystickState; } } public static void UpdateJoystick() // Capturing from device joystick { //Get Joystick State. if(joystick!=null) state = joystick.CurrentJoystickState; } } } 

An error has occurred on this line,

  joystick.SetCooperativeLevel(null,CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background); 

error,

 Error 1 The type 'System.Windows.Forms.Control' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows.Forms... 

I work with XNA 3.0 and .NET 3.5, so what does this mean that a bug?

+1
source share
1 answer

SetCooperativeLevel takes a System.Windows.Forms.Control object as the first parameter (where you have zero), so you should still reference the assembly where this class is defined in your application. Add a link to System.Windows.Forms.dll from your application / game and try. If the code you use uses some other classes that you did not reference under the hood, this is normal, but when they are publicly available (for example, they are parameters or returned from the methods you call), you need to reference assemblies, in which these types are defined.

A similar stackoverflow message: Debugging error 'Type' xx 'defined in an assembly that is not referenced "

+2
source

Source: https://habr.com/ru/post/1397130/


All Articles