Win32 API 日本語リファレンス
ホームDevices.HumanInterfaceDevice › HidP_SetScaledUsageValue

HidP_SetScaledUsageValue

関数
HIDレポート内の指定した用途に物理単位の値を設定する。
DLLHID.dll呼出規約winapi

シグネチャ

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

NTSTATUS HidP_SetScaledUsageValue(
    HIDP_REPORT_TYPE ReportType,
    WORD UsagePage,
    WORD LinkCollection,   // optional
    WORD Usage,
    INT UsageValue,
    PHIDP_PREPARSED_DATA PreparsedData,
    LPSTR Report,
    DWORD ReportLength
);

パラメーター

名前方向
ReportTypeHIDP_REPORT_TYPEin
UsagePageWORDin
LinkCollectionWORDinoptional
UsageWORDin
UsageValueINTin
PreparsedDataPHIDP_PREPARSED_DATAin
ReportLPSTRinout
ReportLengthDWORDin

戻り値の型: NTSTATUS

各言語での呼び出し定義

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

NTSTATUS HidP_SetScaledUsageValue(
    HIDP_REPORT_TYPE ReportType,
    WORD UsagePage,
    WORD LinkCollection,   // optional
    WORD Usage,
    INT UsageValue,
    PHIDP_PREPARSED_DATA PreparsedData,
    LPSTR Report,
    DWORD ReportLength
);
[DllImport("HID.dll", ExactSpelling = true)]
static extern int HidP_SetScaledUsageValue(
    int ReportType,   // HIDP_REPORT_TYPE
    ushort UsagePage,   // WORD
    ushort LinkCollection,   // WORD optional
    ushort Usage,   // WORD
    int UsageValue,   // INT
    IntPtr PreparsedData,   // PHIDP_PREPARSED_DATA
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder Report,   // LPSTR in/out
    uint ReportLength   // DWORD
);
<DllImport("HID.dll", ExactSpelling:=True)>
Public Shared Function HidP_SetScaledUsageValue(
    ReportType As Integer,   ' HIDP_REPORT_TYPE
    UsagePage As UShort,   ' WORD
    LinkCollection As UShort,   ' WORD optional
    Usage As UShort,   ' WORD
    UsageValue As Integer,   ' INT
    PreparsedData As IntPtr,   ' PHIDP_PREPARSED_DATA
    <MarshalAs(UnmanagedType.LPStr)> Report As System.Text.StringBuilder,   ' LPSTR in/out
    ReportLength As UInteger   ' DWORD
) As Integer
End Function
' ReportType : HIDP_REPORT_TYPE
' UsagePage : WORD
' LinkCollection : WORD optional
' Usage : WORD
' UsageValue : INT
' PreparsedData : PHIDP_PREPARSED_DATA
' Report : LPSTR in/out
' ReportLength : DWORD
Declare PtrSafe Function HidP_SetScaledUsageValue Lib "hid" ( _
    ByVal ReportType As Long, _
    ByVal UsagePage As Integer, _
    ByVal LinkCollection As Integer, _
    ByVal Usage As Integer, _
    ByVal UsageValue As Long, _
    ByVal PreparsedData As LongPtr, _
    ByVal Report As String, _
    ByVal ReportLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HidP_SetScaledUsageValue = ctypes.windll.hid.HidP_SetScaledUsageValue
HidP_SetScaledUsageValue.restype = ctypes.c_int
HidP_SetScaledUsageValue.argtypes = [
    ctypes.c_int,  # ReportType : HIDP_REPORT_TYPE
    ctypes.c_ushort,  # UsagePage : WORD
    ctypes.c_ushort,  # LinkCollection : WORD optional
    ctypes.c_ushort,  # Usage : WORD
    ctypes.c_int,  # UsageValue : INT
    ctypes.c_ssize_t,  # PreparsedData : PHIDP_PREPARSED_DATA
    wintypes.LPSTR,  # Report : LPSTR in/out
    wintypes.DWORD,  # ReportLength : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('HID.dll')
HidP_SetScaledUsageValue = Fiddle::Function.new(
  lib['HidP_SetScaledUsageValue'],
  [
    Fiddle::TYPE_INT,  # ReportType : HIDP_REPORT_TYPE
    -Fiddle::TYPE_SHORT,  # UsagePage : WORD
    -Fiddle::TYPE_SHORT,  # LinkCollection : WORD optional
    -Fiddle::TYPE_SHORT,  # Usage : WORD
    Fiddle::TYPE_INT,  # UsageValue : INT
    Fiddle::TYPE_INTPTR_T,  # PreparsedData : PHIDP_PREPARSED_DATA
    Fiddle::TYPE_VOIDP,  # Report : LPSTR in/out
    -Fiddle::TYPE_INT,  # ReportLength : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "hid")]
extern "system" {
    fn HidP_SetScaledUsageValue(
        ReportType: i32,  // HIDP_REPORT_TYPE
        UsagePage: u16,  // WORD
        LinkCollection: u16,  // WORD optional
        Usage: u16,  // WORD
        UsageValue: i32,  // INT
        PreparsedData: isize,  // PHIDP_PREPARSED_DATA
        Report: *mut u8,  // LPSTR in/out
        ReportLength: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("HID.dll")]
public static extern int HidP_SetScaledUsageValue(int ReportType, ushort UsagePage, ushort LinkCollection, ushort Usage, int UsageValue, IntPtr PreparsedData, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder Report, uint ReportLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'HID_HidP_SetScaledUsageValue' -Namespace Win32 -PassThru
# $api::HidP_SetScaledUsageValue(ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, Report, ReportLength)
#uselib "HID.dll"
#func global HidP_SetScaledUsageValue "HidP_SetScaledUsageValue" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; HidP_SetScaledUsageValue ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, varptr(Report), ReportLength   ; 戻り値は stat
; ReportType : HIDP_REPORT_TYPE -> "sptr"
; UsagePage : WORD -> "sptr"
; LinkCollection : WORD optional -> "sptr"
; Usage : WORD -> "sptr"
; UsageValue : INT -> "sptr"
; PreparsedData : PHIDP_PREPARSED_DATA -> "sptr"
; Report : LPSTR in/out -> "sptr"
; ReportLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "HID.dll"
#cfunc global HidP_SetScaledUsageValue "HidP_SetScaledUsageValue" int, int, int, int, int, sptr, var, int
; res = HidP_SetScaledUsageValue(ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, Report, ReportLength)
; ReportType : HIDP_REPORT_TYPE -> "int"
; UsagePage : WORD -> "int"
; LinkCollection : WORD optional -> "int"
; Usage : WORD -> "int"
; UsageValue : INT -> "int"
; PreparsedData : PHIDP_PREPARSED_DATA -> "sptr"
; Report : LPSTR in/out -> "var"
; ReportLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; NTSTATUS HidP_SetScaledUsageValue(HIDP_REPORT_TYPE ReportType, WORD UsagePage, WORD LinkCollection, WORD Usage, INT UsageValue, PHIDP_PREPARSED_DATA PreparsedData, LPSTR Report, DWORD ReportLength)
#uselib "HID.dll"
#cfunc global HidP_SetScaledUsageValue "HidP_SetScaledUsageValue" int, int, int, int, int, intptr, var, int
; res = HidP_SetScaledUsageValue(ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, Report, ReportLength)
; ReportType : HIDP_REPORT_TYPE -> "int"
; UsagePage : WORD -> "int"
; LinkCollection : WORD optional -> "int"
; Usage : WORD -> "int"
; UsageValue : INT -> "int"
; PreparsedData : PHIDP_PREPARSED_DATA -> "intptr"
; Report : LPSTR in/out -> "var"
; ReportLength : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	hid = windows.NewLazySystemDLL("HID.dll")
	procHidP_SetScaledUsageValue = hid.NewProc("HidP_SetScaledUsageValue")
)

// ReportType (HIDP_REPORT_TYPE), UsagePage (WORD), LinkCollection (WORD optional), Usage (WORD), UsageValue (INT), PreparsedData (PHIDP_PREPARSED_DATA), Report (LPSTR in/out), ReportLength (DWORD)
r1, _, err := procHidP_SetScaledUsageValue.Call(
	uintptr(ReportType),
	uintptr(UsagePage),
	uintptr(LinkCollection),
	uintptr(Usage),
	uintptr(UsageValue),
	uintptr(PreparsedData),
	uintptr(Report),
	uintptr(ReportLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function HidP_SetScaledUsageValue(
  ReportType: Integer;   // HIDP_REPORT_TYPE
  UsagePage: Word;   // WORD
  LinkCollection: Word;   // WORD optional
  Usage: Word;   // WORD
  UsageValue: Integer;   // INT
  PreparsedData: NativeInt;   // PHIDP_PREPARSED_DATA
  Report: PAnsiChar;   // LPSTR in/out
  ReportLength: DWORD   // DWORD
): Integer; stdcall;
  external 'HID.dll' name 'HidP_SetScaledUsageValue';
result := DllCall("HID\HidP_SetScaledUsageValue"
    , "Int", ReportType   ; HIDP_REPORT_TYPE
    , "UShort", UsagePage   ; WORD
    , "UShort", LinkCollection   ; WORD optional
    , "UShort", Usage   ; WORD
    , "Int", UsageValue   ; INT
    , "Ptr", PreparsedData   ; PHIDP_PREPARSED_DATA
    , "Ptr", Report   ; LPSTR in/out
    , "UInt", ReportLength   ; DWORD
    , "Int")   ; return: NTSTATUS
●HidP_SetScaledUsageValue(ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, Report, ReportLength) = DLL("HID.dll", "int HidP_SetScaledUsageValue(int, int, int, int, int, int, char*, dword)")
# 呼び出し: HidP_SetScaledUsageValue(ReportType, UsagePage, LinkCollection, Usage, UsageValue, PreparsedData, Report, ReportLength)
# ReportType : HIDP_REPORT_TYPE -> "int"
# UsagePage : WORD -> "int"
# LinkCollection : WORD optional -> "int"
# Usage : WORD -> "int"
# UsageValue : INT -> "int"
# PreparsedData : PHIDP_PREPARSED_DATA -> "int"
# Report : LPSTR in/out -> "char*"
# ReportLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。