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

DiUninstallDriverW

関数
INFで指定したドライバーパッケージをアンインストールする。
DLLnewdev.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 10 以降

シグネチャ

// newdev.dll  (Unicode / -W)
#include <windows.h>

BOOL DiUninstallDriverW(
    HWND hwndParent,   // optional
    LPCWSTR InfPath,
    DIUNINSTALLDRIVER_FLAGS Flags,
    BOOL* NeedReboot   // optional
);

パラメーター

名前方向
hwndParentHWNDinoptional
InfPathLPCWSTRin
FlagsDIUNINSTALLDRIVER_FLAGSin
NeedRebootBOOL*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

// newdev.dll  (Unicode / -W)
#include <windows.h>

BOOL DiUninstallDriverW(
    HWND hwndParent,   // optional
    LPCWSTR InfPath,
    DIUNINSTALLDRIVER_FLAGS Flags,
    BOOL* NeedReboot   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("newdev.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool DiUninstallDriverW(
    IntPtr hwndParent,   // HWND optional
    [MarshalAs(UnmanagedType.LPWStr)] string InfPath,   // LPCWSTR
    uint Flags,   // DIUNINSTALLDRIVER_FLAGS
    IntPtr NeedReboot   // BOOL* optional, out
);
<DllImport("newdev.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DiUninstallDriverW(
    hwndParent As IntPtr,   ' HWND optional
    <MarshalAs(UnmanagedType.LPWStr)> InfPath As String,   ' LPCWSTR
    Flags As UInteger,   ' DIUNINSTALLDRIVER_FLAGS
    NeedReboot As IntPtr   ' BOOL* optional, out
) As Boolean
End Function
' hwndParent : HWND optional
' InfPath : LPCWSTR
' Flags : DIUNINSTALLDRIVER_FLAGS
' NeedReboot : BOOL* optional, out
Declare PtrSafe Function DiUninstallDriverW Lib "newdev" ( _
    ByVal hwndParent As LongPtr, _
    ByVal InfPath As LongPtr, _
    ByVal Flags As Long, _
    ByVal NeedReboot As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DiUninstallDriverW = ctypes.windll.newdev.DiUninstallDriverW
DiUninstallDriverW.restype = wintypes.BOOL
DiUninstallDriverW.argtypes = [
    wintypes.HANDLE,  # hwndParent : HWND optional
    wintypes.LPCWSTR,  # InfPath : LPCWSTR
    wintypes.DWORD,  # Flags : DIUNINSTALLDRIVER_FLAGS
    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')
DiUninstallDriverW = Fiddle::Function.new(
  lib['DiUninstallDriverW'],
  [
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND optional
    Fiddle::TYPE_VOIDP,  # InfPath : LPCWSTR
    -Fiddle::TYPE_INT,  # Flags : DIUNINSTALLDRIVER_FLAGS
    Fiddle::TYPE_VOIDP,  # NeedReboot : BOOL* optional, out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "newdev")]
extern "system" {
    fn DiUninstallDriverW(
        hwndParent: *mut core::ffi::c_void,  // HWND optional
        InfPath: *const u16,  // LPCWSTR
        Flags: u32,  // DIUNINSTALLDRIVER_FLAGS
        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", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool DiUninstallDriverW(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPWStr)] string InfPath, uint Flags, IntPtr NeedReboot);
"@
$api = Add-Type -MemberDefinition $sig -Name 'newdev_DiUninstallDriverW' -Namespace Win32 -PassThru
# $api::DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
#uselib "newdev.dll"
#func global DiUninstallDriverW "DiUninstallDriverW" wptr, wptr, wptr, wptr
; DiUninstallDriverW hwndParent, InfPath, Flags, NeedReboot   ; 戻り値は stat
; hwndParent : HWND optional -> "wptr"
; InfPath : LPCWSTR -> "wptr"
; Flags : DIUNINSTALLDRIVER_FLAGS -> "wptr"
; NeedReboot : BOOL* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "newdev.dll"
#cfunc global DiUninstallDriverW "DiUninstallDriverW" sptr, wstr, int, int
; res = DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
; hwndParent : HWND optional -> "sptr"
; InfPath : LPCWSTR -> "wstr"
; Flags : DIUNINSTALLDRIVER_FLAGS -> "int"
; NeedReboot : BOOL* optional, out -> "int"
; BOOL DiUninstallDriverW(HWND hwndParent, LPCWSTR InfPath, DIUNINSTALLDRIVER_FLAGS Flags, BOOL* NeedReboot)
#uselib "newdev.dll"
#cfunc global DiUninstallDriverW "DiUninstallDriverW" intptr, wstr, int, int
; res = DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
; hwndParent : HWND optional -> "intptr"
; InfPath : LPCWSTR -> "wstr"
; Flags : DIUNINSTALLDRIVER_FLAGS -> "int"
; NeedReboot : BOOL* optional, out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	newdev = windows.NewLazySystemDLL("newdev.dll")
	procDiUninstallDriverW = newdev.NewProc("DiUninstallDriverW")
)

// hwndParent (HWND optional), InfPath (LPCWSTR), Flags (DIUNINSTALLDRIVER_FLAGS), NeedReboot (BOOL* optional, out)
r1, _, err := procDiUninstallDriverW.Call(
	uintptr(hwndParent),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(InfPath))),
	uintptr(Flags),
	uintptr(NeedReboot),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function DiUninstallDriverW(
  hwndParent: THandle;   // HWND optional
  InfPath: PWideChar;   // LPCWSTR
  Flags: DWORD;   // DIUNINSTALLDRIVER_FLAGS
  NeedReboot: Pointer   // BOOL* optional, out
): BOOL; stdcall;
  external 'newdev.dll' name 'DiUninstallDriverW';
result := DllCall("newdev\DiUninstallDriverW"
    , "Ptr", hwndParent   ; HWND optional
    , "WStr", InfPath   ; LPCWSTR
    , "UInt", Flags   ; DIUNINSTALLDRIVER_FLAGS
    , "Ptr", NeedReboot   ; BOOL* optional, out
    , "Int")   ; return: BOOL
●DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot) = DLL("newdev.dll", "bool DiUninstallDriverW(void*, char*, dword, void*)")
# 呼び出し: DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
# hwndParent : HWND optional -> "void*"
# InfPath : LPCWSTR -> "char*"
# Flags : DIUNINSTALLDRIVER_FLAGS -> "dword"
# NeedReboot : BOOL* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。