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

GetRawInputDeviceList

関数
システムに接続されたRaw Inputデバイス一覧を取得する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD GetRawInputDeviceList(
    RAWINPUTDEVICELIST* pRawInputDeviceList,   // optional
    DWORD* puiNumDevices,
    DWORD cbSize
);

パラメーター

名前方向説明
pRawInputDeviceListRAWINPUTDEVICELIST*outoptionalRAW入力デバイス一覧を受け取るRAWINPUTDEVICELIST配列へのポインタ。NULLで個数取得。
puiNumDevicesDWORD*inout配列の要素数を入出力するポインタ。
cbSizeDWORDinRAWINPUTDEVICELIST構造体1個のサイズ(バイト数)。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

GetRawInputDeviceList = ctypes.windll.user32.GetRawInputDeviceList
GetRawInputDeviceList.restype = wintypes.DWORD
GetRawInputDeviceList.argtypes = [
    ctypes.c_void_p,  # pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out
    ctypes.POINTER(wintypes.DWORD),  # puiNumDevices : DWORD* in/out
    wintypes.DWORD,  # cbSize : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetRawInputDeviceList = user32.NewProc("GetRawInputDeviceList")
)

// pRawInputDeviceList (RAWINPUTDEVICELIST* optional, out), puiNumDevices (DWORD* in/out), cbSize (DWORD)
r1, _, err := procGetRawInputDeviceList.Call(
	uintptr(pRawInputDeviceList),
	uintptr(puiNumDevices),
	uintptr(cbSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetRawInputDeviceList(
  pRawInputDeviceList: Pointer;   // RAWINPUTDEVICELIST* optional, out
  puiNumDevices: Pointer;   // DWORD* in/out
  cbSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'USER32.dll' name 'GetRawInputDeviceList';
result := DllCall("USER32\GetRawInputDeviceList"
    , "Ptr", pRawInputDeviceList   ; RAWINPUTDEVICELIST* optional, out
    , "Ptr", puiNumDevices   ; DWORD* in/out
    , "UInt", cbSize   ; DWORD
    , "UInt")   ; return: DWORD
●GetRawInputDeviceList(pRawInputDeviceList, puiNumDevices, cbSize) = DLL("USER32.dll", "dword GetRawInputDeviceList(void*, void*, dword)")
# 呼び出し: GetRawInputDeviceList(pRawInputDeviceList, puiNumDevices, cbSize)
# pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out -> "void*"
# puiNumDevices : DWORD* in/out -> "void*"
# cbSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "user32" fn GetRawInputDeviceList(
    pRawInputDeviceList: [*c]RAWINPUTDEVICELIST, // RAWINPUTDEVICELIST* optional, out
    puiNumDevices: [*c]u32, // DWORD* in/out
    cbSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc GetRawInputDeviceList(
    pRawInputDeviceList: ptr RAWINPUTDEVICELIST,  # RAWINPUTDEVICELIST* optional, out
    puiNumDevices: ptr uint32,  # DWORD* in/out
    cbSize: uint32  # DWORD
): uint32 {.importc: "GetRawInputDeviceList", stdcall, dynlib: "USER32.dll".}
pragma(lib, "user32");
extern(Windows)
uint GetRawInputDeviceList(
    RAWINPUTDEVICELIST* pRawInputDeviceList,   // RAWINPUTDEVICELIST* optional, out
    uint* puiNumDevices,   // DWORD* in/out
    uint cbSize   // DWORD
);
ccall((:GetRawInputDeviceList, "USER32.dll"), stdcall, UInt32,
      (Ptr{RAWINPUTDEVICELIST}, Ptr{UInt32}, UInt32),
      pRawInputDeviceList, puiNumDevices, cbSize)
# pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out -> Ptr{RAWINPUTDEVICELIST}
# puiNumDevices : DWORD* in/out -> Ptr{UInt32}
# cbSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t GetRawInputDeviceList(
    void* pRawInputDeviceList,
    uint32_t* puiNumDevices,
    uint32_t cbSize);
]]
local user32 = ffi.load("user32")
-- user32.GetRawInputDeviceList(pRawInputDeviceList, puiNumDevices, cbSize)
-- pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out
-- puiNumDevices : DWORD* in/out
-- cbSize : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const GetRawInputDeviceList = lib.func('__stdcall', 'GetRawInputDeviceList', 'uint32_t', ['void *', 'uint32_t *', 'uint32_t']);
// GetRawInputDeviceList(pRawInputDeviceList, puiNumDevices, cbSize)
// pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out -> 'void *'
// puiNumDevices : DWORD* in/out -> 'uint32_t *'
// cbSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USER32.dll", {
  GetRawInputDeviceList: { parameters: ["pointer", "pointer", "u32"], result: "u32" },
});
// lib.symbols.GetRawInputDeviceList(pRawInputDeviceList, puiNumDevices, cbSize)
// pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out -> "pointer"
// puiNumDevices : DWORD* in/out -> "pointer"
// cbSize : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t GetRawInputDeviceList(
    void* pRawInputDeviceList,
    uint32_t* puiNumDevices,
    uint32_t cbSize);
