ホーム › Devices.Enumeration.Pnp › SwDeviceInterfaceSetState
SwDeviceInterfaceSetState
関数ソフトウェアデバイスのインターフェイスの有効状態を設定する。
シグネチャ
// CFGMGR32.dll
#include <windows.h>
HRESULT SwDeviceInterfaceSetState(
HSWDEVICE hSwDevice,
LPCWSTR pszDeviceInterfaceId,
BOOL fEnabled
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hSwDevice | HSWDEVICE | in | 対象のソフトウェアデバイスハンドルを指定する。 |
| pszDeviceInterfaceId | LPCWSTR | in | 状態を変更する対象のデバイスインターフェイスID文字列を指定する。 |
| fEnabled | BOOL | in | インターフェイスの有効/無効をBOOLで指定する。TRUEで有効化、FALSEで無効化。 |
戻り値の型: 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 // HRESULTfunction 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)。const std = @import("std");
extern "cfgmgr32" fn SwDeviceInterfaceSetState(
hSwDevice: ?*anyopaque, // HSWDEVICE
pszDeviceInterfaceId: [*c]const u16, // LPCWSTR
fEnabled: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;proc SwDeviceInterfaceSetState(
hSwDevice: pointer, # HSWDEVICE
pszDeviceInterfaceId: WideCString, # LPCWSTR
fEnabled: int32 # BOOL
): int32 {.importc: "SwDeviceInterfaceSetState", stdcall, dynlib: "CFGMGR32.dll".}pragma(lib, "cfgmgr32");
extern(Windows)
int SwDeviceInterfaceSetState(
void* hSwDevice, // HSWDEVICE
const(wchar)* pszDeviceInterfaceId, // LPCWSTR
int fEnabled // BOOL
);ccall((:SwDeviceInterfaceSetState, "CFGMGR32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Int32),
hSwDevice, pszDeviceInterfaceId, fEnabled)
# hSwDevice : HSWDEVICE -> Ptr{Cvoid}
# pszDeviceInterfaceId : LPCWSTR -> Cwstring
# fEnabled : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SwDeviceInterfaceSetState(
void* hSwDevice,
const uint16_t* pszDeviceInterfaceId,
int32_t fEnabled);
]]
local cfgmgr32 = ffi.load("cfgmgr32")
-- cfgmgr32.SwDeviceInterfaceSetState(hSwDevice, pszDeviceInterfaceId, fEnabled)
-- hSwDevice : HSWDEVICE
-- pszDeviceInterfaceId : LPCWSTR
-- fEnabled : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('CFGMGR32.dll');
const SwDeviceInterfaceSetState = lib.func('__stdcall', 'SwDeviceInterfaceSetState', 'int32_t', ['void *', 'str16', 'int32_t']);
// SwDeviceInterfaceSetState(hSwDevice, pszDeviceInterfaceId, fEnabled)
// hSwDevice : HSWDEVICE -> 'void *'
// pszDeviceInterfaceId : LPCWSTR -> 'str16'
// fEnabled : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("CFGMGR32.dll", {
SwDeviceInterfaceSetState: { parameters: ["pointer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.SwDeviceInterfaceSetState(hSwDevice, pszDeviceInterfaceId, fEnabled)
// hSwDevice : HSWDEVICE -> "pointer"
// pszDeviceInterfaceId : LPCWSTR -> "buffer"
// fEnabled : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SwDeviceInterfaceSetState(
void* hSwDevice,
const uint16_t* pszDeviceInterfaceId,
int32_t fEnabled);
C, "CFGMGR32.dll");
// $ffi->SwDeviceInterfaceSetState(hSwDevice, pszDeviceInterfaceId, fEnabled);
// hSwDevice : HSWDEVICE
// pszDeviceInterfaceId : LPCWSTR
// fEnabled : BOOL
// 構造体/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 SwDeviceInterfaceSetState(
Pointer hSwDevice, // HSWDEVICE
WString pszDeviceInterfaceId, // LPCWSTR
boolean fEnabled // BOOL
);
}@[Link("cfgmgr32")]
lib LibCFGMGR32
fun SwDeviceInterfaceSetState = SwDeviceInterfaceSetState(
hSwDevice : Void*, # HSWDEVICE
pszDeviceInterfaceId : UInt16*, # LPCWSTR
fEnabled : Int32 # BOOL
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SwDeviceInterfaceSetStateNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Int32);
typedef SwDeviceInterfaceSetStateDart = int Function(Pointer<Void>, Pointer<Utf16>, int);
final SwDeviceInterfaceSetState = DynamicLibrary.open('CFGMGR32.dll')
.lookupFunction<SwDeviceInterfaceSetStateNative, SwDeviceInterfaceSetStateDart>('SwDeviceInterfaceSetState');
// hSwDevice : HSWDEVICE -> Pointer<Void>
// pszDeviceInterfaceId : LPCWSTR -> Pointer<Utf16>
// fEnabled : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SwDeviceInterfaceSetState(
hSwDevice: THandle; // HSWDEVICE
pszDeviceInterfaceId: PWideChar; // LPCWSTR
fEnabled: BOOL // BOOL
): Integer; stdcall;
external 'CFGMGR32.dll' name 'SwDeviceInterfaceSetState';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SwDeviceInterfaceSetState"
c_SwDeviceInterfaceSetState :: Ptr () -> CWString -> CInt -> IO Int32
-- hSwDevice : HSWDEVICE -> Ptr ()
-- pszDeviceInterfaceId : LPCWSTR -> CWString
-- fEnabled : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let swdeviceinterfacesetstate =
foreign "SwDeviceInterfaceSetState"
((ptr void) @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* hSwDevice : HSWDEVICE -> (ptr void) *)
(* pszDeviceInterfaceId : LPCWSTR -> (ptr uint16_t) *)
(* fEnabled : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library cfgmgr32 (t "CFGMGR32.dll"))
(cffi:use-foreign-library cfgmgr32)
(cffi:defcfun ("SwDeviceInterfaceSetState" sw-device-interface-set-state :convention :stdcall) :int32
(h-sw-device :pointer) ; HSWDEVICE
(psz-device-interface-id (:string :encoding :utf-16le)) ; LPCWSTR
(f-enabled :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SwDeviceInterfaceSetState = Win32::API::More->new('CFGMGR32',
'int SwDeviceInterfaceSetState(HANDLE hSwDevice, LPCWSTR pszDeviceInterfaceId, BOOL fEnabled)');
# my $ret = $SwDeviceInterfaceSetState->Call($hSwDevice, $pszDeviceInterfaceId, $fEnabled);
# hSwDevice : HSWDEVICE -> HANDLE
# pszDeviceInterfaceId : LPCWSTR -> LPCWSTR
# fEnabled : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。