Win32 API 日本語リファレンス
ホームDevices.Enumeration.Pnp › SwDevicePropertySet

SwDevicePropertySet

関数
ソフトウェアデバイスのプロパティを設定する。
DLLCFGMGR32.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT SwDevicePropertySet(
    HSWDEVICE hSwDevice,
    DWORD cPropertyCount,
    const DEVPROPERTY* pProperties
);

パラメーター

名前方向説明
hSwDeviceHSWDEVICEin対象のソフトウェアデバイスハンドルを指定する。
cPropertyCountDWORDinpProperties配列が含むプロパティ数を指定する。
pPropertiesDEVPROPERTY*in設定するDEVPROPERTY配列へのポインタを指定する。デバイスプロパティを更新する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SwDevicePropertySet(
    HSWDEVICE hSwDevice,
    DWORD cPropertyCount,
    const DEVPROPERTY* pProperties
);
[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern int SwDevicePropertySet(
    IntPtr hSwDevice,   // HSWDEVICE
    uint cPropertyCount,   // DWORD
    IntPtr pProperties   // DEVPROPERTY*
);
<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function SwDevicePropertySet(
    hSwDevice As IntPtr,   ' HSWDEVICE
    cPropertyCount As UInteger,   ' DWORD
    pProperties As IntPtr   ' DEVPROPERTY*
) As Integer
End Function
' hSwDevice : HSWDEVICE
' cPropertyCount : DWORD
' pProperties : DEVPROPERTY*
Declare PtrSafe Function SwDevicePropertySet Lib "cfgmgr32" ( _
    ByVal hSwDevice As LongPtr, _
    ByVal cPropertyCount As Long, _
    ByVal pProperties As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SwDevicePropertySet = ctypes.windll.cfgmgr32.SwDevicePropertySet
SwDevicePropertySet.restype = ctypes.c_int
SwDevicePropertySet.argtypes = [
    wintypes.HANDLE,  # hSwDevice : HSWDEVICE
    wintypes.DWORD,  # cPropertyCount : DWORD
    ctypes.c_void_p,  # pProperties : DEVPROPERTY*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CFGMGR32.dll')
SwDevicePropertySet = Fiddle::Function.new(
  lib['SwDevicePropertySet'],
  [
    Fiddle::TYPE_VOIDP,  # hSwDevice : HSWDEVICE
    -Fiddle::TYPE_INT,  # cPropertyCount : DWORD
    Fiddle::TYPE_VOIDP,  # pProperties : DEVPROPERTY*
  ],
  Fiddle::TYPE_INT)
#[link(name = "cfgmgr32")]
extern "system" {
    fn SwDevicePropertySet(
        hSwDevice: *mut core::ffi::c_void,  // HSWDEVICE
        cPropertyCount: u32,  // DWORD
        pProperties: *const DEVPROPERTY  // DEVPROPERTY*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CFGMGR32.dll")]
public static extern int SwDevicePropertySet(IntPtr hSwDevice, uint cPropertyCount, IntPtr pProperties);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_SwDevicePropertySet' -Namespace Win32 -PassThru
# $api::SwDevicePropertySet(hSwDevice, cPropertyCount, pProperties)
#uselib "CFGMGR32.dll"
#func global SwDevicePropertySet "SwDevicePropertySet" sptr, sptr, sptr
; SwDevicePropertySet hSwDevice, cPropertyCount, varptr(pProperties)   ; 戻り値は stat
; hSwDevice : HSWDEVICE -> "sptr"
; cPropertyCount : DWORD -> "sptr"
; pProperties : DEVPROPERTY* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CFGMGR32.dll"
#cfunc global SwDevicePropertySet "SwDevicePropertySet" sptr, int, var
; res = SwDevicePropertySet(hSwDevice, cPropertyCount, pProperties)
; hSwDevice : HSWDEVICE -> "sptr"
; cPropertyCount : DWORD -> "int"
; pProperties : DEVPROPERTY* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SwDevicePropertySet(HSWDEVICE hSwDevice, DWORD cPropertyCount, DEVPROPERTY* pProperties)
#uselib "CFGMGR32.dll"
#cfunc global SwDevicePropertySet "SwDevicePropertySet" intptr, int, var
; res = SwDevicePropertySet(hSwDevice, cPropertyCount, pProperties)
; hSwDevice : HSWDEVICE -> "intptr"
; cPropertyCount : DWORD -> "int"
; pProperties : DEVPROPERTY* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
	procSwDevicePropertySet = cfgmgr32.NewProc("SwDevicePropertySet")
)

// hSwDevice (HSWDEVICE), cPropertyCount (DWORD), pProperties (DEVPROPERTY*)
r1, _, err := procSwDevicePropertySet.Call(
	uintptr(hSwDevice),
	uintptr(cPropertyCount),
	uintptr(pProperties),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SwDevicePropertySet(
  hSwDevice: THandle;   // HSWDEVICE
  cPropertyCount: DWORD;   // DWORD
  pProperties: Pointer   // DEVPROPERTY*
): Integer; stdcall;
  external 'CFGMGR32.dll' name 'SwDevicePropertySet';
result := DllCall("CFGMGR32\SwDevicePropertySet"
    , "Ptr", hSwDevice   ; HSWDEVICE
    , "UInt", cPropertyCount   ; DWORD
    , "Ptr", pProperties   ; DEVPROPERTY*
    , "Int")   ; return: HRESULT
●SwDevicePropertySet(hSwDevice, cPropertyCount, pProperties) = DLL("CFGMGR32.dll", "int SwDevicePropertySet(void*, dword, void*)")
# 呼び出し: SwDevicePropertySet(hSwDevice, cPropertyCount, pProperties)
# hSwDevice : HSWDEVICE -> "void*"
# cPropertyCount : DWORD -> "dword"
# pProperties : DEVPROPERTY* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef SwDevicePropertySetNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>);
typedef SwDevicePropertySetDart = int Function(Pointer<Void>, int, Pointer<Void>);
final SwDevicePropertySet = DynamicLibrary.open('CFGMGR32.dll')
    .lookupFunction<SwDevicePropertySetNative, SwDevicePropertySetDart>('SwDevicePropertySet');
// hSwDevice : HSWDEVICE -> Pointer<Void>
// cPropertyCount : DWORD -> Uint32
// pProperties : DEVPROPERTY* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SwDevicePropertySet(
  hSwDevice: THandle;   // HSWDEVICE
  cPropertyCount: DWORD;   // DWORD
  pProperties: Pointer   // DEVPROPERTY*
): Integer; stdcall;
  external 'CFGMGR32.dll' name 'SwDevicePropertySet';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SwDevicePropertySet"
  c_SwDevicePropertySet :: Ptr () -> Word32 -> Ptr () -> IO Int32
-- hSwDevice : HSWDEVICE -> Ptr ()
-- cPropertyCount : DWORD -> Word32
-- pProperties : DEVPROPERTY* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let swdevicepropertyset =
  foreign "SwDevicePropertySet"
    ((ptr void) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hSwDevice : HSWDEVICE -> (ptr void) *)
(* cPropertyCount : DWORD -> uint32_t *)
(* pProperties : DEVPROPERTY* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library cfgmgr32 (t "CFGMGR32.dll"))
(cffi:use-foreign-library cfgmgr32)

(cffi:defcfun ("SwDevicePropertySet" sw-device-property-set :convention :stdcall) :int32
  (h-sw-device :pointer)   ; HSWDEVICE
  (c-property-count :uint32)   ; DWORD
  (p-properties :pointer))   ; DEVPROPERTY*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SwDevicePropertySet = Win32::API::More->new('CFGMGR32',
    'int SwDevicePropertySet(HANDLE hSwDevice, DWORD cPropertyCount, LPVOID pProperties)');
# my $ret = $SwDevicePropertySet->Call($hSwDevice, $cPropertyCount, $pProperties);
# hSwDevice : HSWDEVICE -> HANDLE
# cPropertyCount : DWORD -> DWORD
# pProperties : DEVPROPERTY* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型