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

SwDeviceInterfaceSetState

関数
ソフトウェアデバイスのインターフェイスの有効状態を設定する。
DLLCFGMGR32.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT SwDeviceInterfaceSetState(
    HSWDEVICE hSwDevice,
    LPCWSTR pszDeviceInterfaceId,
    BOOL fEnabled
);

パラメーター

名前方向
hSwDeviceHSWDEVICEin
pszDeviceInterfaceIdLPCWSTRin
fEnabledBOOLin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SwDeviceInterfaceSetState(
    HSWDEVICE hSwDevice,
    LPCWSTR pszDeviceInterfaceId,
    BOOL fEnabled
);
[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern int SwDeviceInterfaceSetState(
    IntPtr hSwDevice,   // HSWDEVICE
    [MarshalAs(UnmanagedType.LPWStr)] string pszDeviceInterfaceId,   // LPCWSTR
    bool fEnabled   // BOOL
);
<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function SwDeviceInterfaceSetState(
    hSwDevice As IntPtr,   ' HSWDEVICE
    <MarshalAs(UnmanagedType.LPWStr)> pszDeviceInterfaceId As String,   ' LPCWSTR
    fEnabled As Boolean   ' BOOL
) As Integer
End Function
' hSwDevice : HSWDEVICE
' pszDeviceInterfaceId : LPCWSTR
' fEnabled : BOOL
Declare PtrSafe Function SwDeviceInterfaceSetState Lib "cfgmgr32" ( _
    ByVal hSwDevice As LongPtr, _
    ByVal pszDeviceInterfaceId As LongPtr, _
    ByVal fEnabled As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SwDeviceInterfaceSetState = ctypes.windll.cfgmgr32.SwDeviceInterfaceSetState
SwDeviceInterfaceSetState.restype = ctypes.c_int
SwDeviceInterfaceSetState.argtypes = [
    wintypes.HANDLE,  # hSwDevice : HSWDEVICE
    wintypes.LPCWSTR,  # pszDeviceInterfaceId : LPCWSTR
    wintypes.BOOL,  # fEnabled : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CFGMGR32.dll')
SwDeviceInterfaceSetState = Fiddle::Function.new(
  lib['SwDeviceInterfaceSetState'],
  [
    Fiddle::TYPE_VOIDP,  # hSwDevice : HSWDEVICE
    Fiddle::TYPE_VOIDP,  # pszDeviceInterfaceId : LPCWSTR
    Fiddle::TYPE_INT,  # fEnabled : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "cfgmgr32")]
extern "system" {
    fn SwDeviceInterfaceSetState(
        hSwDevice: *mut core::ffi::c_void,  // HSWDEVICE
        pszDeviceInterfaceId: *const u16,  // LPCWSTR
        fEnabled: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CFGMGR32.dll")]
public static extern int SwDeviceInterfaceSetState(IntPtr hSwDevice, [MarshalAs(UnmanagedType.LPWStr)] string pszDeviceInterfaceId, bool fEnabled);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_SwDeviceInterfaceSetState' -Namespace Win32 -PassThru
# $api::SwDeviceInterfaceSetState(hSwDevice, pszDeviceInterfaceId, fEnabled)
#uselib "CFGMGR32.dll"
#func global SwDeviceInterfaceSetState "SwDeviceInterfaceSetState" sptr, sptr, sptr
; SwDeviceInterfaceSetState hSwDevice, pszDeviceInterfaceId, fEnabled   ; 戻り値は stat
; hSwDevice : HSWDEVICE -> "sptr"
; pszDeviceInterfaceId : LPCWSTR -> "sptr"
; fEnabled : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceInterfaceSetState "SwDeviceInterfaceSetState" sptr, wstr, int
; res = SwDeviceInterfaceSetState(hSwDevice, pszDeviceInterfaceId, fEnabled)
; hSwDevice : HSWDEVICE -> "sptr"
; pszDeviceInterfaceId : LPCWSTR -> "wstr"
; fEnabled : BOOL -> "int"
; HRESULT SwDeviceInterfaceSetState(HSWDEVICE hSwDevice, LPCWSTR pszDeviceInterfaceId, BOOL fEnabled)
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceInterfaceSetState "SwDeviceInterfaceSetState" intptr, wstr, int
; res = SwDeviceInterfaceSetState(hSwDevice, pszDeviceInterfaceId, fEnabled)
; hSwDevice : HSWDEVICE -> "intptr"
; pszDeviceInterfaceId : LPCWSTR -> "wstr"
; fEnabled : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
	procSwDeviceInterfaceSetState = cfgmgr32.NewProc("SwDeviceInterfaceSetState")
)

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