ホーム › Devices.DeviceAndDriverInstallation › SetupDiOpenDeviceInterfaceW
SetupDiOpenDeviceInterfaceW
関数デバイスパスを指定してデバイスインターフェイスを開く。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupDiOpenDeviceInterfaceW(
HDEVINFO DeviceInfoSet,
LPCWSTR DevicePath,
DWORD OpenFlags,
SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| DeviceInfoSet | HDEVINFO | in |
| DevicePath | LPCWSTR | in |
| OpenFlags | DWORD | in |
| DeviceInterfaceData | SP_DEVICE_INTERFACE_DATA* | inoutoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupDiOpenDeviceInterfaceW(
HDEVINFO DeviceInfoSet,
LPCWSTR DevicePath,
DWORD OpenFlags,
SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiOpenDeviceInterfaceW(
IntPtr DeviceInfoSet, // HDEVINFO
[MarshalAs(UnmanagedType.LPWStr)] string DevicePath, // LPCWSTR
uint OpenFlags, // DWORD
IntPtr DeviceInterfaceData // SP_DEVICE_INTERFACE_DATA* optional, in/out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiOpenDeviceInterfaceW(
DeviceInfoSet As IntPtr, ' HDEVINFO
<MarshalAs(UnmanagedType.LPWStr)> DevicePath As String, ' LPCWSTR
OpenFlags As UInteger, ' DWORD
DeviceInterfaceData As IntPtr ' SP_DEVICE_INTERFACE_DATA* optional, in/out
) As Boolean
End Function' DeviceInfoSet : HDEVINFO
' DevicePath : LPCWSTR
' OpenFlags : DWORD
' DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out
Declare PtrSafe Function SetupDiOpenDeviceInterfaceW Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DevicePath As LongPtr, _
ByVal OpenFlags As Long, _
ByVal DeviceInterfaceData As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupDiOpenDeviceInterfaceW = ctypes.windll.setupapi.SetupDiOpenDeviceInterfaceW
SetupDiOpenDeviceInterfaceW.restype = wintypes.BOOL
SetupDiOpenDeviceInterfaceW.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
wintypes.LPCWSTR, # DevicePath : LPCWSTR
wintypes.DWORD, # OpenFlags : DWORD
ctypes.c_void_p, # DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiOpenDeviceInterfaceW = Fiddle::Function.new(
lib['SetupDiOpenDeviceInterfaceW'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DevicePath : LPCWSTR
-Fiddle::TYPE_INT, # OpenFlags : DWORD
Fiddle::TYPE_VOIDP, # DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupDiOpenDeviceInterfaceW(
DeviceInfoSet: isize, // HDEVINFO
DevicePath: *const u16, // LPCWSTR
OpenFlags: u32, // DWORD
DeviceInterfaceData: *mut SP_DEVICE_INTERFACE_DATA // SP_DEVICE_INTERFACE_DATA* optional, in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupDiOpenDeviceInterfaceW(IntPtr DeviceInfoSet, [MarshalAs(UnmanagedType.LPWStr)] string DevicePath, uint OpenFlags, IntPtr DeviceInterfaceData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiOpenDeviceInterfaceW' -Namespace Win32 -PassThru
# $api::SetupDiOpenDeviceInterfaceW(DeviceInfoSet, DevicePath, OpenFlags, DeviceInterfaceData)#uselib "SETUPAPI.dll"
#func global SetupDiOpenDeviceInterfaceW "SetupDiOpenDeviceInterfaceW" wptr, wptr, wptr, wptr
; SetupDiOpenDeviceInterfaceW DeviceInfoSet, DevicePath, OpenFlags, varptr(DeviceInterfaceData) ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "wptr"
; DevicePath : LPCWSTR -> "wptr"
; OpenFlags : DWORD -> "wptr"
; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDeviceInterfaceW "SetupDiOpenDeviceInterfaceW" sptr, wstr, int, var ; res = SetupDiOpenDeviceInterfaceW(DeviceInfoSet, DevicePath, OpenFlags, DeviceInterfaceData) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DevicePath : LPCWSTR -> "wstr" ; OpenFlags : DWORD -> "int" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDeviceInterfaceW "SetupDiOpenDeviceInterfaceW" sptr, wstr, int, sptr ; res = SetupDiOpenDeviceInterfaceW(DeviceInfoSet, DevicePath, OpenFlags, varptr(DeviceInterfaceData)) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DevicePath : LPCWSTR -> "wstr" ; OpenFlags : DWORD -> "int" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupDiOpenDeviceInterfaceW(HDEVINFO DeviceInfoSet, LPCWSTR DevicePath, DWORD OpenFlags, SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData) #uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDeviceInterfaceW "SetupDiOpenDeviceInterfaceW" intptr, wstr, int, var ; res = SetupDiOpenDeviceInterfaceW(DeviceInfoSet, DevicePath, OpenFlags, DeviceInterfaceData) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DevicePath : LPCWSTR -> "wstr" ; OpenFlags : DWORD -> "int" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiOpenDeviceInterfaceW(HDEVINFO DeviceInfoSet, LPCWSTR DevicePath, DWORD OpenFlags, SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData) #uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDeviceInterfaceW "SetupDiOpenDeviceInterfaceW" intptr, wstr, int, intptr ; res = SetupDiOpenDeviceInterfaceW(DeviceInfoSet, DevicePath, OpenFlags, varptr(DeviceInterfaceData)) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DevicePath : LPCWSTR -> "wstr" ; OpenFlags : DWORD -> "int" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiOpenDeviceInterfaceW = setupapi.NewProc("SetupDiOpenDeviceInterfaceW")
)
// DeviceInfoSet (HDEVINFO), DevicePath (LPCWSTR), OpenFlags (DWORD), DeviceInterfaceData (SP_DEVICE_INTERFACE_DATA* optional, in/out)
r1, _, err := procSetupDiOpenDeviceInterfaceW.Call(
uintptr(DeviceInfoSet),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DevicePath))),
uintptr(OpenFlags),
uintptr(DeviceInterfaceData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiOpenDeviceInterfaceW(
DeviceInfoSet: NativeInt; // HDEVINFO
DevicePath: PWideChar; // LPCWSTR
OpenFlags: DWORD; // DWORD
DeviceInterfaceData: Pointer // SP_DEVICE_INTERFACE_DATA* optional, in/out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiOpenDeviceInterfaceW';result := DllCall("SETUPAPI\SetupDiOpenDeviceInterfaceW"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "WStr", DevicePath ; LPCWSTR
, "UInt", OpenFlags ; DWORD
, "Ptr", DeviceInterfaceData ; SP_DEVICE_INTERFACE_DATA* optional, in/out
, "Int") ; return: BOOL●SetupDiOpenDeviceInterfaceW(DeviceInfoSet, DevicePath, OpenFlags, DeviceInterfaceData) = DLL("SETUPAPI.dll", "bool SetupDiOpenDeviceInterfaceW(int, char*, dword, void*)")
# 呼び出し: SetupDiOpenDeviceInterfaceW(DeviceInfoSet, DevicePath, OpenFlags, DeviceInterfaceData)
# DeviceInfoSet : HDEVINFO -> "int"
# DevicePath : LPCWSTR -> "char*"
# OpenFlags : DWORD -> "dword"
# DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。