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

SetupDiRemoveDevice

関数
システムからデバイスを削除する。
DLLSETUPAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL SetupDiRemoveDevice(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInfoDataSP_DEVINFO_DATA*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiRemoveDevice(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", ExactSpelling = true)]
static extern bool SetupDiRemoveDevice(
    IntPtr DeviceInfoSet,   // HDEVINFO
    IntPtr DeviceInfoData   // SP_DEVINFO_DATA* in/out
);
<DllImport("SETUPAPI.dll", ExactSpelling:=True)>
Public Shared Function SetupDiRemoveDevice(
    DeviceInfoSet As IntPtr,   ' HDEVINFO
    DeviceInfoData As IntPtr   ' SP_DEVINFO_DATA* in/out
) As Boolean
End Function
' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA* in/out
Declare PtrSafe Function SetupDiRemoveDevice 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

SetupDiRemoveDevice = ctypes.windll.setupapi.SetupDiRemoveDevice
SetupDiRemoveDevice.restype = wintypes.BOOL
SetupDiRemoveDevice.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    ctypes.c_void_p,  # DeviceInfoData : SP_DEVINFO_DATA* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiRemoveDevice = Fiddle::Function.new(
  lib['SetupDiRemoveDevice'],
  [
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO
    Fiddle::TYPE_VOIDP,  # DeviceInfoData : SP_DEVINFO_DATA* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiRemoveDevice(
        DeviceInfoSet: isize,  // HDEVINFO
        DeviceInfoData: *mut SP_DEVINFO_DATA  // SP_DEVINFO_DATA* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll")]
public static extern bool SetupDiRemoveDevice(IntPtr DeviceInfoSet, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiRemoveDevice' -Namespace Win32 -PassThru
# $api::SetupDiRemoveDevice(DeviceInfoSet, DeviceInfoData)
#uselib "SETUPAPI.dll"
#func global SetupDiRemoveDevice "SetupDiRemoveDevice" sptr, sptr
; SetupDiRemoveDevice DeviceInfoSet, varptr(DeviceInfoData)   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiRemoveDevice "SetupDiRemoveDevice" sptr, var
; res = SetupDiRemoveDevice(DeviceInfoSet, DeviceInfoData)
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiRemoveDevice(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiRemoveDevice "SetupDiRemoveDevice" intptr, var
; res = SetupDiRemoveDevice(DeviceInfoSet, DeviceInfoData)
; DeviceInfoSet : HDEVINFO -> "intptr"
; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiRemoveDevice = setupapi.NewProc("SetupDiRemoveDevice")
)

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