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

SwDeviceInterfacePropertySet

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

シグネチャ

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

HRESULT SwDeviceInterfacePropertySet(
    HSWDEVICE hSwDevice,
    LPCWSTR pszDeviceInterfaceId,
    DWORD cPropertyCount,
    const DEVPROPERTY* pProperties
);

パラメーター

名前方向
hSwDeviceHSWDEVICEin
pszDeviceInterfaceIdLPCWSTRin
cPropertyCountDWORDin
pPropertiesDEVPROPERTY*in

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SwDeviceInterfacePropertySet(
    HSWDEVICE hSwDevice,
    LPCWSTR pszDeviceInterfaceId,
    DWORD cPropertyCount,
    const DEVPROPERTY* pProperties
);
[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern int SwDeviceInterfacePropertySet(
    IntPtr hSwDevice,   // HSWDEVICE
    [MarshalAs(UnmanagedType.LPWStr)] string pszDeviceInterfaceId,   // LPCWSTR
    uint cPropertyCount,   // DWORD
    IntPtr pProperties   // DEVPROPERTY*
);
<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function SwDeviceInterfacePropertySet(
    hSwDevice As IntPtr,   ' HSWDEVICE
    <MarshalAs(UnmanagedType.LPWStr)> pszDeviceInterfaceId As String,   ' LPCWSTR
    cPropertyCount As UInteger,   ' DWORD
    pProperties As IntPtr   ' DEVPROPERTY*
) As Integer
End Function
' hSwDevice : HSWDEVICE
' pszDeviceInterfaceId : LPCWSTR
' cPropertyCount : DWORD
' pProperties : DEVPROPERTY*
Declare PtrSafe Function SwDeviceInterfacePropertySet Lib "cfgmgr32" ( _
    ByVal hSwDevice As LongPtr, _
    ByVal pszDeviceInterfaceId 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

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

lib = Fiddle.dlopen('CFGMGR32.dll')
SwDeviceInterfacePropertySet = Fiddle::Function.new(
  lib['SwDeviceInterfacePropertySet'],
  [
    Fiddle::TYPE_VOIDP,  # hSwDevice : HSWDEVICE
    Fiddle::TYPE_VOIDP,  # pszDeviceInterfaceId : LPCWSTR
    -Fiddle::TYPE_INT,  # cPropertyCount : DWORD
    Fiddle::TYPE_VOIDP,  # pProperties : DEVPROPERTY*
  ],
  Fiddle::TYPE_INT)
#[link(name = "cfgmgr32")]
extern "system" {
    fn SwDeviceInterfacePropertySet(
        hSwDevice: *mut core::ffi::c_void,  // HSWDEVICE
        pszDeviceInterfaceId: *const u16,  // LPCWSTR
        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 SwDeviceInterfacePropertySet(IntPtr hSwDevice, [MarshalAs(UnmanagedType.LPWStr)] string pszDeviceInterfaceId, uint cPropertyCount, IntPtr pProperties);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_SwDeviceInterfacePropertySet' -Namespace Win32 -PassThru
# $api::SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
#uselib "CFGMGR32.dll"
#func global SwDeviceInterfacePropertySet "SwDeviceInterfacePropertySet" sptr, sptr, sptr, sptr
; SwDeviceInterfacePropertySet hSwDevice, pszDeviceInterfaceId, cPropertyCount, varptr(pProperties)   ; 戻り値は stat
; hSwDevice : HSWDEVICE -> "sptr"
; pszDeviceInterfaceId : LPCWSTR -> "sptr"
; cPropertyCount : DWORD -> "sptr"
; pProperties : DEVPROPERTY* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceInterfacePropertySet "SwDeviceInterfacePropertySet" sptr, wstr, int, var
; res = SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
; hSwDevice : HSWDEVICE -> "sptr"
; pszDeviceInterfaceId : LPCWSTR -> "wstr"
; cPropertyCount : DWORD -> "int"
; pProperties : DEVPROPERTY* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SwDeviceInterfacePropertySet(HSWDEVICE hSwDevice, LPCWSTR pszDeviceInterfaceId, DWORD cPropertyCount, DEVPROPERTY* pProperties)
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceInterfacePropertySet "SwDeviceInterfacePropertySet" intptr, wstr, int, var
; res = SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
; hSwDevice : HSWDEVICE -> "intptr"
; pszDeviceInterfaceId : LPCWSTR -> "wstr"
; cPropertyCount : DWORD -> "int"
; pProperties : DEVPROPERTY* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
	procSwDeviceInterfacePropertySet = cfgmgr32.NewProc("SwDeviceInterfacePropertySet")
)

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