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
DeviceInfoDataSP_DEVINFO_DATA*in
hwndParentHWNDinoptional
FlagsDIROLLBACKDRIVER_FLAGSin
NeedRebootBOOL*outoptional

戻り値の型: 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 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, 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, int
; 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 -> "int"
; ※出力/バッファ引数は 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, int
; 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 -> "int"
; ※出力/バッファ引数は 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)。