/// <summary>
 ///
 /// </summary>
 public static void RemoveInputDevice(ExternalControllerDevice device)
 {
     if (device == null)
     {
         return;
     }
     instances.Remove(device.handle);
     device.handle = -1;
 }
 /// <summary>
 ///
 /// </summary>
 public static void SetInputDevice(int which, ExternalControllerDevice device)
 {
     if (instances.ContainsKey(which))
     {
         instances[which] = device;
     }
     else
     {
         instances.Add(which, device);
     }
 }
        public static int SendMessage(int which, int Msg, int wParam, int lParam)
        {
            ExternalControllerDevice device = ExternalControllerDevice.GetInputDevice(which);

            if (device == null)
            {
                return(-1);
            }
            //
            return(device.SendMessage(Msg, wParam, lParam));
        }
        public static int GetInputState(int which, ref XDevicePlugin.ControllerState state)
        {
            ExternalControllerDevice device = ExternalControllerDevice.GetInputDevice(which);

            if (device == null)
            {
                return(-1);
            }
            //
            return(device.GetInputState(ref state));
        }
        /// <summary>
        ///
        /// </summary>
        public virtual int GetInputDeviceHandle()
        {
            //
            if (handle >= 0)
            {
                return(handle);
            }
            // Natives
            int ret = XDevicePlugin.GetInputDeviceHandle(name);

            if (ret >= 0)
            {
                XDevicePlugin.RemoveInputDeviceAt(ret);
            }                                                                      // Remove the same name device...
            //
            ret = XDevicePlugin.AddExternalControllerDevice(name, ExternalControllerDevice.GetInputState, ExternalControllerDevice.SendMessage);
            XDevicePlugin.SetInt(ret, XDevicePlugin.kField_ConnectionStateInt, (int)DeviceConnectionState.Connected);
            // Managed
            ExternalControllerDevice.RemoveInputDevice(ExternalControllerDevice.GetInputDevice(name));                    // Remove the same name device...
            ExternalControllerDevice.SetInputDevice(handle = ret, this);
            return(ret);
        }