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

GetRegisteredRawInputDevices

関数
登録済みのRaw Inputデバイス一覧を取得する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD GetRegisteredRawInputDevices(
    RAWINPUTDEVICE* pRawInputDevices,   // optional
    DWORD* puiNumDevices,
    DWORD cbSize
);

パラメーター

名前方向説明
pRawInputDevicesRAWINPUTDEVICE*outoptional登録済みデバイス情報を受け取るRAWINPUTDEVICE配列へのポインタ。NULLで個数取得。
puiNumDevicesDWORD*inout配列の要素数を入出力するポインタ。
cbSizeDWORDinRAWINPUTDEVICE構造体1個のサイズ(バイト数)。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetRegisteredRawInputDevices(
    RAWINPUTDEVICE* pRawInputDevices,   // optional
    DWORD* puiNumDevices,
    DWORD cbSize
);
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern uint GetRegisteredRawInputDevices(
    IntPtr pRawInputDevices,   // RAWINPUTDEVICE* optional, out
    ref uint puiNumDevices,   // DWORD* in/out
    uint cbSize   // DWORD
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetRegisteredRawInputDevices(
    pRawInputDevices As IntPtr,   ' RAWINPUTDEVICE* optional, out
    ByRef puiNumDevices As UInteger,   ' DWORD* in/out
    cbSize As UInteger   ' DWORD
) As UInteger
End Function
' pRawInputDevices : RAWINPUTDEVICE* optional, out
' puiNumDevices : DWORD* in/out
' cbSize : DWORD
Declare PtrSafe Function GetRegisteredRawInputDevices Lib "user32" ( _
    ByVal pRawInputDevices 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

GetRegisteredRawInputDevices = ctypes.windll.user32.GetRegisteredRawInputDevices
GetRegisteredRawInputDevices.restype = wintypes.DWORD
GetRegisteredRawInputDevices.argtypes = [
    ctypes.c_void_p,  # pRawInputDevices : RAWINPUTDEVICE* 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')
GetRegisteredRawInputDevices = Fiddle::Function.new(
  lib['GetRegisteredRawInputDevices'],
  [
    Fiddle::TYPE_VOIDP,  # pRawInputDevices : RAWINPUTDEVICE* optional, out
    Fiddle::TYPE_VOIDP,  # puiNumDevices : DWORD* in/out
    -Fiddle::TYPE_INT,  # cbSize : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn GetRegisteredRawInputDevices(
        pRawInputDevices: *mut RAWINPUTDEVICE,  // RAWINPUTDEVICE* 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 GetRegisteredRawInputDevices(IntPtr pRawInputDevices, ref uint puiNumDevices, uint cbSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetRegisteredRawInputDevices' -Namespace Win32 -PassThru
# $api::GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize)
#uselib "USER32.dll"
#func global GetRegisteredRawInputDevices "GetRegisteredRawInputDevices" sptr, sptr, sptr
; GetRegisteredRawInputDevices varptr(pRawInputDevices), varptr(puiNumDevices), cbSize   ; 戻り値は stat
; pRawInputDevices : RAWINPUTDEVICE* optional, out -> "sptr"
; puiNumDevices : DWORD* in/out -> "sptr"
; cbSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global GetRegisteredRawInputDevices "GetRegisteredRawInputDevices" var, var, int
; res = GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize)
; pRawInputDevices : RAWINPUTDEVICE* optional, out -> "var"
; puiNumDevices : DWORD* in/out -> "var"
; cbSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetRegisteredRawInputDevices(RAWINPUTDEVICE* pRawInputDevices, DWORD* puiNumDevices, DWORD cbSize)
#uselib "USER32.dll"
#cfunc global GetRegisteredRawInputDevices "GetRegisteredRawInputDevices" var, var, int
; res = GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize)
; pRawInputDevices : RAWINPUTDEVICE* 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")
	procGetRegisteredRawInputDevices = user32.NewProc("GetRegisteredRawInputDevices")
)

// pRawInputDevices (RAWINPUTDEVICE* optional, out), puiNumDevices (DWORD* in/out), cbSize (DWORD)
r1, _, err := procGetRegisteredRawInputDevices.Call(
	uintptr(pRawInputDevices),
	uintptr(puiNumDevices),
	uintptr(cbSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetRegisteredRawInputDevices(
  pRawInputDevices: Pointer;   // RAWINPUTDEVICE* optional, out
  puiNumDevices: Pointer;   // DWORD* in/out
  cbSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'USER32.dll' name 'GetRegisteredRawInputDevices';
result := DllCall("USER32\GetRegisteredRawInputDevices"
    , "Ptr", pRawInputDevices   ; RAWINPUTDEVICE* optional, out
    , "Ptr", puiNumDevices   ; DWORD* in/out
    , "UInt", cbSize   ; DWORD
    , "UInt")   ; return: DWORD
●GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize) = DLL("USER32.dll", "dword GetRegisteredRawInputDevices(void*, void*, dword)")
# 呼び出し: GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize)
# pRawInputDevices : RAWINPUTDEVICE* 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 GetRegisteredRawInputDevices(
    pRawInputDevices: [*c]RAWINPUTDEVICE, // RAWINPUTDEVICE* optional, out
    puiNumDevices: [*c]u32, // DWORD* in/out
    cbSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc GetRegisteredRawInputDevices(
    pRawInputDevices: ptr RAWINPUTDEVICE,  # RAWINPUTDEVICE* optional, out
    puiNumDevices: ptr uint32,  # DWORD* in/out
    cbSize: uint32  # DWORD
): uint32 {.importc: "GetRegisteredRawInputDevices", stdcall, dynlib: "USER32.dll".}
pragma(lib, "user32");
extern(Windows)
uint GetRegisteredRawInputDevices(
    RAWINPUTDEVICE* pRawInputDevices,   // RAWINPUTDEVICE* optional, out
    uint* puiNumDevices,   // DWORD* in/out
    uint cbSize   // DWORD
);
ccall((:GetRegisteredRawInputDevices, "USER32.dll"), stdcall, UInt32,
      (Ptr{RAWINPUTDEVICE}, Ptr{UInt32}, UInt32),
      pRawInputDevices, puiNumDevices, cbSize)
# pRawInputDevices : RAWINPUTDEVICE* optional, out -> Ptr{RAWINPUTDEVICE}
# puiNumDevices : DWORD* in/out -> Ptr{UInt32}
# cbSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t GetRegisteredRawInputDevices(
    void* pRawInputDevices,
    uint32_t* puiNumDevices,
    uint32_t cbSize);
]]
local user32 = ffi.load("user32")
-- user32.GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize)
-- pRawInputDevices : RAWINPUTDEVICE* 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 GetRegisteredRawInputDevices = lib.func('__stdcall', 'GetRegisteredRawInputDevices', 'uint32_t', ['void *', 'uint32_t *', 'uint32_t']);
// GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize)
// pRawInputDevices : RAWINPUTDEVICE* optional, out -> 'void *'
// puiNumDevices : DWORD* in/out -> 'uint32_t *'
// cbSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USER32.dll", {
  GetRegisteredRawInputDevices: { parameters: ["pointer", "pointer", "u32"], result: "u32" },
});
// lib.symbols.GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize)
// pRawInputDevices : RAWINPUTDEVICE* optional, out -> "pointer"
// puiNumDevices : DWORD* in/out -> "pointer"
// cbSize : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t GetRegisteredRawInputDevices(
    void* pRawInputDevices,
    uint32_t* puiNumDevices,
    uint32_t cbSize);
