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

DiUninstallDevice

関数
デバイスとそのドライバーをアンインストールする。
DLLnewdev.dll呼出規約winapiSetLastErrorあり対応OSWindows 7 以降

シグネチャ

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

BOOL DiUninstallDevice(
    HWND hwndParent,
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData,
    DWORD Flags,
    BOOL* NeedReboot   // optional
);

パラメーター

名前方向
hwndParentHWNDin
DeviceInfoSetHDEVINFOin
DeviceInfoDataSP_DEVINFO_DATA*in
FlagsDWORDin
NeedRebootBOOL*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

DiUninstallDevice = ctypes.windll.newdev.DiUninstallDevice
DiUninstallDevice.restype = wintypes.BOOL
DiUninstallDevice.argtypes = [
    wintypes.HANDLE,  # hwndParent : HWND
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    ctypes.c_void_p,  # DeviceInfoData : SP_DEVINFO_DATA*
    wintypes.DWORD,  # Flags : DWORD
    ctypes.c_void_p,  # NeedReboot : BOOL* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	newdev = windows.NewLazySystemDLL("newdev.dll")
	procDiUninstallDevice = newdev.NewProc("DiUninstallDevice")
)

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