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

DiRollbackDriver

関数
デバイスのドライバーを以前のバージョンへ戻す。
DLLnewdev.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

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

パラメーター

名前方向説明
DeviceInfoSetHDEVINFOin対象デバイスを含むデバイス情報セットのハンドル。SetupDiで取得したHDEVINFOを指定する。
DeviceInfoDataSP_DEVINFO_DATA*inドライバーを元に戻す対象デバイスを示すSP_DEVINFO_DATA構造体へのポインター。
hwndParentHWNDinoptional進捗やUIの親となるウィンドウハンドル。UI不要時はNULL指定可。
FlagsDIROLLBACKDRIVER_FLAGSinロールバック動作を制御するDIROLLBACKDRIVER_FLAGSフラグ。例外発生時のみ実行などを指定する。
NeedRebootBOOL*outoptional再起動が必要かを受け取るBOOLへのポインター。TRUEなら反映に再起動を要する。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL DiRollbackDriver(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData,
    HWND hwndParent,   // optional
    DIROLLBACKDRIVER_FLAGS Flags,
    BOOL* NeedReboot   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("newdev.dll", SetLastError = true, ExactSpelling = true)]
static extern bool DiRollbackDriver(
    IntPtr DeviceInfoSet,   // HDEVINFO
    IntPtr DeviceInfoData,   // SP_DEVINFO_DATA*
    IntPtr hwndParent,   // HWND optional
    uint Flags,   // DIROLLBACKDRIVER_FLAGS
    IntPtr NeedReboot   // BOOL* optional, out
);
<DllImport("newdev.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DiRollbackDriver(
    DeviceInfoSet As IntPtr,   ' HDEVINFO
    DeviceInfoData As IntPtr,   ' SP_DEVINFO_DATA*
    hwndParent As IntPtr,   ' HWND optional
    Flags As UInteger,   ' DIROLLBACKDRIVER_FLAGS
    NeedReboot As IntPtr   ' BOOL* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA*
' hwndParent : HWND optional
' Flags : DIROLLBACKDRIVER_FLAGS
' NeedReboot : BOOL* optional, out
Declare PtrSafe Function DiRollbackDriver Lib "newdev" ( _
    ByVal DeviceInfoSet As LongPtr, _
    ByVal DeviceInfoData As LongPtr, _
    ByVal hwndParent 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

DiRollbackDriver = ctypes.windll.newdev.DiRollbackDriver
DiRollbackDriver.restype = wintypes.BOOL
DiRollbackDriver.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    ctypes.c_void_p,  # DeviceInfoData : SP_DEVINFO_DATA*
    wintypes.HANDLE,  # hwndParent : HWND optional
    wintypes.DWORD,  # Flags : DIROLLBACKDRIVER_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')
DiRollbackDriver = Fiddle::Function.new(
  lib['DiRollbackDriver'],
  [
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO
    Fiddle::TYPE_VOIDP,  # DeviceInfoData : SP_DEVINFO_DATA*
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND optional
    -Fiddle::TYPE_INT,  # Flags : DIROLLBACKDRIVER_FLAGS
    Fiddle::TYPE_VOIDP,  # NeedReboot : BOOL* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "newdev")]
extern "system" {
    fn DiRollbackDriver(
        DeviceInfoSet: isize,  // HDEVINFO
        DeviceInfoData: *mut SP_DEVINFO_DATA,  // SP_DEVINFO_DATA*
        hwndParent: *mut core::ffi::c_void,  // HWND optional
        Flags: u32,  // DIROLLBACKDRIVER_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", SetLastError = true)]
public static extern bool DiRollbackDriver(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, IntPtr hwndParent, uint Flags, IntPtr NeedReboot);
"@
$api = Add-Type -MemberDefinition $sig -Name 'newdev_DiRollbackDriver' -Namespace Win32 -PassThru
# $api::DiRollbackDriver(DeviceInfoSet, DeviceInfoData, hwndParent, Flags, NeedReboot)
#uselib "newdev.dll"
#func global DiRollbackDriver "DiRollbackDriver" sptr, sptr, sptr, sptr, sptr
; DiRollbackDriver DeviceInfoSet, varptr(DeviceInfoData), hwndParent, Flags, varptr(NeedReboot)   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr"
; hwndParent : HWND optional -> "sptr"
; Flags : DIROLLBACKDRIVER_FLAGS -> "sptr"
; NeedReboot : BOOL* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "newdev.dll"
#cfunc global DiRollbackDriver "DiRollbackDriver" sptr, var, sptr, int, var
; res = DiRollbackDriver(DeviceInfoSet, DeviceInfoData, hwndParent, Flags, NeedReboot)
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "var"
; hwndParent : HWND optional -> "sptr"
; Flags : DIROLLBACKDRIVER_FLAGS -> "int"
; NeedReboot : BOOL* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL DiRollbackDriver(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, HWND hwndParent, DIROLLBACKDRIVER_FLAGS Flags, BOOL* NeedReboot)
#uselib "newdev.dll"
#cfunc global DiRollbackDriver "DiRollbackDriver" intptr, var, intptr, int, var
; res = DiRollbackDriver(DeviceInfoSet, DeviceInfoData, hwndParent, Flags, NeedReboot)
; DeviceInfoSet : HDEVINFO -> "intptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "var"
; hwndParent : HWND optional -> "intptr"
; Flags : DIROLLBACKDRIVER_FLAGS -> "int"
; NeedReboot : BOOL* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	newdev = windows.NewLazySystemDLL("newdev.dll")
	procDiRollbackDriver = newdev.NewProc("DiRollbackDriver")
)

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

extern "newdev" fn DiRollbackDriver(
    DeviceInfoSet: isize, // HDEVINFO
    DeviceInfoData: [*c]SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
    hwndParent: ?*anyopaque, // HWND optional
    Flags: u32, // DIROLLBACKDRIVER_FLAGS
    NeedReboot: [*c]i32 // BOOL* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc DiRollbackDriver(
    DeviceInfoSet: int,  # HDEVINFO
    DeviceInfoData: ptr SP_DEVINFO_DATA,  # SP_DEVINFO_DATA*
    hwndParent: pointer,  # HWND optional
    Flags: uint32,  # DIROLLBACKDRIVER_FLAGS
    NeedReboot: ptr int32  # BOOL* optional, out
): int32 {.importc: "DiRollbackDriver", stdcall, dynlib: "newdev.dll".}
pragma(lib, "newdev");
extern(Windows)
int DiRollbackDriver(
    ptrdiff_t DeviceInfoSet,   // HDEVINFO
    SP_DEVINFO_DATA* DeviceInfoData,   // SP_DEVINFO_DATA*
    void* hwndParent,   // HWND optional
    uint Flags,   // DIROLLBACKDRIVER_FLAGS
    int* NeedReboot   // BOOL* optional, out
);
ccall((:DiRollbackDriver, "newdev.dll"), stdcall, Int32,
      (Int, Ptr{SP_DEVINFO_DATA}, Ptr{Cvoid}, UInt32, Ptr{Int32}),
      DeviceInfoSet, DeviceInfoData, hwndParent, Flags, NeedReboot)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInfoData : SP_DEVINFO_DATA* -> Ptr{SP_DEVINFO_DATA}
# hwndParent : HWND optional -> Ptr{Cvoid}
# Flags : DIROLLBACKDRIVER_FLAGS -> UInt32
# NeedReboot : BOOL* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DiRollbackDriver(
    intptr_t DeviceInfoSet,
    void* DeviceInfoData,
    void* hwndParent,
    uint32_t Flags,
    int32_t* NeedReboot);
]]
local newdev = ffi.load("newdev")
-- newdev.DiRollbackDriver(DeviceInfoSet, DeviceInfoData, hwndParent, Flags, NeedReboot)
-- DeviceInfoSet : HDEVINFO
-- DeviceInfoData : SP_DEVINFO_DATA*
-- hwndParent : HWND optional
-- Flags : DIROLLBACKDRIVER_FLAGS
-- NeedReboot : BOOL* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('newdev.dll');
const DiRollbackDriver = lib.func('__stdcall', 'DiRollbackDriver', 'int32_t', ['intptr_t', 'void *', 'void *', 'uint32_t', 'int32_t *']);
// DiRollbackDriver(DeviceInfoSet, DeviceInfoData, hwndParent, Flags, NeedReboot)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* -> 'void *'
// hwndParent : HWND optional -> 'void *'
// Flags : DIROLLBACKDRIVER_FLAGS -> 'uint32_t'
// NeedReboot : BOOL* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("newdev.dll", {
  DiRollbackDriver: { parameters: ["isize", "pointer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.DiRollbackDriver(DeviceInfoSet, DeviceInfoData, hwndParent, Flags, NeedReboot)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* -> "pointer"
// hwndParent : HWND optional -> "pointer"
// Flags : DIROLLBACKDRIVER_FLAGS -> "u32"
// NeedReboot : BOOL* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DiRollbackDriver(
    intptr_t DeviceInfoSet,
    void* DeviceInfoData,
    void* hwndParent,
    uint32_t Flags,
    int32_t* NeedReboot);
C, "newdev.dll");
// $ffi->DiRollbackDriver(DeviceInfoSet, DeviceInfoData, hwndParent, Flags, NeedReboot);
// DeviceInfoSet : HDEVINFO
// DeviceInfoData : SP_DEVINFO_DATA*
// hwndParent : HWND optional
// Flags : DIROLLBACKDRIVER_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);
    boolean DiRollbackDriver(
        long DeviceInfoSet,   // HDEVINFO
        Pointer DeviceInfoData,   // SP_DEVINFO_DATA*
        Pointer hwndParent,   // HWND optional
        int Flags,   // DIROLLBACKDRIVER_FLAGS
        IntByReference NeedReboot   // BOOL* optional, out
    );
}
@[Link("newdev")]
lib Libnewdev
  fun DiRollbackDriver = DiRollbackDriver(
    DeviceInfoSet : LibC::SSizeT,   # HDEVINFO
    DeviceInfoData : SP_DEVINFO_DATA*,   # SP_DEVINFO_DATA*
    hwndParent : Void*,   # HWND optional
    Flags : UInt32,   # DIROLLBACKDRIVER_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 DiRollbackDriverNative = Int32 Function(IntPtr, Pointer<Void>, Pointer<Void>, Uint32, Pointer<Int32>);
typedef DiRollbackDriverDart = int Function(int, Pointer<Void>, Pointer<Void>, int, Pointer<Int32>);
final DiRollbackDriver = DynamicLibrary.open('newdev.dll')
    .lookupFunction<DiRollbackDriverNative, DiRollbackDriverDart>('DiRollbackDriver');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* -> Pointer<Void>
// hwndParent : HWND optional -> Pointer<Void>
// Flags : DIROLLBACKDRIVER_FLAGS -> Uint32
// NeedReboot : BOOL* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DiRollbackDriver(
  DeviceInfoSet: NativeInt;   // HDEVINFO
  DeviceInfoData: Pointer;   // SP_DEVINFO_DATA*
  hwndParent: THandle;   // HWND optional
  Flags: DWORD;   // DIROLLBACKDRIVER_FLAGS
  NeedReboot: Pointer   // BOOL* optional, out
): BOOL; stdcall;
  external 'newdev.dll' name 'DiRollbackDriver';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DiRollbackDriver"
  c_DiRollbackDriver :: CIntPtr -> Ptr () -> Ptr () -> Word32 -> Ptr CInt -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* -> Ptr ()
-- hwndParent : HWND optional -> Ptr ()
-- Flags : DIROLLBACKDRIVER_FLAGS -> Word32
-- NeedReboot : BOOL* optional, out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dirollbackdriver =
  foreign "DiRollbackDriver"
    (intptr_t @-> (ptr void) @-> (ptr void) @-> uint32_t @-> (ptr int32_t) @-> returning int32_t)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* -> (ptr void) *)
(* hwndParent : HWND optional -> (ptr void) *)
(* Flags : DIROLLBACKDRIVER_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 ("DiRollbackDriver" di-rollback-driver :convention :stdcall) :int32
  (device-info-set :int64)   ; HDEVINFO
  (device-info-data :pointer)   ; SP_DEVINFO_DATA*
  (hwnd-parent :pointer)   ; HWND optional
  (flags :uint32)   ; DIROLLBACKDRIVER_FLAGS
  (need-reboot :pointer))   ; BOOL* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DiRollbackDriver = Win32::API::More->new('newdev',
    'BOOL DiRollbackDriver(LPARAM DeviceInfoSet, LPVOID DeviceInfoData, HANDLE hwndParent, DWORD Flags, LPVOID NeedReboot)');
# my $ret = $DiRollbackDriver->Call($DeviceInfoSet, $DeviceInfoData, $hwndParent, $Flags, $NeedReboot);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* -> LPVOID
# hwndParent : HWND optional -> HANDLE
# Flags : DIROLLBACKDRIVER_FLAGS -> DWORD
# NeedReboot : BOOL* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型