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
);

パラメーター

名前方向説明
hwndParentHWNDinoptionalUIの親となるウィンドウハンドル。UI不要の場合はNULL可。
InfPathLPCWSTRinアンインストールするドライバーのINFファイルへのフルパス文字列(Unicode)。
FlagsDIUNINSTALLDRIVER_FLAGSinアンインストール動作を制御するDIUNINSTALLDRIVER_FLAGS。
NeedRebootBOOL*outoptional再起動が必要かどうかの真偽値を受け取る出力先ポインタ。NULL可。

戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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, varptr(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, var
; res = DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
; hwndParent : HWND optional -> "sptr"
; InfPath : LPCWSTR -> "wstr"
; Flags : DIUNINSTALLDRIVER_FLAGS -> "int"
; NeedReboot : BOOL* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL DiUninstallDriverW(HWND hwndParent, LPCWSTR InfPath, DIUNINSTALLDRIVER_FLAGS Flags, BOOL* NeedReboot)
#uselib "newdev.dll"
#cfunc global DiUninstallDriverW "DiUninstallDriverW" intptr, wstr, int, var
; res = DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
; hwndParent : HWND optional -> "intptr"
; InfPath : LPCWSTR -> "wstr"
; Flags : DIUNINSTALLDRIVER_FLAGS -> "int"
; NeedReboot : BOOL* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
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 版の利用を推奨。
const std = @import("std");

extern "newdev" fn DiUninstallDriverW(
    hwndParent: ?*anyopaque, // HWND optional
    InfPath: [*c]const u16, // LPCWSTR
    Flags: u32, // DIUNINSTALLDRIVER_FLAGS
    NeedReboot: [*c]i32 // BOOL* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc DiUninstallDriverW(
    hwndParent: pointer,  # HWND optional
    InfPath: WideCString,  # LPCWSTR
    Flags: uint32,  # DIUNINSTALLDRIVER_FLAGS
    NeedReboot: ptr int32  # BOOL* optional, out
): int32 {.importc: "DiUninstallDriverW", stdcall, dynlib: "newdev.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "newdev");
extern(Windows)
int DiUninstallDriverW(
    void* hwndParent,   // HWND optional
    const(wchar)* InfPath,   // LPCWSTR
    uint Flags,   // DIUNINSTALLDRIVER_FLAGS
    int* NeedReboot   // BOOL* optional, out
);
ccall((:DiUninstallDriverW, "newdev.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, UInt32, Ptr{Int32}),
      hwndParent, InfPath, Flags, NeedReboot)
# hwndParent : HWND optional -> Ptr{Cvoid}
# InfPath : LPCWSTR -> Cwstring
# Flags : DIUNINSTALLDRIVER_FLAGS -> UInt32
# NeedReboot : BOOL* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t DiUninstallDriverW(
    void* hwndParent,
    const uint16_t* InfPath,
    uint32_t Flags,
    int32_t* NeedReboot);
]]
local newdev = ffi.load("newdev")
-- newdev.DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
-- hwndParent : HWND optional
-- InfPath : LPCWSTR
-- Flags : DIUNINSTALLDRIVER_FLAGS
-- NeedReboot : BOOL* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('newdev.dll');
const DiUninstallDriverW = lib.func('__stdcall', 'DiUninstallDriverW', 'int32_t', ['void *', 'str16', 'uint32_t', 'int32_t *']);
// DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
// hwndParent : HWND optional -> 'void *'
// InfPath : LPCWSTR -> 'str16'
// Flags : DIUNINSTALLDRIVER_FLAGS -> 'uint32_t'
// NeedReboot : BOOL* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("newdev.dll", {
  DiUninstallDriverW: { parameters: ["pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
// hwndParent : HWND optional -> "pointer"
// InfPath : LPCWSTR -> "buffer"
// Flags : DIUNINSTALLDRIVER_FLAGS -> "u32"
// NeedReboot : BOOL* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DiUninstallDriverW(
    void* hwndParent,
    const uint16_t* InfPath,
    uint32_t Flags,
    int32_t* NeedReboot);
C, "newdev.dll");
// $ffi->DiUninstallDriverW(hwndParent, InfPath, Flags, NeedReboot);
// hwndParent : HWND optional
// InfPath : LPCWSTR
// Flags : DIUNINSTALLDRIVER_FLAGS
// NeedReboot : BOOL* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Newdev extends StdCallLibrary {
    Newdev INSTANCE = Native.load("newdev", Newdev.class, W32APIOptions.UNICODE_OPTIONS);
    boolean DiUninstallDriverW(
        Pointer hwndParent,   // HWND optional
        WString InfPath,   // LPCWSTR
        int Flags,   // DIUNINSTALLDRIVER_FLAGS
        IntByReference NeedReboot   // BOOL* optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("newdev")]
lib Libnewdev
  fun DiUninstallDriverW = DiUninstallDriverW(
    hwndParent : Void*,   # HWND optional
    InfPath : UInt16*,   # LPCWSTR
    Flags : UInt32,   # DIUNINSTALLDRIVER_FLAGS
    NeedReboot : Int32*   # BOOL* optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DiUninstallDriverWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Int32>);
typedef DiUninstallDriverWDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Int32>);
final DiUninstallDriverW = DynamicLibrary.open('newdev.dll')
    .lookupFunction<DiUninstallDriverWNative, DiUninstallDriverWDart>('DiUninstallDriverW');
// hwndParent : HWND optional -> Pointer<Void>
// InfPath : LPCWSTR -> Pointer<Utf16>
// Flags : DIUNINSTALLDRIVER_FLAGS -> Uint32
// NeedReboot : BOOL* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DiUninstallDriverW"
  c_DiUninstallDriverW :: Ptr () -> CWString -> Word32 -> Ptr CInt -> IO CInt
-- hwndParent : HWND optional -> Ptr ()
-- InfPath : LPCWSTR -> CWString
-- Flags : DIUNINSTALLDRIVER_FLAGS -> Word32
-- NeedReboot : BOOL* optional, out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let diuninstalldriverw =
  foreign "DiUninstallDriverW"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr int32_t) @-> returning int32_t)
(* hwndParent : HWND optional -> (ptr void) *)
(* InfPath : LPCWSTR -> (ptr uint16_t) *)
(* Flags : DIUNINSTALLDRIVER_FLAGS -> uint32_t *)
(* NeedReboot : BOOL* optional, out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library newdev (t "newdev.dll"))
(cffi:use-foreign-library newdev)

(cffi:defcfun ("DiUninstallDriverW" di-uninstall-driver-w :convention :stdcall) :int32
  (hwnd-parent :pointer)   ; HWND optional
  (inf-path (:string :encoding :utf-16le))   ; LPCWSTR
  (flags :uint32)   ; DIUNINSTALLDRIVER_FLAGS
  (need-reboot :pointer))   ; BOOL* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DiUninstallDriverW = Win32::API::More->new('newdev',
    'BOOL DiUninstallDriverW(HANDLE hwndParent, LPCWSTR InfPath, DWORD Flags, LPVOID NeedReboot)');
# my $ret = $DiUninstallDriverW->Call($hwndParent, $InfPath, $Flags, $NeedReboot);
# hwndParent : HWND optional -> HANDLE
# InfPath : LPCWSTR -> LPCWSTR
# Flags : DIUNINSTALLDRIVER_FLAGS -> DWORD
# NeedReboot : BOOL* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型