ホーム › Devices.DeviceAndDriverInstallation › SetupDiCreateDeviceInfoW
SetupDiCreateDeviceInfoW
関数デバイス情報セットに新しいデバイス情報要素を作成する。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupDiCreateDeviceInfoW(
HDEVINFO DeviceInfoSet,
LPCWSTR DeviceName,
const GUID* ClassGuid,
LPCWSTR DeviceDescription, // optional
HWND hwndParent, // optional
SETUP_DI_DEVICE_CREATION_FLAGS CreationFlags,
SP_DEVINFO_DATA* DeviceInfoData // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| DeviceInfoSet | HDEVINFO | in |
| DeviceName | LPCWSTR | in |
| ClassGuid | GUID* | in |
| DeviceDescription | LPCWSTR | inoptional |
| hwndParent | HWND | inoptional |
| CreationFlags | SETUP_DI_DEVICE_CREATION_FLAGS | in |
| DeviceInfoData | SP_DEVINFO_DATA* | inoutoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupDiCreateDeviceInfoW(
HDEVINFO DeviceInfoSet,
LPCWSTR DeviceName,
const GUID* ClassGuid,
LPCWSTR DeviceDescription, // optional
HWND hwndParent, // optional
SETUP_DI_DEVICE_CREATION_FLAGS CreationFlags,
SP_DEVINFO_DATA* DeviceInfoData // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiCreateDeviceInfoW(
IntPtr DeviceInfoSet, // HDEVINFO
[MarshalAs(UnmanagedType.LPWStr)] string DeviceName, // LPCWSTR
ref Guid ClassGuid, // GUID*
[MarshalAs(UnmanagedType.LPWStr)] string DeviceDescription, // LPCWSTR optional
IntPtr hwndParent, // HWND optional
uint CreationFlags, // SETUP_DI_DEVICE_CREATION_FLAGS
IntPtr DeviceInfoData // SP_DEVINFO_DATA* optional, in/out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiCreateDeviceInfoW(
DeviceInfoSet As IntPtr, ' HDEVINFO
<MarshalAs(UnmanagedType.LPWStr)> DeviceName As String, ' LPCWSTR
ByRef ClassGuid As Guid, ' GUID*
<MarshalAs(UnmanagedType.LPWStr)> DeviceDescription As String, ' LPCWSTR optional
hwndParent As IntPtr, ' HWND optional
CreationFlags As UInteger, ' SETUP_DI_DEVICE_CREATION_FLAGS
DeviceInfoData As IntPtr ' SP_DEVINFO_DATA* optional, in/out
) As Boolean
End Function' DeviceInfoSet : HDEVINFO
' DeviceName : LPCWSTR
' ClassGuid : GUID*
' DeviceDescription : LPCWSTR optional
' hwndParent : HWND optional
' CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS
' DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
Declare PtrSafe Function SetupDiCreateDeviceInfoW Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceName As LongPtr, _
ByVal ClassGuid As LongPtr, _
ByVal DeviceDescription As LongPtr, _
ByVal hwndParent As LongPtr, _
ByVal CreationFlags As Long, _
ByVal DeviceInfoData 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
SetupDiCreateDeviceInfoW = ctypes.windll.setupapi.SetupDiCreateDeviceInfoW
SetupDiCreateDeviceInfoW.restype = wintypes.BOOL
SetupDiCreateDeviceInfoW.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
wintypes.LPCWSTR, # DeviceName : LPCWSTR
ctypes.c_void_p, # ClassGuid : GUID*
wintypes.LPCWSTR, # DeviceDescription : LPCWSTR optional
wintypes.HANDLE, # hwndParent : HWND optional
wintypes.DWORD, # CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_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')
SetupDiCreateDeviceInfoW = Fiddle::Function.new(
lib['SetupDiCreateDeviceInfoW'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceName : LPCWSTR
Fiddle::TYPE_VOIDP, # ClassGuid : GUID*
Fiddle::TYPE_VOIDP, # DeviceDescription : LPCWSTR optional
Fiddle::TYPE_VOIDP, # hwndParent : HWND optional
-Fiddle::TYPE_INT, # CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupDiCreateDeviceInfoW(
DeviceInfoSet: isize, // HDEVINFO
DeviceName: *const u16, // LPCWSTR
ClassGuid: *const GUID, // GUID*
DeviceDescription: *const u16, // LPCWSTR optional
hwndParent: *mut core::ffi::c_void, // HWND optional
CreationFlags: u32, // SETUP_DI_DEVICE_CREATION_FLAGS
DeviceInfoData: *mut SP_DEVINFO_DATA // SP_DEVINFO_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 SetupDiCreateDeviceInfoW(IntPtr DeviceInfoSet, [MarshalAs(UnmanagedType.LPWStr)] string DeviceName, ref Guid ClassGuid, [MarshalAs(UnmanagedType.LPWStr)] string DeviceDescription, IntPtr hwndParent, uint CreationFlags, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiCreateDeviceInfoW' -Namespace Win32 -PassThru
# $api::SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData)#uselib "SETUPAPI.dll"
#func global SetupDiCreateDeviceInfoW "SetupDiCreateDeviceInfoW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiCreateDeviceInfoW DeviceInfoSet, DeviceName, varptr(ClassGuid), DeviceDescription, hwndParent, CreationFlags, varptr(DeviceInfoData) ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "wptr"
; DeviceName : LPCWSTR -> "wptr"
; ClassGuid : GUID* -> "wptr"
; DeviceDescription : LPCWSTR optional -> "wptr"
; hwndParent : HWND optional -> "wptr"
; CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "wptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInfoW "SetupDiCreateDeviceInfoW" sptr, wstr, var, wstr, sptr, int, var ; res = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceName : LPCWSTR -> "wstr" ; ClassGuid : GUID* -> "var" ; DeviceDescription : LPCWSTR optional -> "wstr" ; hwndParent : HWND optional -> "sptr" ; CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "int" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInfoW "SetupDiCreateDeviceInfoW" sptr, wstr, sptr, wstr, sptr, int, sptr ; res = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceName, varptr(ClassGuid), DeviceDescription, hwndParent, CreationFlags, varptr(DeviceInfoData)) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceName : LPCWSTR -> "wstr" ; ClassGuid : GUID* -> "sptr" ; DeviceDescription : LPCWSTR optional -> "wstr" ; hwndParent : HWND optional -> "sptr" ; CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "int" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupDiCreateDeviceInfoW(HDEVINFO DeviceInfoSet, LPCWSTR DeviceName, GUID* ClassGuid, LPCWSTR DeviceDescription, HWND hwndParent, SETUP_DI_DEVICE_CREATION_FLAGS CreationFlags, SP_DEVINFO_DATA* DeviceInfoData) #uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInfoW "SetupDiCreateDeviceInfoW" intptr, wstr, var, wstr, intptr, int, var ; res = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceName : LPCWSTR -> "wstr" ; ClassGuid : GUID* -> "var" ; DeviceDescription : LPCWSTR optional -> "wstr" ; hwndParent : HWND optional -> "intptr" ; CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "int" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiCreateDeviceInfoW(HDEVINFO DeviceInfoSet, LPCWSTR DeviceName, GUID* ClassGuid, LPCWSTR DeviceDescription, HWND hwndParent, SETUP_DI_DEVICE_CREATION_FLAGS CreationFlags, SP_DEVINFO_DATA* DeviceInfoData) #uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInfoW "SetupDiCreateDeviceInfoW" intptr, wstr, intptr, wstr, intptr, int, intptr ; res = SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceName, varptr(ClassGuid), DeviceDescription, hwndParent, CreationFlags, varptr(DeviceInfoData)) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceName : LPCWSTR -> "wstr" ; ClassGuid : GUID* -> "intptr" ; DeviceDescription : LPCWSTR optional -> "wstr" ; hwndParent : HWND optional -> "intptr" ; CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "int" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiCreateDeviceInfoW = setupapi.NewProc("SetupDiCreateDeviceInfoW")
)
// DeviceInfoSet (HDEVINFO), DeviceName (LPCWSTR), ClassGuid (GUID*), DeviceDescription (LPCWSTR optional), hwndParent (HWND optional), CreationFlags (SETUP_DI_DEVICE_CREATION_FLAGS), DeviceInfoData (SP_DEVINFO_DATA* optional, in/out)
r1, _, err := procSetupDiCreateDeviceInfoW.Call(
uintptr(DeviceInfoSet),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DeviceName))),
uintptr(ClassGuid),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DeviceDescription))),
uintptr(hwndParent),
uintptr(CreationFlags),
uintptr(DeviceInfoData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiCreateDeviceInfoW(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceName: PWideChar; // LPCWSTR
ClassGuid: PGUID; // GUID*
DeviceDescription: PWideChar; // LPCWSTR optional
hwndParent: THandle; // HWND optional
CreationFlags: DWORD; // SETUP_DI_DEVICE_CREATION_FLAGS
DeviceInfoData: Pointer // SP_DEVINFO_DATA* optional, in/out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiCreateDeviceInfoW';result := DllCall("SETUPAPI\SetupDiCreateDeviceInfoW"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "WStr", DeviceName ; LPCWSTR
, "Ptr", ClassGuid ; GUID*
, "WStr", DeviceDescription ; LPCWSTR optional
, "Ptr", hwndParent ; HWND optional
, "UInt", CreationFlags ; SETUP_DI_DEVICE_CREATION_FLAGS
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA* optional, in/out
, "Int") ; return: BOOL●SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupDiCreateDeviceInfoW(int, char*, void*, char*, void*, dword, void*)")
# 呼び出し: SetupDiCreateDeviceInfoW(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceName : LPCWSTR -> "char*"
# ClassGuid : GUID* -> "void*"
# DeviceDescription : LPCWSTR optional -> "char*"
# hwndParent : HWND optional -> "void*"
# CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "dword"
# DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。