C, "USER32.dll");
// $ffi->GetRawInputDeviceList(pRawInputDeviceList, puiNumDevices, cbSize);
// pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out
// puiNumDevices : DWORD* in/out
// cbSize : DWORD
// 構造体/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);
    int GetRawInputDeviceList(
        Pointer pRawInputDeviceList,   // RAWINPUTDEVICELIST* optional, out
        IntByReference puiNumDevices,   // DWORD* in/out
        int cbSize   // DWORD
    );
}
@[Link("user32")]
lib LibUSER32
  fun GetRawInputDeviceList = GetRawInputDeviceList(
    pRawInputDeviceList : RAWINPUTDEVICELIST*,   # RAWINPUTDEVICELIST* optional, out
    puiNumDevices : UInt32*,   # DWORD* in/out
    cbSize : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetRawInputDeviceListNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>, Uint32);
typedef GetRawInputDeviceListDart = int Function(Pointer<Void>, Pointer<Uint32>, int);
final GetRawInputDeviceList = DynamicLibrary.open('USER32.dll')
    .lookupFunction<GetRawInputDeviceListNative, GetRawInputDeviceListDart>('GetRawInputDeviceList');
// pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out -> Pointer<Void>
// puiNumDevices : DWORD* in/out -> Pointer<Uint32>
// cbSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetRawInputDeviceList(
  pRawInputDeviceList: Pointer;   // RAWINPUTDEVICELIST* optional, out
  puiNumDevices: Pointer;   // DWORD* in/out
  cbSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'USER32.dll' name 'GetRawInputDeviceList';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetRawInputDeviceList"
  c_GetRawInputDeviceList :: Ptr () -> Ptr Word32 -> Word32 -> IO Word32
-- pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out -> Ptr ()
-- puiNumDevices : DWORD* in/out -> Ptr Word32
-- cbSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getrawinputdevicelist =
  foreign "GetRawInputDeviceList"
    ((ptr void) @-> (ptr uint32_t) @-> uint32_t @-> returning uint32_t)
(* pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out -> (ptr void) *)
(* puiNumDevices : DWORD* in/out -> (ptr uint32_t) *)
(* cbSize : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)

(cffi:defcfun ("GetRawInputDeviceList" get-raw-input-device-list :convention :stdcall) :uint32
  (p-raw-input-device-list :pointer)   ; RAWINPUTDEVICELIST* optional, out
  (pui-num-devices :pointer)   ; DWORD* in/out
  (cb-size :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetRawInputDeviceList = Win32::API::More->new('USER32',
    'DWORD GetRawInputDeviceList(LPVOID pRawInputDeviceList, LPVOID puiNumDevices, DWORD cbSize)');
# my $ret = $GetRawInputDeviceList->Call($pRawInputDeviceList, $puiNumDevices, $cbSize);
# pRawInputDeviceList : RAWINPUTDEVICELIST* optional, out -> LPVOID
# puiNumDevices : DWORD* in/out -> LPVOID
# cbSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型