Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupDiSelectDevice

SetupDiSelectDevice

関数
デバイス選択用の既定動作を実行しドライバを選ぶ。
DLLSETUPAPI.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetupDiSelectDevice(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInfoDataSP_DEVINFO_DATA*inoutoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiSelectDevice(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiSelectDevice(
    IntPtr DeviceInfoSet,   // HDEVINFO
    IntPtr DeviceInfoData   // SP_DEVINFO_DATA* optional, in/out
);
<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiSelectDevice(
    DeviceInfoSet As IntPtr,   ' HDEVINFO
    DeviceInfoData As IntPtr   ' SP_DEVINFO_DATA* optional, in/out
) As Boolean
End Function
' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
Declare PtrSafe Function SetupDiSelectDevice Lib "setupapi" ( _
    ByVal DeviceInfoSet As LongPtr, _
    ByVal DeviceInfoData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiSelectDevice = ctypes.windll.setupapi.SetupDiSelectDevice
SetupDiSelectDevice.restype = wintypes.BOOL
SetupDiSelectDevice.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    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')
SetupDiSelectDevice = Fiddle::Function.new(
  lib['SetupDiSelectDevice'],
  [
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO
    Fiddle::TYPE_VOIDP,  # DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiSelectDevice(
        DeviceInfoSet: isize,  // HDEVINFO
        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", SetLastError = true)]
public static extern bool SetupDiSelectDevice(IntPtr DeviceInfoSet, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiSelectDevice' -Namespace Win32 -PassThru
# $api::SetupDiSelectDevice(DeviceInfoSet, DeviceInfoData)
#uselib "SETUPAPI.dll"
#func global SetupDiSelectDevice "SetupDiSelectDevice" sptr, sptr
; SetupDiSelectDevice DeviceInfoSet, varptr(DeviceInfoData)   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSelectDevice "SetupDiSelectDevice" sptr, var
; res = SetupDiSelectDevice(DeviceInfoSet, DeviceInfoData)
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiSelectDevice(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSelectDevice "SetupDiSelectDevice" intptr, var
; res = SetupDiSelectDevice(DeviceInfoSet, DeviceInfoData)
; DeviceInfoSet : HDEVINFO -> "intptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiSelectDevice = setupapi.NewProc("SetupDiSelectDevice")
)

// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA* optional, in/out)
r1, _, err := procSetupDiSelectDevice.Call(
	uintptr(DeviceInfoSet),
	uintptr(DeviceInfoData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiSelectDevice(
  DeviceInfoSet: NativeInt;   // HDEVINFO
  DeviceInfoData: Pointer   // SP_DEVINFO_DATA* optional, in/out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiSelectDevice';
result := DllCall("SETUPAPI\SetupDiSelectDevice"
    , "Ptr", DeviceInfoSet   ; HDEVINFO
    , "Ptr", DeviceInfoData   ; SP_DEVINFO_DATA* optional, in/out
    , "Int")   ; return: BOOL
●SetupDiSelectDevice(DeviceInfoSet, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupDiSelectDevice(int, void*)")
# 呼び出し: SetupDiSelectDevice(DeviceInfoSet, DeviceInfoData)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。