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

DiInstallDriverW

関数
INFで指定したドライバーパッケージをインストールする。
DLLnewdev.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// newdev.dll  (Unicode / -W)
#include <windows.h>

BOOL DiInstallDriverW(
    HWND hwndParent,   // optional
    LPCWSTR InfPath,
    DIINSTALLDRIVER_FLAGS Flags,
    BOOL* NeedReboot   // optional
);

パラメーター

名前方向
hwndParentHWNDinoptional
InfPathLPCWSTRin
FlagsDIINSTALLDRIVER_FLAGSin
NeedRebootBOOL*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

// newdev.dll  (Unicode / -W)
#include <windows.h>

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

DiInstallDriverW = ctypes.windll.newdev.DiInstallDriverW
DiInstallDriverW.restype = wintypes.BOOL
DiInstallDriverW.argtypes = [
    wintypes.HANDLE,  # hwndParent : HWND optional
    wintypes.LPCWSTR,  # InfPath : LPCWSTR
    wintypes.DWORD,  # Flags : DIINSTALLDRIVER_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')
DiInstallDriverW = Fiddle::Function.new(
  lib['DiInstallDriverW'],
  [
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND optional
    Fiddle::TYPE_VOIDP,  # InfPath : LPCWSTR
    -Fiddle::TYPE_INT,  # Flags : DIINSTALLDRIVER_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 DiInstallDriverW(
        hwndParent: *mut core::ffi::c_void,  // HWND optional
        InfPath: *const u16,  // LPCWSTR
        Flags: u32,  // DIINSTALLDRIVER_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 DiInstallDriverW(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPWStr)] string InfPath, uint Flags, IntPtr NeedReboot);
"@
$api = Add-Type -MemberDefinition $sig -Name 'newdev_DiInstallDriverW' -Namespace Win32 -PassThru
# $api::DiInstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
#uselib "newdev.dll"
#func global DiInstallDriverW "DiInstallDriverW" wptr, wptr, wptr, wptr
; DiInstallDriverW hwndParent, InfPath, Flags, NeedReboot   ; 戻り値は stat
; hwndParent : HWND optional -> "wptr"
; InfPath : LPCWSTR -> "wptr"
; Flags : DIINSTALLDRIVER_FLAGS -> "wptr"
; NeedReboot : BOOL* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "newdev.dll"
#cfunc global DiInstallDriverW "DiInstallDriverW" sptr, wstr, int, int
; res = DiInstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
; hwndParent : HWND optional -> "sptr"
; InfPath : LPCWSTR -> "wstr"
; Flags : DIINSTALLDRIVER_FLAGS -> "int"
; NeedReboot : BOOL* optional, out -> "int"
; BOOL DiInstallDriverW(HWND hwndParent, LPCWSTR InfPath, DIINSTALLDRIVER_FLAGS Flags, BOOL* NeedReboot)
#uselib "newdev.dll"
#cfunc global DiInstallDriverW "DiInstallDriverW" intptr, wstr, int, int
; res = DiInstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
; hwndParent : HWND optional -> "intptr"
; InfPath : LPCWSTR -> "wstr"
; Flags : DIINSTALLDRIVER_FLAGS -> "int"
; NeedReboot : BOOL* optional, out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	newdev = windows.NewLazySystemDLL("newdev.dll")
	procDiInstallDriverW = newdev.NewProc("DiInstallDriverW")
)

// hwndParent (HWND optional), InfPath (LPCWSTR), Flags (DIINSTALLDRIVER_FLAGS), NeedReboot (BOOL* optional, out)
r1, _, err := procDiInstallDriverW.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 DiInstallDriverW(
  hwndParent: THandle;   // HWND optional
  InfPath: PWideChar;   // LPCWSTR
  Flags: DWORD;   // DIINSTALLDRIVER_FLAGS
  NeedReboot: Pointer   // BOOL* optional, out
): BOOL; stdcall;
  external 'newdev.dll' name 'DiInstallDriverW';
result := DllCall("newdev\DiInstallDriverW"
    , "Ptr", hwndParent   ; HWND optional
    , "WStr", InfPath   ; LPCWSTR
    , "UInt", Flags   ; DIINSTALLDRIVER_FLAGS
    , "Ptr", NeedReboot   ; BOOL* optional, out
    , "Int")   ; return: BOOL
●DiInstallDriverW(hwndParent, InfPath, Flags, NeedReboot) = DLL("newdev.dll", "bool DiInstallDriverW(void*, char*, dword, void*)")
# 呼び出し: DiInstallDriverW(hwndParent, InfPath, Flags, NeedReboot)
# hwndParent : HWND optional -> "void*"
# InfPath : LPCWSTR -> "char*"
# Flags : DIINSTALLDRIVER_FLAGS -> "dword"
# NeedReboot : BOOL* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。