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

GetPointerDevices

関数
システムに接続されたポインタデバイス一覧を取得する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSwindows8.0

シグネチャ

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

BOOL GetPointerDevices(
    DWORD* deviceCount,
    POINTER_DEVICE_INFO* pointerDevices   // optional
);

パラメーター

名前方向説明
deviceCountDWORD*inout入力時は配列容量、出力時はデバイス数を表すDWORDへのポインタ。
pointerDevicesPOINTER_DEVICE_INFO*outoptionalポインタデバイス情報を受け取るPOINTER_DEVICE_INFO配列へのポインタ。NULLで件数取得可。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetPointerDevices(
    DWORD* deviceCount,
    POINTER_DEVICE_INFO* pointerDevices   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetPointerDevices(
    ref uint deviceCount,   // DWORD* in/out
    IntPtr pointerDevices   // POINTER_DEVICE_INFO* optional, out
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetPointerDevices(
    ByRef deviceCount As UInteger,   ' DWORD* in/out
    pointerDevices As IntPtr   ' POINTER_DEVICE_INFO* optional, out
) As Boolean
End Function
' deviceCount : DWORD* in/out
' pointerDevices : POINTER_DEVICE_INFO* optional, out
Declare PtrSafe Function GetPointerDevices Lib "user32" ( _
    ByRef deviceCount As Long, _
    ByVal pointerDevices As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetPointerDevices = ctypes.windll.user32.GetPointerDevices
GetPointerDevices.restype = wintypes.BOOL
GetPointerDevices.argtypes = [
    ctypes.POINTER(wintypes.DWORD),  # deviceCount : DWORD* in/out
    ctypes.c_void_p,  # pointerDevices : POINTER_DEVICE_INFO* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
GetPointerDevices = Fiddle::Function.new(
  lib['GetPointerDevices'],
  [
    Fiddle::TYPE_VOIDP,  # deviceCount : DWORD* in/out
    Fiddle::TYPE_VOIDP,  # pointerDevices : POINTER_DEVICE_INFO* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn GetPointerDevices(
        deviceCount: *mut u32,  // DWORD* in/out
        pointerDevices: *mut POINTER_DEVICE_INFO  // POINTER_DEVICE_INFO* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool GetPointerDevices(ref uint deviceCount, IntPtr pointerDevices);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetPointerDevices' -Namespace Win32 -PassThru
# $api::GetPointerDevices(deviceCount, pointerDevices)
#uselib "USER32.dll"
#func global GetPointerDevices "GetPointerDevices" sptr, sptr
; GetPointerDevices varptr(deviceCount), varptr(pointerDevices)   ; 戻り値は stat
; deviceCount : DWORD* in/out -> "sptr"
; pointerDevices : POINTER_DEVICE_INFO* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global GetPointerDevices "GetPointerDevices" var, var
; res = GetPointerDevices(deviceCount, pointerDevices)
; deviceCount : DWORD* in/out -> "var"
; pointerDevices : POINTER_DEVICE_INFO* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetPointerDevices(DWORD* deviceCount, POINTER_DEVICE_INFO* pointerDevices)
#uselib "USER32.dll"
#cfunc global GetPointerDevices "GetPointerDevices" var, var
; res = GetPointerDevices(deviceCount, pointerDevices)
; deviceCount : DWORD* in/out -> "var"
; pointerDevices : POINTER_DEVICE_INFO* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetPointerDevices = user32.NewProc("GetPointerDevices")
)

// deviceCount (DWORD* in/out), pointerDevices (POINTER_DEVICE_INFO* optional, out)
r1, _, err := procGetPointerDevices.Call(
	uintptr(deviceCount),
	uintptr(pointerDevices),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetPointerDevices(
  deviceCount: Pointer;   // DWORD* in/out
  pointerDevices: Pointer   // POINTER_DEVICE_INFO* optional, out
): BOOL; stdcall;
  external 'USER32.dll' name 'GetPointerDevices';
result := DllCall("USER32\GetPointerDevices"
    , "Ptr", deviceCount   ; DWORD* in/out
    , "Ptr", pointerDevices   ; POINTER_DEVICE_INFO* optional, out
    , "Int")   ; return: BOOL
●GetPointerDevices(deviceCount, pointerDevices) = DLL("USER32.dll", "bool GetPointerDevices(void*, void*)")
# 呼び出し: GetPointerDevices(deviceCount, pointerDevices)
# deviceCount : DWORD* in/out -> "void*"
# pointerDevices : POINTER_DEVICE_INFO* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。