ホーム › Devices.DeviceAndDriverInstallation › DiInstallDevice
DiInstallDevice
関数デバイスをインストールしドライバーを適用する。
シグネチャ
// newdev.dll
#include <windows.h>
BOOL DiInstallDevice(
HWND hwndParent, // optional
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
SP_DRVINFO_DATA_V2_W* DriverInfoData, // optional
DIINSTALLDEVICE_FLAGS Flags,
BOOL* NeedReboot // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | inoptional | UIの親となるウィンドウハンドル。UI不要の場合はNULL可。 |
| DeviceInfoSet | HDEVINFO | in | 対象デバイスを含むデバイス情報セットのハンドル(HDEVINFO)。 |
| DeviceInfoData | SP_DEVINFO_DATA* | in | インストール対象デバイスを示すSP_DEVINFO_DATA構造体へのポインタ。 |
| DriverInfoData | SP_DRVINFO_DATA_V2_W* | inoptional | インストールするドライバーを示すSP_DRVINFO_DATA_V2_W構造体へのポインタ。NULLで最適ドライバーを選択。 |
| Flags | DIINSTALLDEVICE_FLAGS | in | インストール動作を制御するDIINSTALLDEVICE_FLAGS(DIIDFLAG_*)。 |
| NeedReboot | BOOL* | outoptional | 再起動が必要かどうかの真偽値を受け取る出力先ポインタ。NULL可。 |
戻り値の型: BOOL
各言語での呼び出し定義
// newdev.dll
#include <windows.h>
BOOL DiInstallDevice(
HWND hwndParent, // optional
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
SP_DRVINFO_DATA_V2_W* DriverInfoData, // optional
DIINSTALLDEVICE_FLAGS Flags,
BOOL* NeedReboot // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("newdev.dll", SetLastError = true, ExactSpelling = true)]
static extern bool DiInstallDevice(
IntPtr hwndParent, // HWND optional
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInfoData, // SP_DEVINFO_DATA*
IntPtr DriverInfoData, // SP_DRVINFO_DATA_V2_W* optional
uint Flags, // DIINSTALLDEVICE_FLAGS
IntPtr NeedReboot // BOOL* optional, out
);<DllImport("newdev.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DiInstallDevice(
hwndParent As IntPtr, ' HWND optional
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInfoData As IntPtr, ' SP_DEVINFO_DATA*
DriverInfoData As IntPtr, ' SP_DRVINFO_DATA_V2_W* optional
Flags As UInteger, ' DIINSTALLDEVICE_FLAGS
NeedReboot As IntPtr ' BOOL* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hwndParent : HWND optional
' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA*
' DriverInfoData : SP_DRVINFO_DATA_V2_W* optional
' Flags : DIINSTALLDEVICE_FLAGS
' NeedReboot : BOOL* optional, out
Declare PtrSafe Function DiInstallDevice Lib "newdev" ( _
ByVal hwndParent As LongPtr, _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData As LongPtr, _
ByVal DriverInfoData 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
DiInstallDevice = ctypes.windll.newdev.DiInstallDevice
DiInstallDevice.restype = wintypes.BOOL
DiInstallDevice.argtypes = [
wintypes.HANDLE, # hwndParent : HWND optional
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_DATA*
ctypes.c_void_p, # DriverInfoData : SP_DRVINFO_DATA_V2_W* optional
wintypes.DWORD, # Flags : DIINSTALLDEVICE_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')
DiInstallDevice = Fiddle::Function.new(
lib['DiInstallDevice'],
[
Fiddle::TYPE_VOIDP, # hwndParent : HWND optional
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA*
Fiddle::TYPE_VOIDP, # DriverInfoData : SP_DRVINFO_DATA_V2_W* optional
-Fiddle::TYPE_INT, # Flags : DIINSTALLDEVICE_FLAGS
Fiddle::TYPE_VOIDP, # NeedReboot : BOOL* optional, out
],
Fiddle::TYPE_INT)#[link(name = "newdev")]
extern "system" {
fn DiInstallDevice(
hwndParent: *mut core::ffi::c_void, // HWND optional
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: *mut SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
DriverInfoData: *mut SP_DRVINFO_DATA_V2_W, // SP_DRVINFO_DATA_V2_W* optional
Flags: u32, // DIINSTALLDEVICE_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 DiInstallDevice(IntPtr hwndParent, IntPtr DeviceInfoSet, IntPtr DeviceInfoData, IntPtr DriverInfoData, uint Flags, IntPtr NeedReboot);
"@
$api = Add-Type -MemberDefinition $sig -Name 'newdev_DiInstallDevice' -Namespace Win32 -PassThru
# $api::DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot)#uselib "newdev.dll"
#func global DiInstallDevice "DiInstallDevice" sptr, sptr, sptr, sptr, sptr, sptr
; DiInstallDevice hwndParent, DeviceInfoSet, varptr(DeviceInfoData), varptr(DriverInfoData), Flags, varptr(NeedReboot) ; 戻り値は stat
; hwndParent : HWND optional -> "sptr"
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr"
; DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> "sptr"
; Flags : DIINSTALLDEVICE_FLAGS -> "sptr"
; NeedReboot : BOOL* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "newdev.dll" #cfunc global DiInstallDevice "DiInstallDevice" sptr, sptr, var, var, int, var ; res = DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot) ; hwndParent : HWND optional -> "sptr" ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> "var" ; Flags : DIINSTALLDEVICE_FLAGS -> "int" ; NeedReboot : BOOL* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "newdev.dll" #cfunc global DiInstallDevice "DiInstallDevice" sptr, sptr, sptr, sptr, int, sptr ; res = DiInstallDevice(hwndParent, DeviceInfoSet, varptr(DeviceInfoData), varptr(DriverInfoData), Flags, varptr(NeedReboot)) ; hwndParent : HWND optional -> "sptr" ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr" ; DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> "sptr" ; Flags : DIINSTALLDEVICE_FLAGS -> "int" ; NeedReboot : BOOL* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL DiInstallDevice(HWND hwndParent, HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SP_DRVINFO_DATA_V2_W* DriverInfoData, DIINSTALLDEVICE_FLAGS Flags, BOOL* NeedReboot) #uselib "newdev.dll" #cfunc global DiInstallDevice "DiInstallDevice" intptr, intptr, var, var, int, var ; res = DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot) ; hwndParent : HWND optional -> "intptr" ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> "var" ; Flags : DIINSTALLDEVICE_FLAGS -> "int" ; NeedReboot : BOOL* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL DiInstallDevice(HWND hwndParent, HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SP_DRVINFO_DATA_V2_W* DriverInfoData, DIINSTALLDEVICE_FLAGS Flags, BOOL* NeedReboot) #uselib "newdev.dll" #cfunc global DiInstallDevice "DiInstallDevice" intptr, intptr, intptr, intptr, int, intptr ; res = DiInstallDevice(hwndParent, DeviceInfoSet, varptr(DeviceInfoData), varptr(DriverInfoData), Flags, varptr(NeedReboot)) ; hwndParent : HWND optional -> "intptr" ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "intptr" ; DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> "intptr" ; Flags : DIINSTALLDEVICE_FLAGS -> "int" ; NeedReboot : BOOL* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
newdev = windows.NewLazySystemDLL("newdev.dll")
procDiInstallDevice = newdev.NewProc("DiInstallDevice")
)
// hwndParent (HWND optional), DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA*), DriverInfoData (SP_DRVINFO_DATA_V2_W* optional), Flags (DIINSTALLDEVICE_FLAGS), NeedReboot (BOOL* optional, out)
r1, _, err := procDiInstallDevice.Call(
uintptr(hwndParent),
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
uintptr(DriverInfoData),
uintptr(Flags),
uintptr(NeedReboot),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction DiInstallDevice(
hwndParent: THandle; // HWND optional
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA*
DriverInfoData: Pointer; // SP_DRVINFO_DATA_V2_W* optional
Flags: DWORD; // DIINSTALLDEVICE_FLAGS
NeedReboot: Pointer // BOOL* optional, out
): BOOL; stdcall;
external 'newdev.dll' name 'DiInstallDevice';result := DllCall("newdev\DiInstallDevice"
, "Ptr", hwndParent ; HWND optional
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA*
, "Ptr", DriverInfoData ; SP_DRVINFO_DATA_V2_W* optional
, "UInt", Flags ; DIINSTALLDEVICE_FLAGS
, "Ptr", NeedReboot ; BOOL* optional, out
, "Int") ; return: BOOL●DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot) = DLL("newdev.dll", "bool DiInstallDevice(void*, int, void*, void*, dword, void*)")
# 呼び出し: DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot)
# hwndParent : HWND optional -> "void*"
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* -> "void*"
# DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> "void*"
# Flags : DIINSTALLDEVICE_FLAGS -> "dword"
# NeedReboot : BOOL* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "newdev" fn DiInstallDevice(
hwndParent: ?*anyopaque, // HWND optional
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: [*c]SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
DriverInfoData: [*c]SP_DRVINFO_DATA_V2_W, // SP_DRVINFO_DATA_V2_W* optional
Flags: u32, // DIINSTALLDEVICE_FLAGS
NeedReboot: [*c]i32 // BOOL* optional, out
) callconv(std.os.windows.WINAPI) i32;proc DiInstallDevice(
hwndParent: pointer, # HWND optional
DeviceInfoSet: int, # HDEVINFO
DeviceInfoData: ptr SP_DEVINFO_DATA, # SP_DEVINFO_DATA*
DriverInfoData: ptr SP_DRVINFO_DATA_V2_W, # SP_DRVINFO_DATA_V2_W* optional
Flags: uint32, # DIINSTALLDEVICE_FLAGS
NeedReboot: ptr int32 # BOOL* optional, out
): int32 {.importc: "DiInstallDevice", stdcall, dynlib: "newdev.dll".}pragma(lib, "newdev");
extern(Windows)
int DiInstallDevice(
void* hwndParent, // HWND optional
ptrdiff_t DeviceInfoSet, // HDEVINFO
SP_DEVINFO_DATA* DeviceInfoData, // SP_DEVINFO_DATA*
SP_DRVINFO_DATA_V2_W* DriverInfoData, // SP_DRVINFO_DATA_V2_W* optional
uint Flags, // DIINSTALLDEVICE_FLAGS
int* NeedReboot // BOOL* optional, out
);ccall((:DiInstallDevice, "newdev.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int, Ptr{SP_DEVINFO_DATA}, Ptr{SP_DRVINFO_DATA_V2_W}, UInt32, Ptr{Int32}),
hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot)
# hwndParent : HWND optional -> Ptr{Cvoid}
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInfoData : SP_DEVINFO_DATA* -> Ptr{SP_DEVINFO_DATA}
# DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> Ptr{SP_DRVINFO_DATA_V2_W}
# Flags : DIINSTALLDEVICE_FLAGS -> UInt32
# NeedReboot : BOOL* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t DiInstallDevice(
void* hwndParent,
intptr_t DeviceInfoSet,
void* DeviceInfoData,
void* DriverInfoData,
uint32_t Flags,
int32_t* NeedReboot);
]]
local newdev = ffi.load("newdev")
-- newdev.DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot)
-- hwndParent : HWND optional
-- DeviceInfoSet : HDEVINFO
-- DeviceInfoData : SP_DEVINFO_DATA*
-- DriverInfoData : SP_DRVINFO_DATA_V2_W* optional
-- Flags : DIINSTALLDEVICE_FLAGS
-- NeedReboot : BOOL* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('newdev.dll');
const DiInstallDevice = lib.func('__stdcall', 'DiInstallDevice', 'int32_t', ['void *', 'intptr_t', 'void *', 'void *', 'uint32_t', 'int32_t *']);
// DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot)
// hwndParent : HWND optional -> 'void *'
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* -> 'void *'
// DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> 'void *'
// Flags : DIINSTALLDEVICE_FLAGS -> 'uint32_t'
// NeedReboot : BOOL* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("newdev.dll", {
DiInstallDevice: { parameters: ["pointer", "isize", "pointer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot)
// hwndParent : HWND optional -> "pointer"
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* -> "pointer"
// DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> "pointer"
// Flags : DIINSTALLDEVICE_FLAGS -> "u32"
// NeedReboot : BOOL* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t DiInstallDevice(
void* hwndParent,
intptr_t DeviceInfoSet,
void* DeviceInfoData,
void* DriverInfoData,
uint32_t Flags,
int32_t* NeedReboot);
C, "newdev.dll");
// $ffi->DiInstallDevice(hwndParent, DeviceInfoSet, DeviceInfoData, DriverInfoData, Flags, NeedReboot);
// hwndParent : HWND optional
// DeviceInfoSet : HDEVINFO
// DeviceInfoData : SP_DEVINFO_DATA*
// DriverInfoData : SP_DRVINFO_DATA_V2_W* optional
// Flags : DIINSTALLDEVICE_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 DiInstallDevice(
Pointer hwndParent, // HWND optional
long DeviceInfoSet, // HDEVINFO
Pointer DeviceInfoData, // SP_DEVINFO_DATA*
Pointer DriverInfoData, // SP_DRVINFO_DATA_V2_W* optional
int Flags, // DIINSTALLDEVICE_FLAGS
IntByReference NeedReboot // BOOL* optional, out
);
}@[Link("newdev")]
lib Libnewdev
fun DiInstallDevice = DiInstallDevice(
hwndParent : Void*, # HWND optional
DeviceInfoSet : LibC::SSizeT, # HDEVINFO
DeviceInfoData : SP_DEVINFO_DATA*, # SP_DEVINFO_DATA*
DriverInfoData : SP_DRVINFO_DATA_V2_W*, # SP_DRVINFO_DATA_V2_W* optional
Flags : UInt32, # DIINSTALLDEVICE_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 DiInstallDeviceNative = Int32 Function(Pointer<Void>, IntPtr, Pointer<Void>, Pointer<Void>, Uint32, Pointer<Int32>);
typedef DiInstallDeviceDart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Void>, int, Pointer<Int32>);
final DiInstallDevice = DynamicLibrary.open('newdev.dll')
.lookupFunction<DiInstallDeviceNative, DiInstallDeviceDart>('DiInstallDevice');
// hwndParent : HWND optional -> Pointer<Void>
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* -> Pointer<Void>
// DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> Pointer<Void>
// Flags : DIINSTALLDEVICE_FLAGS -> Uint32
// NeedReboot : BOOL* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DiInstallDevice(
hwndParent: THandle; // HWND optional
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA*
DriverInfoData: Pointer; // SP_DRVINFO_DATA_V2_W* optional
Flags: DWORD; // DIINSTALLDEVICE_FLAGS
NeedReboot: Pointer // BOOL* optional, out
): BOOL; stdcall;
external 'newdev.dll' name 'DiInstallDevice';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DiInstallDevice"
c_DiInstallDevice :: Ptr () -> CIntPtr -> Ptr () -> Ptr () -> Word32 -> Ptr CInt -> IO CInt
-- hwndParent : HWND optional -> Ptr ()
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* -> Ptr ()
-- DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> Ptr ()
-- Flags : DIINSTALLDEVICE_FLAGS -> Word32
-- NeedReboot : BOOL* optional, out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let diinstalldevice =
foreign "DiInstallDevice"
((ptr void) @-> intptr_t @-> (ptr void) @-> (ptr void) @-> uint32_t @-> (ptr int32_t) @-> returning int32_t)
(* hwndParent : HWND optional -> (ptr void) *)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* -> (ptr void) *)
(* DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> (ptr void) *)
(* Flags : DIINSTALLDEVICE_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 ("DiInstallDevice" di-install-device :convention :stdcall) :int32
(hwnd-parent :pointer) ; HWND optional
(device-info-set :int64) ; HDEVINFO
(device-info-data :pointer) ; SP_DEVINFO_DATA*
(driver-info-data :pointer) ; SP_DRVINFO_DATA_V2_W* optional
(flags :uint32) ; DIINSTALLDEVICE_FLAGS
(need-reboot :pointer)) ; BOOL* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DiInstallDevice = Win32::API::More->new('newdev',
'BOOL DiInstallDevice(HANDLE hwndParent, LPARAM DeviceInfoSet, LPVOID DeviceInfoData, LPVOID DriverInfoData, DWORD Flags, LPVOID NeedReboot)');
# my $ret = $DiInstallDevice->Call($hwndParent, $DeviceInfoSet, $DeviceInfoData, $DriverInfoData, $Flags, $NeedReboot);
# hwndParent : HWND optional -> HANDLE
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* -> LPVOID
# DriverInfoData : SP_DRVINFO_DATA_V2_W* optional -> LPVOID
# Flags : DIINSTALLDEVICE_FLAGS -> DWORD
# NeedReboot : BOOL* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。