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

DiUninstallDriverA

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

シグネチャ

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

BOOL DiUninstallDriverA(
    HWND hwndParent,   // optional
    LPCSTR InfPath,
    DIUNINSTALLDRIVER_FLAGS Flags,
    BOOL* NeedReboot   // optional
);

パラメーター

名前方向
hwndParentHWNDinoptional
InfPathLPCSTRin
FlagsDIUNINSTALLDRIVER_FLAGSin
NeedRebootBOOL*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL DiUninstallDriverA(
    HWND hwndParent,   // optional
    LPCSTR InfPath,
    DIUNINSTALLDRIVER_FLAGS Flags,
    BOOL* NeedReboot   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("newdev.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool DiUninstallDriverA(
    IntPtr hwndParent,   // HWND optional
    [MarshalAs(UnmanagedType.LPStr)] string InfPath,   // LPCSTR
    uint Flags,   // DIUNINSTALLDRIVER_FLAGS
    IntPtr NeedReboot   // BOOL* optional, out
);
<DllImport("newdev.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DiUninstallDriverA(
    hwndParent As IntPtr,   ' HWND optional
    <MarshalAs(UnmanagedType.LPStr)> InfPath As String,   ' LPCSTR
    Flags As UInteger,   ' DIUNINSTALLDRIVER_FLAGS
    NeedReboot As IntPtr   ' BOOL* optional, out
) As Boolean
End Function
' hwndParent : HWND optional
' InfPath : LPCSTR
' Flags : DIUNINSTALLDRIVER_FLAGS
' NeedReboot : BOOL* optional, out
Declare PtrSafe Function DiUninstallDriverA Lib "newdev" ( _
    ByVal hwndParent As LongPtr, _
    ByVal InfPath As String, _
    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

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

var (
	newdev = windows.NewLazySystemDLL("newdev.dll")
	procDiUninstallDriverA = newdev.NewProc("DiUninstallDriverA")
)

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