ホーム › Devices.DeviceAndDriverInstallation › UpdateDriverForPlugAndPlayDevicesW
UpdateDriverForPlugAndPlayDevicesW
関数指定ハードウェアIDのデバイスのドライバーを更新する。
シグネチャ
// newdev.dll (Unicode / -W)
#include <windows.h>
BOOL UpdateDriverForPlugAndPlayDevicesW(
HWND hwndParent, // optional
LPCWSTR HardwareId,
LPCWSTR FullInfPath,
UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS InstallFlags,
BOOL* bRebootRequired // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | inoptional | UIの親となるウィンドウハンドル。UI不要の場合はNULL可。 |
| HardwareId | LPCWSTR | in | 更新対象を特定するハードウェアID文字列(Unicode)。 |
| FullInfPath | LPCWSTR | in | 適用するINFファイルへのフルパス文字列(Unicode)。 |
| InstallFlags | UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS | in | インストール動作を制御するフラグ(INSTALLFLAG_FORCE/READONLY/NONINTERACTIVE)。 |
| bRebootRequired | BOOL* | outoptional | 再起動が必要かどうかの真偽値を受け取る出力先ポインタ。NULL可。 |
戻り値の型: BOOL
各言語での呼び出し定義
// newdev.dll (Unicode / -W)
#include <windows.h>
BOOL UpdateDriverForPlugAndPlayDevicesW(
HWND hwndParent, // optional
LPCWSTR HardwareId,
LPCWSTR FullInfPath,
UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS InstallFlags,
BOOL* bRebootRequired // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("newdev.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool UpdateDriverForPlugAndPlayDevicesW(
IntPtr hwndParent, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] string HardwareId, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string FullInfPath, // LPCWSTR
uint InstallFlags, // UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
IntPtr bRebootRequired // BOOL* optional, out
);<DllImport("newdev.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function UpdateDriverForPlugAndPlayDevicesW(
hwndParent As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> HardwareId As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> FullInfPath As String, ' LPCWSTR
InstallFlags As UInteger, ' UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
bRebootRequired As IntPtr ' BOOL* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hwndParent : HWND optional
' HardwareId : LPCWSTR
' FullInfPath : LPCWSTR
' InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
' bRebootRequired : BOOL* optional, out
Declare PtrSafe Function UpdateDriverForPlugAndPlayDevicesW Lib "newdev" ( _
ByVal hwndParent As LongPtr, _
ByVal HardwareId As LongPtr, _
ByVal FullInfPath As LongPtr, _
ByVal InstallFlags As Long, _
ByVal bRebootRequired 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
UpdateDriverForPlugAndPlayDevicesW = ctypes.windll.newdev.UpdateDriverForPlugAndPlayDevicesW
UpdateDriverForPlugAndPlayDevicesW.restype = wintypes.BOOL
UpdateDriverForPlugAndPlayDevicesW.argtypes = [
wintypes.HANDLE, # hwndParent : HWND optional
wintypes.LPCWSTR, # HardwareId : LPCWSTR
wintypes.LPCWSTR, # FullInfPath : LPCWSTR
wintypes.DWORD, # InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
ctypes.c_void_p, # bRebootRequired : BOOL* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('newdev.dll')
UpdateDriverForPlugAndPlayDevicesW = Fiddle::Function.new(
lib['UpdateDriverForPlugAndPlayDevicesW'],
[
Fiddle::TYPE_VOIDP, # hwndParent : HWND optional
Fiddle::TYPE_VOIDP, # HardwareId : LPCWSTR
Fiddle::TYPE_VOIDP, # FullInfPath : LPCWSTR
-Fiddle::TYPE_INT, # InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
Fiddle::TYPE_VOIDP, # bRebootRequired : BOOL* optional, out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "newdev")]
extern "system" {
fn UpdateDriverForPlugAndPlayDevicesW(
hwndParent: *mut core::ffi::c_void, // HWND optional
HardwareId: *const u16, // LPCWSTR
FullInfPath: *const u16, // LPCWSTR
InstallFlags: u32, // UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
bRebootRequired: *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 UpdateDriverForPlugAndPlayDevicesW(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPWStr)] string HardwareId, [MarshalAs(UnmanagedType.LPWStr)] string FullInfPath, uint InstallFlags, IntPtr bRebootRequired);
"@
$api = Add-Type -MemberDefinition $sig -Name 'newdev_UpdateDriverForPlugAndPlayDevicesW' -Namespace Win32 -PassThru
# $api::UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired)#uselib "newdev.dll"
#func global UpdateDriverForPlugAndPlayDevicesW "UpdateDriverForPlugAndPlayDevicesW" wptr, wptr, wptr, wptr, wptr
; UpdateDriverForPlugAndPlayDevicesW hwndParent, HardwareId, FullInfPath, InstallFlags, varptr(bRebootRequired) ; 戻り値は stat
; hwndParent : HWND optional -> "wptr"
; HardwareId : LPCWSTR -> "wptr"
; FullInfPath : LPCWSTR -> "wptr"
; InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> "wptr"
; bRebootRequired : BOOL* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "newdev.dll" #cfunc global UpdateDriverForPlugAndPlayDevicesW "UpdateDriverForPlugAndPlayDevicesW" sptr, wstr, wstr, int, var ; res = UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired) ; hwndParent : HWND optional -> "sptr" ; HardwareId : LPCWSTR -> "wstr" ; FullInfPath : LPCWSTR -> "wstr" ; InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> "int" ; bRebootRequired : BOOL* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "newdev.dll" #cfunc global UpdateDriverForPlugAndPlayDevicesW "UpdateDriverForPlugAndPlayDevicesW" sptr, wstr, wstr, int, sptr ; res = UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, varptr(bRebootRequired)) ; hwndParent : HWND optional -> "sptr" ; HardwareId : LPCWSTR -> "wstr" ; FullInfPath : LPCWSTR -> "wstr" ; InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> "int" ; bRebootRequired : BOOL* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL UpdateDriverForPlugAndPlayDevicesW(HWND hwndParent, LPCWSTR HardwareId, LPCWSTR FullInfPath, UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS InstallFlags, BOOL* bRebootRequired) #uselib "newdev.dll" #cfunc global UpdateDriverForPlugAndPlayDevicesW "UpdateDriverForPlugAndPlayDevicesW" intptr, wstr, wstr, int, var ; res = UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired) ; hwndParent : HWND optional -> "intptr" ; HardwareId : LPCWSTR -> "wstr" ; FullInfPath : LPCWSTR -> "wstr" ; InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> "int" ; bRebootRequired : BOOL* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL UpdateDriverForPlugAndPlayDevicesW(HWND hwndParent, LPCWSTR HardwareId, LPCWSTR FullInfPath, UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS InstallFlags, BOOL* bRebootRequired) #uselib "newdev.dll" #cfunc global UpdateDriverForPlugAndPlayDevicesW "UpdateDriverForPlugAndPlayDevicesW" intptr, wstr, wstr, int, intptr ; res = UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, varptr(bRebootRequired)) ; hwndParent : HWND optional -> "intptr" ; HardwareId : LPCWSTR -> "wstr" ; FullInfPath : LPCWSTR -> "wstr" ; InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> "int" ; bRebootRequired : BOOL* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
newdev = windows.NewLazySystemDLL("newdev.dll")
procUpdateDriverForPlugAndPlayDevicesW = newdev.NewProc("UpdateDriverForPlugAndPlayDevicesW")
)
// hwndParent (HWND optional), HardwareId (LPCWSTR), FullInfPath (LPCWSTR), InstallFlags (UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS), bRebootRequired (BOOL* optional, out)
r1, _, err := procUpdateDriverForPlugAndPlayDevicesW.Call(
uintptr(hwndParent),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(HardwareId))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FullInfPath))),
uintptr(InstallFlags),
uintptr(bRebootRequired),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction UpdateDriverForPlugAndPlayDevicesW(
hwndParent: THandle; // HWND optional
HardwareId: PWideChar; // LPCWSTR
FullInfPath: PWideChar; // LPCWSTR
InstallFlags: DWORD; // UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
bRebootRequired: Pointer // BOOL* optional, out
): BOOL; stdcall;
external 'newdev.dll' name 'UpdateDriverForPlugAndPlayDevicesW';result := DllCall("newdev\UpdateDriverForPlugAndPlayDevicesW"
, "Ptr", hwndParent ; HWND optional
, "WStr", HardwareId ; LPCWSTR
, "WStr", FullInfPath ; LPCWSTR
, "UInt", InstallFlags ; UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
, "Ptr", bRebootRequired ; BOOL* optional, out
, "Int") ; return: BOOL●UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired) = DLL("newdev.dll", "bool UpdateDriverForPlugAndPlayDevicesW(void*, char*, char*, dword, void*)")
# 呼び出し: UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired)
# hwndParent : HWND optional -> "void*"
# HardwareId : LPCWSTR -> "char*"
# FullInfPath : LPCWSTR -> "char*"
# InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> "dword"
# bRebootRequired : 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 UpdateDriverForPlugAndPlayDevicesW(
hwndParent: ?*anyopaque, // HWND optional
HardwareId: [*c]const u16, // LPCWSTR
FullInfPath: [*c]const u16, // LPCWSTR
InstallFlags: u32, // UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
bRebootRequired: [*c]i32 // BOOL* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc UpdateDriverForPlugAndPlayDevicesW(
hwndParent: pointer, # HWND optional
HardwareId: WideCString, # LPCWSTR
FullInfPath: WideCString, # LPCWSTR
InstallFlags: uint32, # UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
bRebootRequired: ptr int32 # BOOL* optional, out
): int32 {.importc: "UpdateDriverForPlugAndPlayDevicesW", stdcall, dynlib: "newdev.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "newdev");
extern(Windows)
int UpdateDriverForPlugAndPlayDevicesW(
void* hwndParent, // HWND optional
const(wchar)* HardwareId, // LPCWSTR
const(wchar)* FullInfPath, // LPCWSTR
uint InstallFlags, // UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
int* bRebootRequired // BOOL* optional, out
);ccall((:UpdateDriverForPlugAndPlayDevicesW, "newdev.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Cwstring, UInt32, Ptr{Int32}),
hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired)
# hwndParent : HWND optional -> Ptr{Cvoid}
# HardwareId : LPCWSTR -> Cwstring
# FullInfPath : LPCWSTR -> Cwstring
# InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> UInt32
# bRebootRequired : BOOL* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t UpdateDriverForPlugAndPlayDevicesW(
void* hwndParent,
const uint16_t* HardwareId,
const uint16_t* FullInfPath,
uint32_t InstallFlags,
int32_t* bRebootRequired);
]]
local newdev = ffi.load("newdev")
-- newdev.UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired)
-- hwndParent : HWND optional
-- HardwareId : LPCWSTR
-- FullInfPath : LPCWSTR
-- InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
-- bRebootRequired : 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 UpdateDriverForPlugAndPlayDevicesW = lib.func('__stdcall', 'UpdateDriverForPlugAndPlayDevicesW', 'int32_t', ['void *', 'str16', 'str16', 'uint32_t', 'int32_t *']);
// UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired)
// hwndParent : HWND optional -> 'void *'
// HardwareId : LPCWSTR -> 'str16'
// FullInfPath : LPCWSTR -> 'str16'
// InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> 'uint32_t'
// bRebootRequired : BOOL* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("newdev.dll", {
UpdateDriverForPlugAndPlayDevicesW: { parameters: ["pointer", "buffer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired)
// hwndParent : HWND optional -> "pointer"
// HardwareId : LPCWSTR -> "buffer"
// FullInfPath : LPCWSTR -> "buffer"
// InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> "u32"
// bRebootRequired : BOOL* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t UpdateDriverForPlugAndPlayDevicesW(
void* hwndParent,
const uint16_t* HardwareId,
const uint16_t* FullInfPath,
uint32_t InstallFlags,
int32_t* bRebootRequired);
C, "newdev.dll");
// $ffi->UpdateDriverForPlugAndPlayDevicesW(hwndParent, HardwareId, FullInfPath, InstallFlags, bRebootRequired);
// hwndParent : HWND optional
// HardwareId : LPCWSTR
// FullInfPath : LPCWSTR
// InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
// bRebootRequired : 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 UpdateDriverForPlugAndPlayDevicesW(
Pointer hwndParent, // HWND optional
WString HardwareId, // LPCWSTR
WString FullInfPath, // LPCWSTR
int InstallFlags, // UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
IntByReference bRebootRequired // BOOL* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("newdev")]
lib Libnewdev
fun UpdateDriverForPlugAndPlayDevicesW = UpdateDriverForPlugAndPlayDevicesW(
hwndParent : Void*, # HWND optional
HardwareId : UInt16*, # LPCWSTR
FullInfPath : UInt16*, # LPCWSTR
InstallFlags : UInt32, # UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
bRebootRequired : 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 UpdateDriverForPlugAndPlayDevicesWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Int32>);
typedef UpdateDriverForPlugAndPlayDevicesWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Int32>);
final UpdateDriverForPlugAndPlayDevicesW = DynamicLibrary.open('newdev.dll')
.lookupFunction<UpdateDriverForPlugAndPlayDevicesWNative, UpdateDriverForPlugAndPlayDevicesWDart>('UpdateDriverForPlugAndPlayDevicesW');
// hwndParent : HWND optional -> Pointer<Void>
// HardwareId : LPCWSTR -> Pointer<Utf16>
// FullInfPath : LPCWSTR -> Pointer<Utf16>
// InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> Uint32
// bRebootRequired : BOOL* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function UpdateDriverForPlugAndPlayDevicesW(
hwndParent: THandle; // HWND optional
HardwareId: PWideChar; // LPCWSTR
FullInfPath: PWideChar; // LPCWSTR
InstallFlags: DWORD; // UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
bRebootRequired: Pointer // BOOL* optional, out
): BOOL; stdcall;
external 'newdev.dll' name 'UpdateDriverForPlugAndPlayDevicesW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "UpdateDriverForPlugAndPlayDevicesW"
c_UpdateDriverForPlugAndPlayDevicesW :: Ptr () -> CWString -> CWString -> Word32 -> Ptr CInt -> IO CInt
-- hwndParent : HWND optional -> Ptr ()
-- HardwareId : LPCWSTR -> CWString
-- FullInfPath : LPCWSTR -> CWString
-- InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> Word32
-- bRebootRequired : BOOL* optional, out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let updatedriverforplugandplaydevicesw =
foreign "UpdateDriverForPlugAndPlayDevicesW"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr int32_t) @-> returning int32_t)
(* hwndParent : HWND optional -> (ptr void) *)
(* HardwareId : LPCWSTR -> (ptr uint16_t) *)
(* FullInfPath : LPCWSTR -> (ptr uint16_t) *)
(* InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> uint32_t *)
(* bRebootRequired : 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 ("UpdateDriverForPlugAndPlayDevicesW" update-driver-for-plug-and-play-devices-w :convention :stdcall) :int32
(hwnd-parent :pointer) ; HWND optional
(hardware-id (:string :encoding :utf-16le)) ; LPCWSTR
(full-inf-path (:string :encoding :utf-16le)) ; LPCWSTR
(install-flags :uint32) ; UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS
(b-reboot-required :pointer)) ; BOOL* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $UpdateDriverForPlugAndPlayDevicesW = Win32::API::More->new('newdev',
'BOOL UpdateDriverForPlugAndPlayDevicesW(HANDLE hwndParent, LPCWSTR HardwareId, LPCWSTR FullInfPath, DWORD InstallFlags, LPVOID bRebootRequired)');
# my $ret = $UpdateDriverForPlugAndPlayDevicesW->Call($hwndParent, $HardwareId, $FullInfPath, $InstallFlags, $bRebootRequired);
# hwndParent : HWND optional -> HANDLE
# HardwareId : LPCWSTR -> LPCWSTR
# FullInfPath : LPCWSTR -> LPCWSTR
# InstallFlags : UPDATEDRIVERFORPLUGANDPLAYDEVICES_FLAGS -> DWORD
# bRebootRequired : BOOL* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f UpdateDriverForPlugAndPlayDevicesA (ANSI版) — 指定ハードウェアIDのデバイスのドライバーを更新する。