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

SetupDiSetSelectedDriverA

関数
デバイスに使用するドライバを選択設定する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupDiSetSelectedDriverA(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData,   // optional
    SP_DRVINFO_DATA_V2_A* DriverInfoData   // optional
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInfoDataSP_DEVINFO_DATA*inoutoptional
DriverInfoDataSP_DRVINFO_DATA_V2_A*inoutoptional

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

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

SetupDiSetSelectedDriverA = ctypes.windll.setupapi.SetupDiSetSelectedDriverA
SetupDiSetSelectedDriverA.restype = wintypes.BOOL
SetupDiSetSelectedDriverA.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    ctypes.c_void_p,  # DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
    ctypes.c_void_p,  # DriverInfoData : SP_DRVINFO_DATA_V2_A* optional, in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiSetSelectedDriverA = setupapi.NewProc("SetupDiSetSelectedDriverA")
)

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