ホーム › UI.Input.Pointer › GetPointerDevices
GetPointerDevices
関数システムに接続されたポインタデバイス一覧を取得する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL GetPointerDevices(
DWORD* deviceCount,
POINTER_DEVICE_INFO* pointerDevices // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| deviceCount | DWORD* | inout | 入力時は配列容量、出力時はデバイス数を表すDWORDへのポインタ。 |
| pointerDevices | POINTER_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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "USER32.dll" #cfunc global GetPointerDevices "GetPointerDevices" sptr, sptr ; res = GetPointerDevices(varptr(deviceCount), varptr(pointerDevices)) ; deviceCount : DWORD* in/out -> "sptr" ; pointerDevices : POINTER_DEVICE_INFO* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; BOOL GetPointerDevices(DWORD* deviceCount, POINTER_DEVICE_INFO* pointerDevices) #uselib "USER32.dll" #cfunc global GetPointerDevices "GetPointerDevices" intptr, intptr ; res = GetPointerDevices(varptr(deviceCount), varptr(pointerDevices)) ; deviceCount : DWORD* in/out -> "intptr" ; pointerDevices : POINTER_DEVICE_INFO* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "user32" fn GetPointerDevices(
deviceCount: [*c]u32, // DWORD* in/out
pointerDevices: [*c]POINTER_DEVICE_INFO // POINTER_DEVICE_INFO* optional, out
) callconv(std.os.windows.WINAPI) i32;proc GetPointerDevices(
deviceCount: ptr uint32, # DWORD* in/out
pointerDevices: ptr POINTER_DEVICE_INFO # POINTER_DEVICE_INFO* optional, out
): int32 {.importc: "GetPointerDevices", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int GetPointerDevices(
uint* deviceCount, // DWORD* in/out
POINTER_DEVICE_INFO* pointerDevices // POINTER_DEVICE_INFO* optional, out
);ccall((:GetPointerDevices, "USER32.dll"), stdcall, Int32,
(Ptr{UInt32}, Ptr{POINTER_DEVICE_INFO}),
deviceCount, pointerDevices)
# deviceCount : DWORD* in/out -> Ptr{UInt32}
# pointerDevices : POINTER_DEVICE_INFO* optional, out -> Ptr{POINTER_DEVICE_INFO}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetPointerDevices(
uint32_t* deviceCount,
void* pointerDevices);
]]
local user32 = ffi.load("user32")
-- user32.GetPointerDevices(deviceCount, pointerDevices)
-- deviceCount : DWORD* in/out
-- pointerDevices : POINTER_DEVICE_INFO* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const GetPointerDevices = lib.func('__stdcall', 'GetPointerDevices', 'int32_t', ['uint32_t *', 'void *']);
// GetPointerDevices(deviceCount, pointerDevices)
// deviceCount : DWORD* in/out -> 'uint32_t *'
// pointerDevices : POINTER_DEVICE_INFO* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
GetPointerDevices: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetPointerDevices(deviceCount, pointerDevices)
// deviceCount : DWORD* in/out -> "pointer"
// pointerDevices : POINTER_DEVICE_INFO* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetPointerDevices(
uint32_t* deviceCount,
void* pointerDevices);
C, "USER32.dll");
// $ffi->GetPointerDevices(deviceCount, pointerDevices);
// deviceCount : DWORD* in/out
// pointerDevices : POINTER_DEVICE_INFO* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class);
boolean GetPointerDevices(
IntByReference deviceCount, // DWORD* in/out
Pointer pointerDevices // POINTER_DEVICE_INFO* optional, out
);
}@[Link("user32")]
lib LibUSER32
fun GetPointerDevices = GetPointerDevices(
deviceCount : UInt32*, # DWORD* in/out
pointerDevices : POINTER_DEVICE_INFO* # POINTER_DEVICE_INFO* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetPointerDevicesNative = Int32 Function(Pointer<Uint32>, Pointer<Void>);
typedef GetPointerDevicesDart = int Function(Pointer<Uint32>, Pointer<Void>);
final GetPointerDevices = DynamicLibrary.open('USER32.dll')
.lookupFunction<GetPointerDevicesNative, GetPointerDevicesDart>('GetPointerDevices');
// deviceCount : DWORD* in/out -> Pointer<Uint32>
// pointerDevices : POINTER_DEVICE_INFO* optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetPointerDevices(
deviceCount: Pointer; // DWORD* in/out
pointerDevices: Pointer // POINTER_DEVICE_INFO* optional, out
): BOOL; stdcall;
external 'USER32.dll' name 'GetPointerDevices';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetPointerDevices"
c_GetPointerDevices :: Ptr Word32 -> Ptr () -> IO CInt
-- deviceCount : DWORD* in/out -> Ptr Word32
-- pointerDevices : POINTER_DEVICE_INFO* optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getpointerdevices =
foreign "GetPointerDevices"
((ptr uint32_t) @-> (ptr void) @-> returning int32_t)
(* deviceCount : DWORD* in/out -> (ptr uint32_t) *)
(* pointerDevices : POINTER_DEVICE_INFO* optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("GetPointerDevices" get-pointer-devices :convention :stdcall) :int32
(device-count :pointer) ; DWORD* in/out
(pointer-devices :pointer)) ; POINTER_DEVICE_INFO* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetPointerDevices = Win32::API::More->new('USER32',
'BOOL GetPointerDevices(LPVOID deviceCount, LPVOID pointerDevices)');
# my $ret = $GetPointerDevices->Call($deviceCount, $pointerDevices);
# deviceCount : DWORD* in/out -> LPVOID
# pointerDevices : POINTER_DEVICE_INFO* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。