ホーム › Devices.DeviceAndDriverInstallation › SetupDiCreateDeviceInfoA
SetupDiCreateDeviceInfoA
関数デバイス情報セットに新しいデバイス情報要素を作成する。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiCreateDeviceInfoA(
HDEVINFO DeviceInfoSet,
LPCSTR DeviceName,
const GUID* ClassGuid,
LPCSTR DeviceDescription, // optional
HWND hwndParent, // optional
SETUP_DI_DEVICE_CREATION_FLAGS CreationFlags,
SP_DEVINFO_DATA* DeviceInfoData // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| DeviceInfoSet | HDEVINFO | in | 新しいデバイス情報要素を追加する対象のデバイス情報セット。 |
| DeviceName | LPCSTR | in | 作成するデバイスインスタンスのID/名前(ANSI)。 |
| ClassGuid | GUID* | in | デバイスのセットアップクラスGUIDへのポインタ。 |
| DeviceDescription | LPCSTR | inoptional | デバイスの説明文字列(ANSI)。NULL可。 |
| hwndParent | HWND | inoptional | UI表示時の親ウィンドウハンドル。NULL可。 |
| CreationFlags | SETUP_DI_DEVICE_CREATION_FLAGS | in | DICD_*系の作成動作を制御するフラグ。 |
| DeviceInfoData | SP_DEVINFO_DATA* | inoutoptional | 作成された要素情報を受け取るSP_DEVINFO_DATAへのポインタ(出力)。NULL可。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiCreateDeviceInfoA(
HDEVINFO DeviceInfoSet,
LPCSTR DeviceName,
const GUID* ClassGuid,
LPCSTR 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.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiCreateDeviceInfoA(
IntPtr DeviceInfoSet, // HDEVINFO
[MarshalAs(UnmanagedType.LPStr)] string DeviceName, // LPCSTR
ref Guid ClassGuid, // GUID*
[MarshalAs(UnmanagedType.LPStr)] string DeviceDescription, // LPCSTR 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.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiCreateDeviceInfoA(
DeviceInfoSet As IntPtr, ' HDEVINFO
<MarshalAs(UnmanagedType.LPStr)> DeviceName As String, ' LPCSTR
ByRef ClassGuid As Guid, ' GUID*
<MarshalAs(UnmanagedType.LPStr)> DeviceDescription As String, ' LPCSTR 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 : LPCSTR
' ClassGuid : GUID*
' DeviceDescription : LPCSTR optional
' hwndParent : HWND optional
' CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS
' DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
Declare PtrSafe Function SetupDiCreateDeviceInfoA Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceName As String, _
ByVal ClassGuid As LongPtr, _
ByVal DeviceDescription As String, _
ByVal hwndParent As LongPtr, _
ByVal CreationFlags As Long, _
ByVal DeviceInfoData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupDiCreateDeviceInfoA = ctypes.windll.setupapi.SetupDiCreateDeviceInfoA
SetupDiCreateDeviceInfoA.restype = wintypes.BOOL
SetupDiCreateDeviceInfoA.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
wintypes.LPCSTR, # DeviceName : LPCSTR
ctypes.c_void_p, # ClassGuid : GUID*
wintypes.LPCSTR, # DeviceDescription : LPCSTR 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')
SetupDiCreateDeviceInfoA = Fiddle::Function.new(
lib['SetupDiCreateDeviceInfoA'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceName : LPCSTR
Fiddle::TYPE_VOIDP, # ClassGuid : GUID*
Fiddle::TYPE_VOIDP, # DeviceDescription : LPCSTR 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)#[link(name = "setupapi")]
extern "system" {
fn SetupDiCreateDeviceInfoA(
DeviceInfoSet: isize, // HDEVINFO
DeviceName: *const u8, // LPCSTR
ClassGuid: *const GUID, // GUID*
DeviceDescription: *const u8, // LPCSTR 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.Ansi, SetLastError = true)]
public static extern bool SetupDiCreateDeviceInfoA(IntPtr DeviceInfoSet, [MarshalAs(UnmanagedType.LPStr)] string DeviceName, ref Guid ClassGuid, [MarshalAs(UnmanagedType.LPStr)] string DeviceDescription, IntPtr hwndParent, uint CreationFlags, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiCreateDeviceInfoA' -Namespace Win32 -PassThru
# $api::SetupDiCreateDeviceInfoA(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData)#uselib "SETUPAPI.dll"
#func global SetupDiCreateDeviceInfoA "SetupDiCreateDeviceInfoA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiCreateDeviceInfoA DeviceInfoSet, DeviceName, varptr(ClassGuid), DeviceDescription, hwndParent, CreationFlags, varptr(DeviceInfoData) ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceName : LPCSTR -> "sptr"
; ClassGuid : GUID* -> "sptr"
; DeviceDescription : LPCSTR optional -> "sptr"
; hwndParent : HWND optional -> "sptr"
; CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInfoA "SetupDiCreateDeviceInfoA" sptr, str, var, str, sptr, int, var ; res = SetupDiCreateDeviceInfoA(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceName : LPCSTR -> "str" ; ClassGuid : GUID* -> "var" ; DeviceDescription : LPCSTR optional -> "str" ; 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 SetupDiCreateDeviceInfoA "SetupDiCreateDeviceInfoA" sptr, str, sptr, str, sptr, int, sptr ; res = SetupDiCreateDeviceInfoA(DeviceInfoSet, DeviceName, varptr(ClassGuid), DeviceDescription, hwndParent, CreationFlags, varptr(DeviceInfoData)) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceName : LPCSTR -> "str" ; ClassGuid : GUID* -> "sptr" ; DeviceDescription : LPCSTR optional -> "str" ; hwndParent : HWND optional -> "sptr" ; CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "int" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, LPCSTR DeviceName, GUID* ClassGuid, LPCSTR DeviceDescription, HWND hwndParent, SETUP_DI_DEVICE_CREATION_FLAGS CreationFlags, SP_DEVINFO_DATA* DeviceInfoData) #uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInfoA "SetupDiCreateDeviceInfoA" intptr, str, var, str, intptr, int, var ; res = SetupDiCreateDeviceInfoA(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceName : LPCSTR -> "str" ; ClassGuid : GUID* -> "var" ; DeviceDescription : LPCSTR optional -> "str" ; hwndParent : HWND optional -> "intptr" ; CreationFlags : SETUP_DI_DEVICE_CREATION_FLAGS -> "int" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiCreateDeviceInfoA(HDEVINFO DeviceInfoSet, LPCSTR DeviceName, GUID* ClassGuid, LPCSTR DeviceDescription, HWND hwndParent, SETUP_DI_DEVICE_CREATION_FLAGS CreationFlags, SP_DEVINFO_DATA* DeviceInfoData) #uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInfoA "SetupDiCreateDeviceInfoA" intptr, str, intptr, str, intptr, int, intptr ; res = SetupDiCreateDeviceInfoA(DeviceInfoSet, DeviceName, varptr(ClassGuid), DeviceDescription, hwndParent, CreationFlags, varptr(DeviceInfoData)) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceName : LPCSTR -> "str" ; ClassGuid : GUID* -> "intptr" ; DeviceDescription : LPCSTR optional -> "str" ; 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")
procSetupDiCreateDeviceInfoA = setupapi.NewProc("SetupDiCreateDeviceInfoA")
)
// DeviceInfoSet (HDEVINFO), DeviceName (LPCSTR), ClassGuid (GUID*), DeviceDescription (LPCSTR optional), hwndParent (HWND optional), CreationFlags (SETUP_DI_DEVICE_CREATION_FLAGS), DeviceInfoData (SP_DEVINFO_DATA* optional, in/out)
r1, _, err := procSetupDiCreateDeviceInfoA.Call(
uintptr(DeviceInfoSet),
uintptr(unsafe.Pointer(windows.BytePtrFromString(DeviceName))),
uintptr(ClassGuid),
uintptr(unsafe.Pointer(windows.BytePtrFromString(DeviceDescription))),
uintptr(hwndParent),
uintptr(CreationFlags),
uintptr(DeviceInfoData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiCreateDeviceInfoA(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceName: PAnsiChar; // LPCSTR
ClassGuid: PGUID; // GUID*
DeviceDescription: PAnsiChar; // LPCSTR 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 'SetupDiCreateDeviceInfoA';result := DllCall("SETUPAPI\SetupDiCreateDeviceInfoA"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "AStr", DeviceName ; LPCSTR
, "Ptr", ClassGuid ; GUID*
, "AStr", DeviceDescription ; LPCSTR optional
, "Ptr", hwndParent ; HWND optional
, "UInt", CreationFlags ; SETUP_DI_DEVICE_CREATION_FLAGS
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA* optional, in/out
, "Int") ; return: BOOL●SetupDiCreateDeviceInfoA(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupDiCreateDeviceInfoA(int, char*, void*, char*, void*, dword, void*)")
# 呼び出し: SetupDiCreateDeviceInfoA(DeviceInfoSet, DeviceName, ClassGuid, DeviceDescription, hwndParent, CreationFlags, DeviceInfoData)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceName : LPCSTR -> "char*"
# ClassGuid : GUID* -> "void*"
# DeviceDescription : LPCSTR 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)。