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