C, "USER32.dll");
// $ffi->GetRegisteredRawInputDevices(pRawInputDevices, puiNumDevices, cbSize);
// pRawInputDevices : RAWINPUTDEVICE* 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 GetRegisteredRawInputDevices(
        Pointer pRawInputDevices,   // RAWINPUTDEVICE* optional, out
        IntByReference puiNumDevices,   // DWORD* in/out
        int cbSize   // DWORD
    );
}
@[Link("user32")]
lib LibUSER32
  fun GetRegisteredRawInputDevices = GetRegisteredRawInputDevices(
    pRawInputDevices : RAWINPUTDEVICE*,   # RAWINPUTDEVICE* 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 GetRegisteredRawInputDevicesNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>, Uint32);
typedef GetRegisteredRawInputDevicesDart = int Function(Pointer<Void>, Pointer<Uint32>, int);
final GetRegisteredRawInputDevices = DynamicLibrary.open('USER32.dll')
    .lookupFunction<GetRegisteredRawInputDevicesNative, GetRegisteredRawInputDevicesDart>('GetRegisteredRawInputDevices');
// pRawInputDevices : RAWINPUTDEVICE* optional, out -> Pointer<Void>
// puiNumDevices : DWORD* in/out -> Pointer<Uint32>
// cbSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetRegisteredRawInputDevices(
  pRawInputDevices: Pointer;   // RAWINPUTDEVICE* optional, out
  puiNumDevices: Pointer;   // DWORD* in/out
  cbSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'USER32.dll' name 'GetRegisteredRawInputDevices';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let getregisteredrawinputdevices =
  foreign "GetRegisteredRawInputDevices"
    ((ptr void) @-> (ptr uint32_t) @-> uint32_t @-> returning uint32_t)
(* pRawInputDevices : RAWINPUTDEVICE* 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 ("GetRegisteredRawInputDevices" get-registered-raw-input-devices :convention :stdcall) :uint32
  (p-raw-input-devices :pointer)   ; RAWINPUTDEVICE* 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 $GetRegisteredRawInputDevices = Win32::API::More->new('USER32',
    'DWORD GetRegisteredRawInputDevices(LPVOID pRawInputDevices, LPVOID puiNumDevices, DWORD cbSize)');
# my $ret = $GetRegisteredRawInputDevices->Call($pRawInputDevices, $puiNumDevices, $cbSize);
# pRawInputDevices : RAWINPUTDEVICE* optional, out -> LPVOID
# puiNumDevices : DWORD* in/out -> LPVOID
# cbSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型