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

SetVCPFeature

関数
モニタの指定VCP機能に新しい値を設定する。
DLLdxva2.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

INT SetVCPFeature(
    HANDLE hMonitor,
    BYTE bVCPCode,
    DWORD dwNewValue
);

パラメーター

名前方向説明
hMonitorHANDLEin物理モニターへのハンドル。モニターハンドルを取得するには、GetPhysicalMonitorsFromHMONITOR または GetPhysicalMonitorsFromIDirect3DDevice9 を呼び出します。
bVCPCodeBYTEin設定する VCP コード。VCP コードは VESA Monitor Control Command Set (MCCS) 標準のバージョン 1.0 および 2.0 で定義されています。このパラメーターには、連続もしくは非連続の VCP、またはベンダー固有のコードを指定する必要があります。テーブル制御コードは指定できません。
dwNewValueDWORDinVCP コードの値。

戻り値の型: INT

公式ドキュメント

モニターの仮想コントロールパネル (VCP) コードの値を設定します。

戻り値

関数が成功した場合、戻り値は TRUE です。関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

この関数は、Display Data Channel Command Interface (DDC/CI) 標準の "Set VCP Feature" コマンドに対応します。

この関数が戻るまでに約 50 ミリ秒かかります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

INT SetVCPFeature(
    HANDLE hMonitor,
    BYTE bVCPCode,
    DWORD dwNewValue
);
[DllImport("dxva2.dll", ExactSpelling = true)]
static extern int SetVCPFeature(
    IntPtr hMonitor,   // HANDLE
    byte bVCPCode,   // BYTE
    uint dwNewValue   // DWORD
);
<DllImport("dxva2.dll", ExactSpelling:=True)>
Public Shared Function SetVCPFeature(
    hMonitor As IntPtr,   ' HANDLE
    bVCPCode As Byte,   ' BYTE
    dwNewValue As UInteger   ' DWORD
) As Integer
End Function
' hMonitor : HANDLE
' bVCPCode : BYTE
' dwNewValue : DWORD
Declare PtrSafe Function SetVCPFeature Lib "dxva2" ( _
    ByVal hMonitor As LongPtr, _
    ByVal bVCPCode As Byte, _
    ByVal dwNewValue As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetVCPFeature = ctypes.windll.dxva2.SetVCPFeature
SetVCPFeature.restype = ctypes.c_int
SetVCPFeature.argtypes = [
    wintypes.HANDLE,  # hMonitor : HANDLE
    ctypes.c_ubyte,  # bVCPCode : BYTE
    wintypes.DWORD,  # dwNewValue : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dxva2.dll')
SetVCPFeature = Fiddle::Function.new(
  lib['SetVCPFeature'],
  [
    Fiddle::TYPE_VOIDP,  # hMonitor : HANDLE
    -Fiddle::TYPE_CHAR,  # bVCPCode : BYTE
    -Fiddle::TYPE_INT,  # dwNewValue : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "dxva2")]
extern "system" {
    fn SetVCPFeature(
        hMonitor: *mut core::ffi::c_void,  // HANDLE
        bVCPCode: u8,  // BYTE
        dwNewValue: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("dxva2.dll")]
public static extern int SetVCPFeature(IntPtr hMonitor, byte bVCPCode, uint dwNewValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dxva2_SetVCPFeature' -Namespace Win32 -PassThru
# $api::SetVCPFeature(hMonitor, bVCPCode, dwNewValue)
#uselib "dxva2.dll"
#func global SetVCPFeature "SetVCPFeature" sptr, sptr, sptr
; SetVCPFeature hMonitor, bVCPCode, dwNewValue   ; 戻り値は stat
; hMonitor : HANDLE -> "sptr"
; bVCPCode : BYTE -> "sptr"
; dwNewValue : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "dxva2.dll"
#cfunc global SetVCPFeature "SetVCPFeature" sptr, int, int
; res = SetVCPFeature(hMonitor, bVCPCode, dwNewValue)
; hMonitor : HANDLE -> "sptr"
; bVCPCode : BYTE -> "int"
; dwNewValue : DWORD -> "int"
; INT SetVCPFeature(HANDLE hMonitor, BYTE bVCPCode, DWORD dwNewValue)
#uselib "dxva2.dll"
#cfunc global SetVCPFeature "SetVCPFeature" intptr, int, int
; res = SetVCPFeature(hMonitor, bVCPCode, dwNewValue)
; hMonitor : HANDLE -> "intptr"
; bVCPCode : BYTE -> "int"
; dwNewValue : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dxva2 = windows.NewLazySystemDLL("dxva2.dll")
	procSetVCPFeature = dxva2.NewProc("SetVCPFeature")
)

// hMonitor (HANDLE), bVCPCode (BYTE), dwNewValue (DWORD)
r1, _, err := procSetVCPFeature.Call(
	uintptr(hMonitor),
	uintptr(bVCPCode),
	uintptr(dwNewValue),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SetVCPFeature(
  hMonitor: THandle;   // HANDLE
  bVCPCode: Byte;   // BYTE
  dwNewValue: DWORD   // DWORD
): Integer; stdcall;
  external 'dxva2.dll' name 'SetVCPFeature';
result := DllCall("dxva2\SetVCPFeature"
    , "Ptr", hMonitor   ; HANDLE
    , "UChar", bVCPCode   ; BYTE
    , "UInt", dwNewValue   ; DWORD
    , "Int")   ; return: INT
●SetVCPFeature(hMonitor, bVCPCode, dwNewValue) = DLL("dxva2.dll", "int SetVCPFeature(void*, byte, dword)")
# 呼び出し: SetVCPFeature(hMonitor, bVCPCode, dwNewValue)
# hMonitor : HANDLE -> "void*"
# bVCPCode : BYTE -> "byte"
# dwNewValue : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "dxva2" fn SetVCPFeature(
    hMonitor: ?*anyopaque, // HANDLE
    bVCPCode: u8, // BYTE
    dwNewValue: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SetVCPFeature(
    hMonitor: pointer,  # HANDLE
    bVCPCode: uint8,  # BYTE
    dwNewValue: uint32  # DWORD
): int32 {.importc: "SetVCPFeature", stdcall, dynlib: "dxva2.dll".}
pragma(lib, "dxva2");
extern(Windows)
int SetVCPFeature(
    void* hMonitor,   // HANDLE
    ubyte bVCPCode,   // BYTE
    uint dwNewValue   // DWORD
);
ccall((:SetVCPFeature, "dxva2.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt8, UInt32),
      hMonitor, bVCPCode, dwNewValue)
# hMonitor : HANDLE -> Ptr{Cvoid}
# bVCPCode : BYTE -> UInt8
# dwNewValue : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetVCPFeature(
    void* hMonitor,
    uint8_t bVCPCode,
    uint32_t dwNewValue);
]]
local dxva2 = ffi.load("dxva2")
-- dxva2.SetVCPFeature(hMonitor, bVCPCode, dwNewValue)
-- hMonitor : HANDLE
-- bVCPCode : BYTE
-- dwNewValue : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('dxva2.dll');
const SetVCPFeature = lib.func('__stdcall', 'SetVCPFeature', 'int32_t', ['void *', 'uint8_t', 'uint32_t']);
// SetVCPFeature(hMonitor, bVCPCode, dwNewValue)
// hMonitor : HANDLE -> 'void *'
// bVCPCode : BYTE -> 'uint8_t'
// dwNewValue : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dxva2.dll", {
  SetVCPFeature: { parameters: ["pointer", "u8", "u32"], result: "i32" },
});
// lib.symbols.SetVCPFeature(hMonitor, bVCPCode, dwNewValue)
// hMonitor : HANDLE -> "pointer"
// bVCPCode : BYTE -> "u8"
// dwNewValue : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetVCPFeature(
    void* hMonitor,
    uint8_t bVCPCode,
    uint32_t dwNewValue);
C, "dxva2.dll");
// $ffi->SetVCPFeature(hMonitor, bVCPCode, dwNewValue);
// hMonitor : HANDLE
// bVCPCode : BYTE
// dwNewValue : 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 Dxva2 extends StdCallLibrary {
    Dxva2 INSTANCE = Native.load("dxva2", Dxva2.class);
    int SetVCPFeature(
        Pointer hMonitor,   // HANDLE
        byte bVCPCode,   // BYTE
        int dwNewValue   // DWORD
    );
}
@[Link("dxva2")]
lib Libdxva2
  fun SetVCPFeature = SetVCPFeature(
    hMonitor : Void*,   # HANDLE
    bVCPCode : UInt8,   # BYTE
    dwNewValue : 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 SetVCPFeatureNative = Int32 Function(Pointer<Void>, Uint8, Uint32);
typedef SetVCPFeatureDart = int Function(Pointer<Void>, int, int);
final SetVCPFeature = DynamicLibrary.open('dxva2.dll')
    .lookupFunction<SetVCPFeatureNative, SetVCPFeatureDart>('SetVCPFeature');
// hMonitor : HANDLE -> Pointer<Void>
// bVCPCode : BYTE -> Uint8
// dwNewValue : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetVCPFeature(
  hMonitor: THandle;   // HANDLE
  bVCPCode: Byte;   // BYTE
  dwNewValue: DWORD   // DWORD
): Integer; stdcall;
  external 'dxva2.dll' name 'SetVCPFeature';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetVCPFeature"
  c_SetVCPFeature :: Ptr () -> Word8 -> Word32 -> IO Int32
-- hMonitor : HANDLE -> Ptr ()
-- bVCPCode : BYTE -> Word8
-- dwNewValue : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setvcpfeature =
  foreign "SetVCPFeature"
    ((ptr void) @-> uint8_t @-> uint32_t @-> returning int32_t)
(* hMonitor : HANDLE -> (ptr void) *)
(* bVCPCode : BYTE -> uint8_t *)
(* dwNewValue : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dxva2 (t "dxva2.dll"))
(cffi:use-foreign-library dxva2)

(cffi:defcfun ("SetVCPFeature" set-vcpfeature :convention :stdcall) :int32
  (h-monitor :pointer)   ; HANDLE
  (b-vcpcode :uint8)   ; BYTE
  (dw-new-value :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetVCPFeature = Win32::API::More->new('dxva2',
    'int SetVCPFeature(HANDLE hMonitor, BYTE bVCPCode, DWORD dwNewValue)');
# my $ret = $SetVCPFeature->Call($hMonitor, $bVCPCode, $dwNewValue);
# hMonitor : HANDLE -> HANDLE
# bVCPCode : BYTE -> BYTE
# dwNewValue : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。