This is in a similar strain to the DLL I released a while back, just doesn't have all the functionality pre-mapped.
//
// Title XInput Source
// Author Robert Lettan
// DBPro 1.06.0 (Release Only) And Above
// API 1.0, 1.1 (Sound Render and Capture Not Supported Currently)
//
// XInput.dba - Entry point for XInput System for DarkBASIC Professional
//
// XInput Constants
//
#Constant XINPUT_1_0 WinDir$() + "system32xinput9_1_0.dll"
#Constant XINPUT_1_1 WinDir$() + "system32xinput1_1.dll"
#Constant XINPUT_MAX_USERS 4
#Constant XINPUT_ERROR_SUCCESS 0
#Constant XINPUT_ERROR_UNSUPPORTED 404
#Constant XINPUT_ERROR_DLLEXIST 405
#Constant XINPUT_ERROR_DLLNOTEXIST 406
//
// Device types available in XINPUT_CAPABILITIES
//
#Constant XINPUT_DEVTYPE_GAMEPAD 0x01
//
// Device subtypes available in XINPUT_CAPABILITIES
//
#Constant XINPUT_DEVSUBTYPE_GAMEPAD 0x01
#Constant XINPUT_DEVSUBTYPE_WHEEL 0x02
#Constant XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
#Constant XINPUT_DEVSUBTYPE_FLIGHT_SICK 0x04
#Constant XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
//
// Flags for XINPUT_CAPABILITIES
//
#Constant XINPUT_CAPS_VOICE_SUPPORTED 0x0004
//
// Constants for gamepad buttons
//
#Constant XINPUT_GAMEPAD_DPAD_UP 0x0001
#Constant XINPUT_GAMEPAD_DPAD_DOWN 0x0002
#Constant XINPUT_GAMEPAD_DPAD_LEFT 0x0004
#Constant XINPUT_GAMEPAD_DPAD_RIGHT 0x0008
#Constant XINPUT_GAMEPAD_START 0x0010
#Constant XINPUT_GAMEPAD_BACK 0x0020
#Constant XINPUT_GAMEPAD_LEFT_THUMB 0x0040
#Constant XINPUT_GAMEPAD_RIGHT_THUMB 0x0080
#Constant XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
#Constant XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
#Constant XINPUT_GAMEPAD_A 0x1000
#Constant XINPUT_GAMEPAD_B 0x2000
#Constant XINPUT_GAMEPAD_X 0x4000
#Constant XINPUT_GAMEPAD_Y 0x8000
//
// Gamepad thresholds
//
#Constant XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE 7849
#Constant XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689
#Constant XINPUT_GAMEPAD_TRIGGER_THRESHOLD 30
//
// Flags to pass to XInputGetCapabilities
//
#Constant XINPUT_FLAG_GAMEPAD 0x00000001
//
// XInput API
//
Using_XInput:
//
// Structures used by XInput APIs
//
Type _XINPUT_GAMEPAD
wButtons As Word
bLeftTrigger As Byte
bRightTrigger As Byte
sThumbLX As Integer
sThumbLY As Integer
sThumbRX As Integer
sThumbRY As Integer
EndType
Type _XINPUT_STATE
dwPacketNumber As Dword
Gamepad As _XINPUT_GAMEPAD
EndType
Type _XINPUT_VIBRATION
wLeftMotorSpeed As Word
wRightMotorSpeed As Word
EndType
Type _XINPUT_CAPABILITIES
bType As Byte
bSubType As Byte
wFlags As Word
Gamepad As _XINPUT_GAMEPAD
Vibration As _XINPUT_VIBRATION
EndType
Type _XINPUT
State As _XINPUT_STATE
Vibration As _XINPUT_VIBRATION
EndType
Global Dim XInput(XINPUT_MAX_USERS) As _XINPUT
Global Dim XInputCapabilities(XINPUT_MAX_USERS) As _XINPUT_CAPABILITIES
Global XInputVersion As Float
Global XInputDLL As Byte
XInputStart()
Return
//
// Alternative DLL Loading Function
//
Function XInputLoadDLL(szFileName As String)
Local Index As Dword = 1
While DLL Exist(Index) : EndWhile
EndFunction Index
//
// XInput API Functions
//
Function XInputGetState(dwUserIndex As Dword)
Local Result, pState As Dword = XINPUT_ERROR_UNSUPPORTED
Local Dim State(void) As XINPUT_STATE
If DLL Exist(XInputDLL)
State(void) = XInput(dwUserIndex).State
pState = State(void)
Result = Call DLL(XInputDLL, "XInputGetState", dwUserIndex, pGamepad)
EndIf
EndFunction Result
Function XInputSetState(dwUserIndex As Dword)
Local Result, pVibration As Dword = XINPUT_ERROR_UNSUPPORTED
Local Dim Vibration(void) As XINPUT_VIBRATION
If DLL Exist(XInputDLL)
Vibration(void) = XInput(dwUserIndex).Vibration
pVibration = Vibration(void)
Result = Call DLL(XInputDLL, "XInputSetState", dwUserIndex, pVibration)
EndIf
EndFunction Result
Function XInputGetCapabilities(dwUserIndex As Dword, dwFlags As Dword)
Local Result, pCapabilities As Dword = XINPUT_ERROR_UNSUPPORTED
If DLL Exist(XInputDLL)
pCapabilities = XInputCapabilities(dwUserIndex)
Result = Call DLL(XInputDLL, "XInputGetCapabilities", dwUserIndex, dwFlags, pCapabilities)
EndIf
EndFunction Result
Function XInputEnable(bEnable As Boolean)
If DLL Exist(XInputDLL)
If XInputVersion > 1.1
Call DLL XInputDLL, "XInputEnable", bEnable
Else
ExitFunction XINPUT_ERROR_UNSUPPORTED
EndIf
EndIf
EndFunction XINPUT_ERROR_SUCCESS
Function XInputStart()
If DLL Exist(XInputDLL) = False
If File Exist(XINPUT_1_1)
XInputVersion = 1.1
XInputDLL = XInputLoadDLL(XINPUT_1_0)
EndIf
If File Exist(XINPUT_1_0)
XInputVersion = 1.0
XInputDLL = XInputLoadDLL(XINPUT_1_0)
EndIf
Else
ExitFunction XINPUT_ERROR_DLLEXIST
EndIf
EndFunction XINPUT_ERROR_SUCCESS
Function XInputRelease()
If DLL Exist(XInputDLL)
Delete DLL XInput
Else
ExitFunction XINPUT_ERROR_DLLNOTEXIST
EndIf
EndFunction XINPUT_ERROR_SUCCESS
It'll load the XInput DLL, and you can then use the GetState to get what the controller is currently doing, (stored in XInput(User).State.Gamepad) and SetState to set the Rumble (your store that in XInput(User).Vibration)
I mean some features are cut out as I've ported the API directly so you can use it with code rather than a DLL, should make your source about 20kb smaller as a result; but won't run as quickly or is quite a simple to use.
Still I'm sure someone will find some use for it.
[edit] Almost forgot to add... to use this straight, just add the line:
GoSub Using_XInput
to the top of your code. before End you'll want to use XInputRelease()