none
VB.NET XInput

    Question

  • How do I use XInput in VB.NET so I can use the Xbox 360 Controller's Rumble feature & get all the button presses, the only examples I found show C++ but I need to access the controller in my VB.NET application...

    I can't even figure out how to make a reference to XInput to try & start using it or if I need to download something first(if I don't already have it installed.)

    By what I see a version of XInput comes with windows already in Windows Vista, but I wouldn't know what .dll to look for, where it's located or what references to add or how to use the .dll, like what api's I can use when having added it to my application to use.

    Tuesday, December 13, 2011 6:26 PM

Answers

  • Considering I have made unique code to my usage/situation I thought it appropriate to include how I defined the API's & the structures which hold the information from the api's & not provide my actual usage of the code so that it maybe easier to adapt the usage of the API's to your own situation, not be restricted by the way in which I used them.

    Private Declare Function XInputGetBatteryInformation Lib "xinput1_3.dll" (ByVal uJoyID As Integer, ByVal uJoyID2 As UInteger, ByRef GameState As XINPUT_BATTERY_INFORMATION) As Int16
        Private Declare Function XInputGetState Lib "xinput1_3.dll" (ByVal uJoyID As Integer, ByRef GameState As XINPUT_STATE) As Boolean
        Private Declare Function XInputSetState Lib "xinput1_3.dll" (ByVal uJoyID As Integer, ByRef GameState As XINPUT_VIBRATION) As Int16
    
        Private Structure XINPUT_BATTERY_INFORMATION
            Public BatteryType As Byte
            Public BatteryLevel As Byte
        End Structure
    
        Private Structure XINPUT_GAMEPAD
            Public wButtons As UInt16
            Public bLeftTrigger As Char
            Public bRightTrigger As Char
            Public sThumbLX As Int16
            Public sThumbLY As Int16
            Public sThumbRX As Int16
            Public sThumbRY As Int16
        End Structure
    
        Private Structure XINPUT_STATE
            Public dwPacketNumber As Integer
            Public Gamepad As XINPUT_GAMEPAD
        End Structure
    
        Private Structure XINPUT_VIBRATION
            Public wLeftMotorSpeed As UShort
            Public wRightMotorSpeed As UShort
        End Structure
    

    • Marked as answer by Michael Key Thursday, December 29, 2011 3:15 AM
    Thursday, December 29, 2011 3:14 AM

