Jump to content
Sign in to follow this  
SkellySoul

Xbox Dll Call

Recommended Posts

SkellySoul

Hello :mellow:

I just bought a Xbox Controller for the PC and been playing around with it and have just about everything functional except I don't know how to call this Dll to get the battery life.

http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.xinputgetbatteryinformation

Also is it possible to make the Xbox Guide button functional and may be any code to mess with the lights :)

Thanks :)

Share this post


Link to post
Share on other sites
monoscout999

what dll?

EDIT: Are you talking about autoIt? because as far i can see there is no DLL only a C++ Library, but my knowldege is few maybe someone else can point you to the right direction.

more EDIT: Usually MSDN put you as requirements the DLL you need, when this is not there it means that there`s no dll at all.

more and more EDIT: ...the mouse ate your tonge? jijiji

and more of that EDIT: ...i don`t know to much but maybe AutoItObject can help you with this quest.

Edited by monoscout999

Share this post


Link to post
Share on other sites
SkellySoul

what dll?

EDIT: Are you talking about autoIt? because as far i can see there is no DLL only a C++ Library, but my knowldege is few maybe someone else can point you to the right direction.

more EDIT: Usually MSDN put you as requirements the DLL you need, when this is not there it means that there`s no dll at all.

more and more EDIT: ...the mouse ate your tonge? jijiji

and more of that EDIT: ...i don`t know to much but maybe AutoItObject can help you with this quest.

xinput9_1_0.dll

Share this post


Link to post
Share on other sites
monoscout999

i didn`t find it, please point me to the documentation of that dll, because MSDN doesn`t say anything about that...

Only guessing, thrusting in that the dll might work this way. and also thrusting that you know what means every parameter of this function.

DllCall("xinput9_1_0.dll","dword","XInputGetBatteryInformation","dword",$UserIndex,"byte",$devType,"ptr",DllStructGetPtr($tXINPUT_BATTERY_INFORMATION))

Mainly something like this.

After that

$BatteryType = DllStructGetData($tXINPUT_BATTERY_INFORMATION,1)
$BatteryLevel = DllStructGetData($tXINPUT_BATTERY_INFORMATION,2)
Edited by monoscout999

Share this post


Link to post
Share on other sites
smashly

Hi, have you actually tried calling any of the Xinput functions?

I've been calling xinput1_3.dll and the XInputGetBatteryInformation works for me in xp x86, not tried it in win 7 yet.

It's a pretty straight forward api call.

Share this post


Link to post
Share on other sites
JohnOne

I'm usually wrong with dll witchcraft but imagine it would look something like this.

$type = "?" ; Dont know where you get this from, I assume you do.
$Index = "?" ; same

$OutStruct = DllStructCreate("byte;byte")
$dwUserIndex = DllStructCreate("dword dwUserIndex")
$devType = DllStructCreate("byte[" & BinaryLen($type) & "] devType")

DllStructSetData($dwUserIndex,"dwUserIndex",$type)
DllStructSetData($devType,"devType",$Index)

$pointer = DllStructGetPtr($OutStruct)

$sDll = "Some.dll")

$Rtn = DllCall($sDll,"dword","XInputGetBatteryInformation","dword",$dwUserIndex,"byte",$devType,"ptr",$pointer)

:mellow:

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
smashly

These are the constants I'm using

;// User index definitions
Global Const $XUSER_MAX_COUNT           =      4 ; Can be a value in the range 0 to XUSER_MAX_COUNT − 1

;// Device types available in XINPUT_CAPABILITIES
Global Const $XINPUT_DEVTYPE_GAMEPAD    =      0x01

Global Const $tag_XINPUT_BATTERY_INFORMATION = "BYTE BatteryType;BYTE BatteryLevel"

;// Flags for battery status level
;// Battery Type
Global Const $BATTERY_TYPE_DISCONNECTED =      0x00    ;// This device is not connected
Global Const $BATTERY_TYPE_WIRED        =      0x01    ;// Wired device, no battery
Global Const $BATTERY_TYPE_ALKALINE     =      0x02    ;// Alkaline battery source
Global Const $BATTERY_TYPE_NIMH         =      0x03    ;// Nickel Metal Hydride battery source
Global Const $BATTERY_TYPE_UNKNOWN      =      0xFF    ;// Cannot determine the battery type

