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
cPropertyCountDWORDin
pPropertiesDEVPROPERTY*in

戻り値の型: 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)。