All replies

  • According to this MSDN page, the version of the XInput DLL that comes with Vista (XINPUT9_1_0.DLL) is out of date. The latest version (XINPUT1_4.DLL) ships with Windows 8, and earlier versions shipped with the DirectX SDK. The page also implies that the DLL is tailored for use in C++ applications, so it might take some trial and error to use it in a VB.Net application.
    Tuesday, December 13, 2011 6:53 PM
  • It likely means I have version 1.3 that comes with redist version of directx 2010 but I don't mind a lot of trial & error I just need to know how to reference XInput & access it so I can start trying to get ANY part of it to work.

    Can you help with that much?

    Tuesday, December 13, 2011 6:57 PM
  • First, find the DLL. I assume it will be called something like XINPUT1_3.DLL and will be in the folder(s) created when you installed the DirectX SDK.  Next, in your VB project, add a reference to the DLL (double-click the My Project node in solution explorer then click the references tab).  You should now be able to use the classes defined in the DLL.
    Tuesday, December 13, 2011 7:13 PM
  • I searched everything, in my search of the WHOLE filesystem i found a lot of input.dll but no other .dll files with the word input in them at all, I did a search without enabling the (case-sensitive) option as well & still nothing.

    As for where it installed to, I don't know, it was a default location, I tried to run through the installer again but it just says a newer or equivalent version of directx is already installed.

    How do I find the .dll I need & how do I start to use any of it to do something useful(interact with the controller in any way)

    Tuesday, December 13, 2011 8:09 PM
  • Is it DirectX you are trying to reinstall, or the DirectX SDK? It's the SDK you want. You can download it from http://www.microsoft.com/download/en/details.aspx?id=6812

    To actually use the DLL, you will need to find out what classes and methods it provides.  I would expect the SDK to include a C++ header file that describes them.

    • Edited by Blackwood Tuesday, December 13, 2011 8:17 PM
    Tuesday, December 13, 2011 8:15 PM
  • There are 3 downloads available, one looks like the sdk alone, dx & sdk, and then the web installer(dx alone)

    Both of the ones with the sdk just show me that message as above & still even though ive installed the one your telling me I need to install I can't find an Xinput dll.

    Tuesday, December 13, 2011 8:18 PM
  • If the DLL is not in the download, I'm afraid I don't know where it might be. There appears to be only one download on the page I linked to (DXSDK_Jun10.exe - about 570 MB). 

    When you double-click on the DXSDK_Jun10.exe file you downloaded, I assume it installed something somewhere. I can only suggest that you look through those folders looking for the DLL or some kind of help file.

    • Proposed as answer by Mike FengModerator Thursday, December 15, 2011 8:19 AM
    • Unproposed as answer by Michael Key Thursday, December 15, 2011 6:37 PM
    Tuesday, December 13, 2011 8:26 PM
  • Unfortunately not knowing isn't a real answer, I will leave this post open a while to see if anyone else can help me figure out how to get a reference to XInput & use it...I may just change languages to C++ if nobody answers back after a while because I really have to be able to use XInput for my current project to work.
    Thursday, December 15, 2011 6:38 PM
  • I went ahead and installed the SDK from DXSDK_Jun10.exe.  xinput1_3.dll is installed in Windows\System32\, and the C++ header file XInput.h is in Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\.

    XInput.h contains constant definitions and structure definitions that you may need to adapt for your VB code, as well as API definitions for the various methods available in the DLL such as XInputGetCapabilities, XInputSetState, etc. that you can adapt to call the methods from your VB code.
    Thursday, December 15, 2011 7:15 PM
  • Well I found what I needed in the file you mentioned, lots of code & everything, the only thing I was unable to move over to VB was the important part, the api's themselves, all the rest of it I have moved over already but since I don't know other languages besides VB I am unable to translate it & running the code through 12 different translators has yielded no results, I simply can't move the API code over myself, I don't understand what the code is because I don't know anything but VB.NET & no translators have helped me to understand the code any better so that I can translate it msyelf.

    Any help would be appreciated.

    Thursday, December 15, 2011 7:50 PM
  • As I said, it's likely to take some trial and error.  The method of calling the API should be similar to how you call the Windows API functions. Try looking in pinvoke.net for examples of calling Windows API functions and use the same techniques for the XInput functions.
    Thursday, December 15, 2011 8:05 PM
  • Blackwood, thanks, I just looked at other projects where I call API's (I don't write up my own code to call API's before now, I copy/paste it from somewhere else.)

    As far as things go I kind of got a little bit work done detecting buttons with 1 of the 3 api's but I can tell already it's going to be hard work getting things how they need to be so I can work with the controller, I will keep working on it & if I need further help, I will post here again.

    Regardless, I will post code for others when I am done, I have marked your other post as helpful showing me where the file is that has the code for the other language that made me able to even call the one API so far to get part of it working, thanks for that.

    Thursday, December 15, 2011 8:16 PM
  • Considering I have made unique code to my usage/situation I thought it appropriate to include how I defined the API's & the structures which hold the information from the api's & not provide my actual usage of the code so that it maybe easier to adapt the usage of the API's to your own situation, not be restricted by the way in which I used them.

    Private Declare Function XInputGetBatteryInformation Lib "xinput1_3.dll" (ByVal uJoyID As Integer, ByVal uJoyID2 As UInteger, ByRef GameState As XINPUT_BATTERY_INFORMATION) As Int16
        Private Declare Function XInputGetState Lib "xinput1_3.dll" (ByVal uJoyID As Integer, ByRef GameState As XINPUT_STATE) As Boolean
        Private Declare Function XInputSetState Lib "xinput1_3.dll" (ByVal uJoyID As Integer, ByRef GameState As XINPUT_VIBRATION) As Int16
    
        Private Structure XINPUT_BATTERY_INFORMATION
            Public BatteryType As Byte
            Public BatteryLevel As Byte
        End Structure
    
        Private Structure XINPUT_GAMEPAD
            Public wButtons As UInt16
            Public bLeftTrigger As Char
            Public bRightTrigger As Char
            Public sThumbLX As Int16
            Public sThumbLY As Int16
            Public sThumbRX As Int16
            Public sThumbRY As Int16
        End Structure
    
        Private Structure XINPUT_STATE
            Public dwPacketNumber As Integer
            Public Gamepad As XINPUT_GAMEPAD
        End Structure
    
        Private Structure XINPUT_VIBRATION
            Public wLeftMotorSpeed As UShort
            Public wRightMotorSpeed As UShort
        End Structure
    

    • Marked as answer by Michael Key Thursday, December 29, 2011 3:15 AM
    Thursday, December 29, 2011 3:14 AM