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

RegisterRawInputDevices

関数
アプリケーションでRaw Inputデバイスを登録する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL RegisterRawInputDevices(
    RAWINPUTDEVICE* pRawInputDevices,
    DWORD uiNumDevices,
    DWORD cbSize
);

パラメーター

名前方向説明
pRawInputDevicesRAWINPUTDEVICE*in登録するRAW入力デバイスを定義するRAWINPUTDEVICE構造体配列へのポインタ。
uiNumDevicesDWORDinpRawInputDevices配列の要素数。
cbSizeDWORDinRAWINPUTDEVICE構造体1個のサイズ(バイト数)。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL RegisterRawInputDevices(
    RAWINPUTDEVICE* pRawInputDevices,
    DWORD uiNumDevices,
    DWORD cbSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool RegisterRawInputDevices(
    IntPtr pRawInputDevices,   // RAWINPUTDEVICE*
    uint uiNumDevices,   // DWORD
    uint cbSize   // DWORD
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RegisterRawInputDevices(
    pRawInputDevices As IntPtr,   ' RAWINPUTDEVICE*
    uiNumDevices As UInteger,   ' DWORD
    cbSize As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pRawInputDevices : RAWINPUTDEVICE*
' uiNumDevices : DWORD
' cbSize : DWORD
Declare PtrSafe Function RegisterRawInputDevices Lib "user32" ( _
    ByVal pRawInputDevices As LongPtr, _
    ByVal uiNumDevices 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

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procRegisterRawInputDevices = user32.NewProc("RegisterRawInputDevices")
)

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

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

typedef RegisterRawInputDevicesNative = Int32 Function(Pointer<Void>, Uint32, Uint32);
typedef RegisterRawInputDevicesDart = int Function(Pointer<Void>, int, int);
final RegisterRawInputDevices = DynamicLibrary.open('USER32.dll')
    .lookupFunction<RegisterRawInputDevicesNative, RegisterRawInputDevicesDart>('RegisterRawInputDevices');
// pRawInputDevices : RAWINPUTDEVICE* -> Pointer<Void>
// uiNumDevices : DWORD -> Uint32
// cbSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RegisterRawInputDevices(
  pRawInputDevices: Pointer;   // RAWINPUTDEVICE*
  uiNumDevices: DWORD;   // DWORD
  cbSize: DWORD   // DWORD
): BOOL; stdcall;
  external 'USER32.dll' name 'RegisterRawInputDevices';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RegisterRawInputDevices"
  c_RegisterRawInputDevices :: Ptr () -> Word32 -> Word32 -> IO CInt
-- pRawInputDevices : RAWINPUTDEVICE* -> Ptr ()
-- uiNumDevices : DWORD -> Word32
-- cbSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let registerrawinputdevices =
  foreign "RegisterRawInputDevices"
    ((ptr void) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* pRawInputDevices : RAWINPUTDEVICE* -> (ptr void) *)
(* uiNumDevices : DWORD -> 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 ("RegisterRawInputDevices" register-raw-input-devices :convention :stdcall) :int32
  (p-raw-input-devices :pointer)   ; RAWINPUTDEVICE*
  (ui-num-devices :uint32)   ; DWORD
  (cb-size :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RegisterRawInputDevices = Win32::API::More->new('USER32',
    'BOOL RegisterRawInputDevices(LPVOID pRawInputDevices, DWORD uiNumDevices, DWORD cbSize)');
# my $ret = $RegisterRawInputDevices->Call($pRawInputDevices, $uiNumDevices, $cbSize);
# pRawInputDevices : RAWINPUTDEVICE* -> LPVOID
# uiNumDevices : DWORD -> DWORD
# cbSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型