Win32 API 日本語リファレンス
ホームUI.Input.XboxController › XInputGetBatteryInformation

XInputGetBatteryInformation

関数
Xboxコントローラーのバッテリー情報を取得する。
DLLxinput1_4.dll呼出規約winapi

シグネチャ

// xinput1_4.dll
#include <windows.h>

DWORD XInputGetBatteryInformation(
    DWORD dwUserIndex,
    BATTERY_DEVTYPE devType,
    XINPUT_BATTERY_INFORMATION* pBatteryInformation
);

パラメーター

名前方向
dwUserIndexDWORDin
devTypeBATTERY_DEVTYPEin
pBatteryInformationXINPUT_BATTERY_INFORMATION*out

戻り値の型: DWORD

各言語での呼び出し定義

// xinput1_4.dll
#include <windows.h>

DWORD XInputGetBatteryInformation(
    DWORD dwUserIndex,
    BATTERY_DEVTYPE devType,
    XINPUT_BATTERY_INFORMATION* pBatteryInformation
);
[DllImport("xinput1_4.dll", ExactSpelling = true)]
static extern uint XInputGetBatteryInformation(
    uint dwUserIndex,   // DWORD
    byte devType,   // BATTERY_DEVTYPE
    IntPtr pBatteryInformation   // XINPUT_BATTERY_INFORMATION* out
);
<DllImport("xinput1_4.dll", ExactSpelling:=True)>
Public Shared Function XInputGetBatteryInformation(
    dwUserIndex As UInteger,   ' DWORD
    devType As Byte,   ' BATTERY_DEVTYPE
    pBatteryInformation As IntPtr   ' XINPUT_BATTERY_INFORMATION* out
) As UInteger
End Function
' dwUserIndex : DWORD
' devType : BATTERY_DEVTYPE
' pBatteryInformation : XINPUT_BATTERY_INFORMATION* out
Declare PtrSafe Function XInputGetBatteryInformation Lib "xinput1_4" ( _
    ByVal dwUserIndex As Long, _
    ByVal devType As Byte, _
    ByVal pBatteryInformation As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

XInputGetBatteryInformation = ctypes.windll.xinput1_4.XInputGetBatteryInformation
XInputGetBatteryInformation.restype = wintypes.DWORD
XInputGetBatteryInformation.argtypes = [
    wintypes.DWORD,  # dwUserIndex : DWORD
    ctypes.c_ubyte,  # devType : BATTERY_DEVTYPE
    ctypes.c_void_p,  # pBatteryInformation : XINPUT_BATTERY_INFORMATION* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('xinput1_4.dll')
XInputGetBatteryInformation = Fiddle::Function.new(
  lib['XInputGetBatteryInformation'],
  [
    -Fiddle::TYPE_INT,  # dwUserIndex : DWORD
    -Fiddle::TYPE_CHAR,  # devType : BATTERY_DEVTYPE
    Fiddle::TYPE_VOIDP,  # pBatteryInformation : XINPUT_BATTERY_INFORMATION* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "xinput1_4")]
extern "system" {
    fn XInputGetBatteryInformation(
        dwUserIndex: u32,  // DWORD
        devType: u8,  // BATTERY_DEVTYPE
        pBatteryInformation: *mut XINPUT_BATTERY_INFORMATION  // XINPUT_BATTERY_INFORMATION* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("xinput1_4.dll")]
public static extern uint XInputGetBatteryInformation(uint dwUserIndex, byte devType, IntPtr pBatteryInformation);
"@
$api = Add-Type -MemberDefinition $sig -Name 'xinput1_4_XInputGetBatteryInformation' -Namespace Win32 -PassThru
# $api::XInputGetBatteryInformation(dwUserIndex, devType, pBatteryInformation)
#uselib "xinput1_4.dll"
#func global XInputGetBatteryInformation "XInputGetBatteryInformation" sptr, sptr, sptr
; XInputGetBatteryInformation dwUserIndex, devType, varptr(pBatteryInformation)   ; 戻り値は stat
; dwUserIndex : DWORD -> "sptr"
; devType : BATTERY_DEVTYPE -> "sptr"
; pBatteryInformation : XINPUT_BATTERY_INFORMATION* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "xinput1_4.dll"
#cfunc global XInputGetBatteryInformation "XInputGetBatteryInformation" int, int, var
; res = XInputGetBatteryInformation(dwUserIndex, devType, pBatteryInformation)
; dwUserIndex : DWORD -> "int"
; devType : BATTERY_DEVTYPE -> "int"
; pBatteryInformation : XINPUT_BATTERY_INFORMATION* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD XInputGetBatteryInformation(DWORD dwUserIndex, BATTERY_DEVTYPE devType, XINPUT_BATTERY_INFORMATION* pBatteryInformation)
#uselib "xinput1_4.dll"
#cfunc global XInputGetBatteryInformation "XInputGetBatteryInformation" int, int, var
; res = XInputGetBatteryInformation(dwUserIndex, devType, pBatteryInformation)
; dwUserIndex : DWORD -> "int"
; devType : BATTERY_DEVTYPE -> "int"
; pBatteryInformation : XINPUT_BATTERY_INFORMATION* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	xinput1_4 = windows.NewLazySystemDLL("xinput1_4.dll")
	procXInputGetBatteryInformation = xinput1_4.NewProc("XInputGetBatteryInformation")
)

// dwUserIndex (DWORD), devType (BATTERY_DEVTYPE), pBatteryInformation (XINPUT_BATTERY_INFORMATION* out)
r1, _, err := procXInputGetBatteryInformation.Call(
	uintptr(dwUserIndex),
	uintptr(devType),
	uintptr(pBatteryInformation),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function XInputGetBatteryInformation(
  dwUserIndex: DWORD;   // DWORD
  devType: Byte;   // BATTERY_DEVTYPE
  pBatteryInformation: Pointer   // XINPUT_BATTERY_INFORMATION* out
): DWORD; stdcall;
  external 'xinput1_4.dll' name 'XInputGetBatteryInformation';
result := DllCall("xinput1_4\XInputGetBatteryInformation"
    , "UInt", dwUserIndex   ; DWORD
    , "UChar", devType   ; BATTERY_DEVTYPE
    , "Ptr", pBatteryInformation   ; XINPUT_BATTERY_INFORMATION* out
    , "UInt")   ; return: DWORD
●XInputGetBatteryInformation(dwUserIndex, devType, pBatteryInformation) = DLL("xinput1_4.dll", "dword XInputGetBatteryInformation(dword, byte, void*)")
# 呼び出し: XInputGetBatteryInformation(dwUserIndex, devType, pBatteryInformation)
# dwUserIndex : DWORD -> "dword"
# devType : BATTERY_DEVTYPE -> "byte"
# pBatteryInformation : XINPUT_BATTERY_INFORMATION* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。