;// These are only valid for wireless, connected devices, with known battery types
;// The amount of use time remaining depends on the type of device.
;// Battery Level
Global Const $BATTERY_LEVEL_EMPTY       =      0x00
Global Const $BATTERY_LEVEL_LOW         =      0x01
Global Const $BATTERY_LEVEL_MEDIUM      =      0x02
Global Const $BATTERY_LEVEL_FULL        =      0x03
Basically a copy and paste from XInput.h from DX SDK Aug 09

Edited by smashly

Share this post


Link to post
Share on other sites
SkellySoul

;Xbox Controller
;Button[1] = Up
;Button[2] = Down
;Button[3] = Left
;Button[4] = Right
;Button[5] = Start
;Button[6] = Back
;Button[7] = Left Joy
;Button[8] = Right Joy
;Button[9] = Left Button
;Button[10] = Right Button
;Button[11] = A
;Button[12] = B
;Button[13] = X
;Button[14] = Y

$X_Dll = X_Start()

While 1
    $Idle = 100
    $X_Input = _X_Input($X_Dll)
    $X_Button = _X_Button($X_Input[2])

    Sleep($Idle)

    If $X_Button[1] Then ; Up
        ;;;
    ElseIf $X_Button[2] Then ; Down
        ;;;
    ElseIf $X_Button[3] Then ; Left
        ;;;
    ElseIf $X_Button[4] Then ; Right
        ;;;
    ElseIf $X_Button[5] Then ; Start
        ;;;
    ElseIf $X_Button[6] Then ; Back
        ;;;
    ElseIf $X_Button[7] Then ; Left Joy
        ;;;
    ElseIf $X_Button[8] Then ; Right Joy
        ;;;
    ElseIf $X_Button[9] Then ; Left Button
        ;;;
    ElseIf $X_Button[10] Then ; Right Button
        ;;;
    ElseIf $X_Button[11] Then ; A
        ;;;
    ElseIf $X_Button[12] Then ; B
        ;;;
    ElseIf $X_Button[13] Then ; X
        ;;;
    ElseIf $X_Button[14] Then ; Y
        ;;;
    EndIf
    _X_Vibrate($X_Dll, Round(($X_Input[3] / 255) * 100), Round(($X_Input[4] / 255) * 100))
WEnd

Func X_Start()
    Local $Box
    $Box = DllOpen(@ScriptDir & "\Controller.dll")
    If $Box = -1 Then
        MsgBox(16, "Error" , "Exiting...")
        DllClose($Box)
    Else
        Return $Box
    EndIf
EndFunc

Func _X_Input($X_Dll)
    Local $Input[9]
    $Pad = DllStructCreate("dword;short;ubyte;ubyte;short;short;short;short")
    If DllCall($X_Dll, "long", "XInputGetState", "long", 0, "ptr", DllStructGetPtr($Pad)) = 0 Then Return
    For $i = 1 to 8
        $Input[$i] = DllStructGetData($Pad, $i)
    Next
    Return $Input
EndFunc

Func _X_Button($X_Button)
    Local $Pressed[15]
    If $X_Button < 0 Then
        $X_Button = $X_Button + 32768
        $Pressed[14] = 1
    EndIf
    For $i = 14 to 12 Step -1
        If $X_Button >= (2 ^ $i) Then
            $X_Button = $X_Button - (2 ^ $i)
            $Pressed[($i-1)] = 1
        EndIf
    Next
    For $i = 9 to 0 Step -1
        If $X_Button >= (2 ^ $i) Then
            $X_Button = $X_Button - (2 ^ $i)
            $Pressed[($i + 1)] = 1
        EndIf
    Next
    Return $Pressed
EndFunc

Func _X_Vibrate($X_Dll, $L_Motor, $R_Motor)
    $X_Vibration = DllStructCreate("short;short")
    DllStructSetData($X_Vibration, 1, Round(($L_Motor / 100) * 32767))
    DllStructSetData($X_Vibration, 2, Round(($R_Motor / 100) * 32767))
    DllCall($X_Dll, "long", "XInputSetState", "long", 0, "ptr", DllStructGetPtr($X_Vibration))
EndFunc

Edited by SkellySoul

Share this post


Link to post
Share on other sites
SkellySoul

"ubyte"

Is that a valid type in autoit?

24th August, 2007 - v3.2.6.0

Added: byte and ubyte type to DllCall().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×