ホーム › Devices.DeviceAndDriverInstallation › DiUninstallDriverA
DiUninstallDriverA
関数INFで指定したドライバーパッケージをアンインストールする。
シグネチャ
// newdev.dll (ANSI / -A)
#include <windows.h>
BOOL DiUninstallDriverA(
HWND hwndParent, // optional
LPCSTR InfPath,
DIUNINSTALLDRIVER_FLAGS Flags,
BOOL* NeedReboot // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | inoptional | UIの親となるウィンドウハンドル。UI不要の場合はNULL可。 |
| InfPath | LPCSTR | in | アンインストールするドライバーのINFファイルへのフルパス文字列(ANSI)。 |
| Flags | DIUNINSTALLDRIVER_FLAGS | in | アンインストール動作を制御するDIUNINSTALLDRIVER_FLAGS。 |
| NeedReboot | BOOL* | outoptional | 再起動が必要かどうかの真偽値を受け取る出力先ポインタ。NULL可。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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, varptr(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, var ; res = DiUninstallDriverA(hwndParent, InfPath, Flags, NeedReboot) ; hwndParent : HWND optional -> "sptr" ; InfPath : LPCSTR -> "str" ; Flags : DIUNINSTALLDRIVER_FLAGS -> "int" ; NeedReboot : BOOL* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "newdev.dll" #cfunc global DiUninstallDriverA "DiUninstallDriverA" sptr, str, int, sptr ; res = DiUninstallDriverA(hwndParent, InfPath, Flags, varptr(NeedReboot)) ; hwndParent : HWND optional -> "sptr" ; InfPath : LPCSTR -> "str" ; Flags : DIUNINSTALLDRIVER_FLAGS -> "int" ; NeedReboot : BOOL* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL DiUninstallDriverA(HWND hwndParent, LPCSTR InfPath, DIUNINSTALLDRIVER_FLAGS Flags, BOOL* NeedReboot) #uselib "newdev.dll" #cfunc global DiUninstallDriverA "DiUninstallDriverA" intptr, str, int, var ; res = DiUninstallDriverA(hwndParent, InfPath, Flags, NeedReboot) ; hwndParent : HWND optional -> "intptr" ; InfPath : LPCSTR -> "str" ; Flags : DIUNINSTALLDRIVER_FLAGS -> "int" ; NeedReboot : BOOL* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL DiUninstallDriverA(HWND hwndParent, LPCSTR InfPath, DIUNINSTALLDRIVER_FLAGS Flags, BOOL* NeedReboot) #uselib "newdev.dll" #cfunc global DiUninstallDriverA "DiUninstallDriverA" intptr, str, int, intptr ; res = DiUninstallDriverA(hwndParent, InfPath, Flags, varptr(NeedReboot)) ; hwndParent : HWND optional -> "intptr" ; InfPath : LPCSTR -> "str" ; Flags : DIUNINSTALLDRIVER_FLAGS -> "int" ; NeedReboot : BOOL* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
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 // BOOLfunction 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)。const std = @import("std");
extern "newdev" fn DiUninstallDriverA(
hwndParent: ?*anyopaque, // HWND optional
InfPath: [*c]const u8, // LPCSTR
Flags: u32, // DIUNINSTALLDRIVER_FLAGS
NeedReboot: [*c]i32 // BOOL* optional, out
) callconv(std.os.windows.WINAPI) i32;proc DiUninstallDriverA(
hwndParent: pointer, # HWND optional
InfPath: cstring, # LPCSTR
Flags: uint32, # DIUNINSTALLDRIVER_FLAGS
NeedReboot: ptr int32 # BOOL* optional, out
): int32 {.importc: "DiUninstallDriverA", stdcall, dynlib: "newdev.dll".}pragma(lib, "newdev");
extern(Windows)
int DiUninstallDriverA(
void* hwndParent, // HWND optional
const(char)* InfPath, // LPCSTR
uint Flags, // DIUNINSTALLDRIVER_FLAGS
int* NeedReboot // BOOL* optional, out
);ccall((:DiUninstallDriverA, "newdev.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cstring, UInt32, Ptr{Int32}),
hwndParent, InfPath, Flags, NeedReboot)
# hwndParent : HWND optional -> Ptr{Cvoid}
# InfPath : LPCSTR -> Cstring
# Flags : DIUNINSTALLDRIVER_FLAGS -> UInt32
# NeedReboot : BOOL* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t DiUninstallDriverA(
void* hwndParent,
const char* InfPath,
uint32_t Flags,
int32_t* NeedReboot);
]]
local newdev = ffi.load("newdev")
-- newdev.DiUninstallDriverA(hwndParent, InfPath, Flags, NeedReboot)
-- hwndParent : HWND optional
-- InfPath : LPCSTR
-- Flags : DIUNINSTALLDRIVER_FLAGS
-- NeedReboot : BOOL* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('newdev.dll');
const DiUninstallDriverA = lib.func('__stdcall', 'DiUninstallDriverA', 'int32_t', ['void *', 'str', 'uint32_t', 'int32_t *']);
// DiUninstallDriverA(hwndParent, InfPath, Flags, NeedReboot)
// hwndParent : HWND optional -> 'void *'
// InfPath : LPCSTR -> 'str'
// Flags : DIUNINSTALLDRIVER_FLAGS -> 'uint32_t'
// NeedReboot : BOOL* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("newdev.dll", {
DiUninstallDriverA: { parameters: ["pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.DiUninstallDriverA(hwndParent, InfPath, Flags, NeedReboot)
// hwndParent : HWND optional -> "pointer"
// InfPath : LPCSTR -> "buffer"
// Flags : DIUNINSTALLDRIVER_FLAGS -> "u32"
// NeedReboot : BOOL* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t DiUninstallDriverA(
void* hwndParent,
const char* InfPath,
uint32_t Flags,
int32_t* NeedReboot);
C, "newdev.dll");
// $ffi->DiUninstallDriverA(hwndParent, InfPath, Flags, NeedReboot);
// hwndParent : HWND optional
// InfPath : LPCSTR
// 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.ASCII_OPTIONS);
boolean DiUninstallDriverA(
Pointer hwndParent, // HWND optional
String InfPath, // LPCSTR
int Flags, // DIUNINSTALLDRIVER_FLAGS
IntByReference NeedReboot // BOOL* optional, out
);
}@[Link("newdev")]
lib Libnewdev
fun DiUninstallDriverA = DiUninstallDriverA(
hwndParent : Void*, # HWND optional
InfPath : UInt8*, # LPCSTR
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 DiUninstallDriverANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Int32>);
typedef DiUninstallDriverADart = int Function(Pointer<Void>, Pointer<Utf8>, int, Pointer<Int32>);
final DiUninstallDriverA = DynamicLibrary.open('newdev.dll')
.lookupFunction<DiUninstallDriverANative, DiUninstallDriverADart>('DiUninstallDriverA');
// hwndParent : HWND optional -> Pointer<Void>
// InfPath : LPCSTR -> Pointer<Utf8>
// Flags : DIUNINSTALLDRIVER_FLAGS -> Uint32
// NeedReboot : BOOL* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DiUninstallDriverA"
c_DiUninstallDriverA :: Ptr () -> CString -> Word32 -> Ptr CInt -> IO CInt
-- hwndParent : HWND optional -> Ptr ()
-- InfPath : LPCSTR -> CString
-- Flags : DIUNINSTALLDRIVER_FLAGS -> Word32
-- NeedReboot : BOOL* optional, out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let diuninstalldrivera =
foreign "DiUninstallDriverA"
((ptr void) @-> string @-> uint32_t @-> (ptr int32_t) @-> returning int32_t)
(* hwndParent : HWND optional -> (ptr void) *)
(* InfPath : LPCSTR -> string *)
(* 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 ("DiUninstallDriverA" di-uninstall-driver-a :convention :stdcall) :int32
(hwnd-parent :pointer) ; HWND optional
(inf-path :string) ; LPCSTR
(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 $DiUninstallDriverA = Win32::API::More->new('newdev',
'BOOL DiUninstallDriverA(HANDLE hwndParent, LPCSTR InfPath, DWORD Flags, LPVOID NeedReboot)');
# my $ret = $DiUninstallDriverA->Call($hwndParent, $InfPath, $Flags, $NeedReboot);
# hwndParent : HWND optional -> HANDLE
# InfPath : LPCSTR -> LPCSTR
# Flags : DIUNINSTALLDRIVER_FLAGS -> DWORD
# NeedReboot : BOOL* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f DiUninstallDriverW (Unicode版) — INFで指定したドライバーパッケージをアンインストールする。