0

I've been trying to implement DirectInput into unity using SharpDX.DirectInput dlls, but when i create a joystick, it gives me an error:

SharpDXException: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

and here is my code:

using System;
using UnityEngine;
using SharpDX.DirectInput;


namespace KurdifyEngine.Input
{
static class Direct
{
    public static DirectInput directInput;
    public static Guid directGuid;
    public static Joystick directGamepad ;
    internal static void Initialize()
    {
        // Initialize DirectInput
        directInput = new DirectInput();
        directGuid = Guid.Empty;
        DirectUpdate();


    }
    internal static void DirectUpdate()
    {
        // search for Gamepad
        foreach (var deviceInstance in directInput.GetDevices(SharpDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly))
            directGuid = deviceInstance.InstanceGuid;
        }
        if (directGuid != Guid.Empty)
        {
            directGamepad = new Joystick(directInput, directGuid);
        }
    }
}

}

the error happens when i create a joystick:

directGamepad = new Joystick(directInput, directGuid);
Shkar T. Noori
  • 263
  • 2
  • 6
  • I doubt that you will be able to mix SharpDX (a rendering framework / game engine) with Unity (a rendering framework / game engine). And why even bother? Unity has built-in support for joysticks/gamepads and if that doesn't suffice you'll find even better support on the asset store. – CodeSmile Oct 31 '14 at 18:40
  • It worked for someone else, and The built-in support is lacking a lot of features, I already made support for XInput, runtime keybinding, i just want to know how to to it myself, and I don't want to rely in asset store assets. – Shkar T. Noori Oct 31 '14 at 20:26

1 Answers1

1

We have been developing exotic controller support for a Unity product and encountered the same problem (SharpDXException: HRESULT: [0x80070057]) on the exact same line.

We tried recompiling the SharpDX by fixing it like it is explained in this github post: https://github.com/sharpdx/SharpDX/issues/406 but encountered other problems with the DirectX (June 2010) SDK.

We just found a way to compile our Unity project using the libraries included in this project (which is an add-on for exotic controllers support in Kerbal Space Program): https://github.com/pbatard/AltInput just pick up the .dll under Libraries/, replace your old .dll by these and you're good to go !

Guillaume
  • 11
  • 2