ホーム › Devices.DeviceAndDriverInstallation › SetupInstallFromInfSectionW
SetupInstallFromInfSectionW
関数INFのセクションに従いファイルコピーやレジストリ設定を実行する。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupInstallFromInfSectionW(
HWND Owner, // optional
void* InfHandle,
LPCWSTR SectionName,
DWORD Flags,
HKEY RelativeKeyRoot, // optional
LPCWSTR SourceRootPath, // optional
DWORD CopyFlags,
PSP_FILE_CALLBACK_W MsgHandler, // optional
void* Context, // optional
HDEVINFO DeviceInfoSet, // optional
SP_DEVINFO_DATA* DeviceInfoData // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Owner | HWND | inoptional | 進捗ダイアログの親ウィンドウハンドル。NULL可。 |
| InfHandle | void* | in | インストール情報を持つINFファイルのハンドル。 |
| SectionName | LPCWSTR | in | 実行するInstallセクションの名前(Unicode)。 |
| Flags | DWORD | in | SPINST_*系の処理対象を示すフラグ(レジストリ/ファイル等)。 |
| RelativeKeyRoot | HKEY | inoptional | AddRegで使う相対レジストリのルートキーハンドル。 |
| SourceRootPath | LPCWSTR | inoptional | コピー元ファイルのルートパス(Unicode)。NULL可。 |
| CopyFlags | DWORD | in | ファイルコピー時に適用するSP_COPY_*フラグ。 |
| MsgHandler | PSP_FILE_CALLBACK_W | inoptional | コピー進捗を受け取るコールバック関数(Unicode)。NULL可。 |
| Context | void* | inoptional | コールバックへ渡すコンテキストポインタ。 |
| DeviceInfoSet | HDEVINFO | inoptional | 関連付けるデバイス情報セットのハンドル。NULL可。 |
| DeviceInfoData | SP_DEVINFO_DATA* | inoptional | 対象デバイスを示すSP_DEVINFO_DATA構造体へのポインタ。NULL可。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupInstallFromInfSectionW(
HWND Owner, // optional
void* InfHandle,
LPCWSTR SectionName,
DWORD Flags,
HKEY RelativeKeyRoot, // optional
LPCWSTR SourceRootPath, // optional
DWORD CopyFlags,
PSP_FILE_CALLBACK_W MsgHandler, // optional
void* Context, // optional
HDEVINFO DeviceInfoSet, // optional
SP_DEVINFO_DATA* DeviceInfoData // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupInstallFromInfSectionW(
IntPtr Owner, // HWND optional
IntPtr InfHandle, // void*
[MarshalAs(UnmanagedType.LPWStr)] string SectionName, // LPCWSTR
uint Flags, // DWORD
IntPtr RelativeKeyRoot, // HKEY optional
[MarshalAs(UnmanagedType.LPWStr)] string SourceRootPath, // LPCWSTR optional
uint CopyFlags, // DWORD
IntPtr MsgHandler, // PSP_FILE_CALLBACK_W optional
IntPtr Context, // void* optional
IntPtr DeviceInfoSet, // HDEVINFO optional
IntPtr DeviceInfoData // SP_DEVINFO_DATA* optional
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupInstallFromInfSectionW(
Owner As IntPtr, ' HWND optional
InfHandle As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPWStr)> SectionName As String, ' LPCWSTR
Flags As UInteger, ' DWORD
RelativeKeyRoot As IntPtr, ' HKEY optional
<MarshalAs(UnmanagedType.LPWStr)> SourceRootPath As String, ' LPCWSTR optional
CopyFlags As UInteger, ' DWORD
MsgHandler As IntPtr, ' PSP_FILE_CALLBACK_W optional
Context As IntPtr, ' void* optional
DeviceInfoSet As IntPtr, ' HDEVINFO optional
DeviceInfoData As IntPtr ' SP_DEVINFO_DATA* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' Owner : HWND optional
' InfHandle : void*
' SectionName : LPCWSTR
' Flags : DWORD
' RelativeKeyRoot : HKEY optional
' SourceRootPath : LPCWSTR optional
' CopyFlags : DWORD
' MsgHandler : PSP_FILE_CALLBACK_W optional
' Context : void* optional
' DeviceInfoSet : HDEVINFO optional
' DeviceInfoData : SP_DEVINFO_DATA* optional
Declare PtrSafe Function SetupInstallFromInfSectionW Lib "setupapi" ( _
ByVal Owner As LongPtr, _
ByVal InfHandle As LongPtr, _
ByVal SectionName As LongPtr, _
ByVal Flags As Long, _
ByVal RelativeKeyRoot As LongPtr, _
ByVal SourceRootPath As LongPtr, _
ByVal CopyFlags As Long, _
ByVal MsgHandler As LongPtr, _
ByVal Context As LongPtr, _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData 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
SetupInstallFromInfSectionW = ctypes.windll.setupapi.SetupInstallFromInfSectionW
SetupInstallFromInfSectionW.restype = wintypes.BOOL
SetupInstallFromInfSectionW.argtypes = [
wintypes.HANDLE, # Owner : HWND optional
ctypes.POINTER(None), # InfHandle : void*
wintypes.LPCWSTR, # SectionName : LPCWSTR
wintypes.DWORD, # Flags : DWORD
wintypes.HANDLE, # RelativeKeyRoot : HKEY optional
wintypes.LPCWSTR, # SourceRootPath : LPCWSTR optional
wintypes.DWORD, # CopyFlags : DWORD
ctypes.c_void_p, # MsgHandler : PSP_FILE_CALLBACK_W optional
ctypes.POINTER(None), # Context : void* optional
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO optional
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_DATA* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupInstallFromInfSectionW = Fiddle::Function.new(
lib['SetupInstallFromInfSectionW'],
[
Fiddle::TYPE_VOIDP, # Owner : HWND optional
Fiddle::TYPE_VOIDP, # InfHandle : void*
Fiddle::TYPE_VOIDP, # SectionName : LPCWSTR
-Fiddle::TYPE_INT, # Flags : DWORD
Fiddle::TYPE_VOIDP, # RelativeKeyRoot : HKEY optional
Fiddle::TYPE_VOIDP, # SourceRootPath : LPCWSTR optional
-Fiddle::TYPE_INT, # CopyFlags : DWORD
Fiddle::TYPE_VOIDP, # MsgHandler : PSP_FILE_CALLBACK_W optional
Fiddle::TYPE_VOIDP, # Context : void* optional
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO optional
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA* optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupInstallFromInfSectionW(
Owner: *mut core::ffi::c_void, // HWND optional
InfHandle: *mut (), // void*
SectionName: *const u16, // LPCWSTR
Flags: u32, // DWORD
RelativeKeyRoot: *mut core::ffi::c_void, // HKEY optional
SourceRootPath: *const u16, // LPCWSTR optional
CopyFlags: u32, // DWORD
MsgHandler: *const core::ffi::c_void, // PSP_FILE_CALLBACK_W optional
Context: *mut (), // void* optional
DeviceInfoSet: isize, // HDEVINFO optional
DeviceInfoData: *mut SP_DEVINFO_DATA // SP_DEVINFO_DATA* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupInstallFromInfSectionW(IntPtr Owner, IntPtr InfHandle, [MarshalAs(UnmanagedType.LPWStr)] string SectionName, uint Flags, IntPtr RelativeKeyRoot, [MarshalAs(UnmanagedType.LPWStr)] string SourceRootPath, uint CopyFlags, IntPtr MsgHandler, IntPtr Context, IntPtr DeviceInfoSet, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupInstallFromInfSectionW' -Namespace Win32 -PassThru
# $api::SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)#uselib "SETUPAPI.dll"
#func global SetupInstallFromInfSectionW "SetupInstallFromInfSectionW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupInstallFromInfSectionW Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, varptr(DeviceInfoData) ; 戻り値は stat
; Owner : HWND optional -> "wptr"
; InfHandle : void* -> "wptr"
; SectionName : LPCWSTR -> "wptr"
; Flags : DWORD -> "wptr"
; RelativeKeyRoot : HKEY optional -> "wptr"
; SourceRootPath : LPCWSTR optional -> "wptr"
; CopyFlags : DWORD -> "wptr"
; MsgHandler : PSP_FILE_CALLBACK_W optional -> "wptr"
; Context : void* optional -> "wptr"
; DeviceInfoSet : HDEVINFO optional -> "wptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupInstallFromInfSectionW "SetupInstallFromInfSectionW" sptr, sptr, wstr, int, sptr, wstr, int, sptr, sptr, sptr, var ; res = SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData) ; Owner : HWND optional -> "sptr" ; InfHandle : void* -> "sptr" ; SectionName : LPCWSTR -> "wstr" ; Flags : DWORD -> "int" ; RelativeKeyRoot : HKEY optional -> "sptr" ; SourceRootPath : LPCWSTR optional -> "wstr" ; CopyFlags : DWORD -> "int" ; MsgHandler : PSP_FILE_CALLBACK_W optional -> "sptr" ; Context : void* optional -> "sptr" ; DeviceInfoSet : HDEVINFO optional -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupInstallFromInfSectionW "SetupInstallFromInfSectionW" sptr, sptr, wstr, int, sptr, wstr, int, sptr, sptr, sptr, sptr ; res = SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, varptr(DeviceInfoData)) ; Owner : HWND optional -> "sptr" ; InfHandle : void* -> "sptr" ; SectionName : LPCWSTR -> "wstr" ; Flags : DWORD -> "int" ; RelativeKeyRoot : HKEY optional -> "sptr" ; SourceRootPath : LPCWSTR optional -> "wstr" ; CopyFlags : DWORD -> "int" ; MsgHandler : PSP_FILE_CALLBACK_W optional -> "sptr" ; Context : void* optional -> "sptr" ; DeviceInfoSet : HDEVINFO optional -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupInstallFromInfSectionW(HWND Owner, void* InfHandle, LPCWSTR SectionName, DWORD Flags, HKEY RelativeKeyRoot, LPCWSTR SourceRootPath, DWORD CopyFlags, PSP_FILE_CALLBACK_W MsgHandler, void* Context, HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData) #uselib "SETUPAPI.dll" #cfunc global SetupInstallFromInfSectionW "SetupInstallFromInfSectionW" intptr, intptr, wstr, int, intptr, wstr, int, intptr, intptr, intptr, var ; res = SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData) ; Owner : HWND optional -> "intptr" ; InfHandle : void* -> "intptr" ; SectionName : LPCWSTR -> "wstr" ; Flags : DWORD -> "int" ; RelativeKeyRoot : HKEY optional -> "intptr" ; SourceRootPath : LPCWSTR optional -> "wstr" ; CopyFlags : DWORD -> "int" ; MsgHandler : PSP_FILE_CALLBACK_W optional -> "intptr" ; Context : void* optional -> "intptr" ; DeviceInfoSet : HDEVINFO optional -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupInstallFromInfSectionW(HWND Owner, void* InfHandle, LPCWSTR SectionName, DWORD Flags, HKEY RelativeKeyRoot, LPCWSTR SourceRootPath, DWORD CopyFlags, PSP_FILE_CALLBACK_W MsgHandler, void* Context, HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData) #uselib "SETUPAPI.dll" #cfunc global SetupInstallFromInfSectionW "SetupInstallFromInfSectionW" intptr, intptr, wstr, int, intptr, wstr, int, intptr, intptr, intptr, intptr ; res = SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, varptr(DeviceInfoData)) ; Owner : HWND optional -> "intptr" ; InfHandle : void* -> "intptr" ; SectionName : LPCWSTR -> "wstr" ; Flags : DWORD -> "int" ; RelativeKeyRoot : HKEY optional -> "intptr" ; SourceRootPath : LPCWSTR optional -> "wstr" ; CopyFlags : DWORD -> "int" ; MsgHandler : PSP_FILE_CALLBACK_W optional -> "intptr" ; Context : void* optional -> "intptr" ; DeviceInfoSet : HDEVINFO optional -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupInstallFromInfSectionW = setupapi.NewProc("SetupInstallFromInfSectionW")
)
// Owner (HWND optional), InfHandle (void*), SectionName (LPCWSTR), Flags (DWORD), RelativeKeyRoot (HKEY optional), SourceRootPath (LPCWSTR optional), CopyFlags (DWORD), MsgHandler (PSP_FILE_CALLBACK_W optional), Context (void* optional), DeviceInfoSet (HDEVINFO optional), DeviceInfoData (SP_DEVINFO_DATA* optional)
r1, _, err := procSetupInstallFromInfSectionW.Call(
uintptr(Owner),
uintptr(InfHandle),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SectionName))),
uintptr(Flags),
uintptr(RelativeKeyRoot),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceRootPath))),
uintptr(CopyFlags),
uintptr(MsgHandler),
uintptr(Context),
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupInstallFromInfSectionW(
Owner: THandle; // HWND optional
InfHandle: Pointer; // void*
SectionName: PWideChar; // LPCWSTR
Flags: DWORD; // DWORD
RelativeKeyRoot: THandle; // HKEY optional
SourceRootPath: PWideChar; // LPCWSTR optional
CopyFlags: DWORD; // DWORD
MsgHandler: Pointer; // PSP_FILE_CALLBACK_W optional
Context: Pointer; // void* optional
DeviceInfoSet: NativeInt; // HDEVINFO optional
DeviceInfoData: Pointer // SP_DEVINFO_DATA* optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupInstallFromInfSectionW';result := DllCall("SETUPAPI\SetupInstallFromInfSectionW"
, "Ptr", Owner ; HWND optional
, "Ptr", InfHandle ; void*
, "WStr", SectionName ; LPCWSTR
, "UInt", Flags ; DWORD
, "Ptr", RelativeKeyRoot ; HKEY optional
, "WStr", SourceRootPath ; LPCWSTR optional
, "UInt", CopyFlags ; DWORD
, "Ptr", MsgHandler ; PSP_FILE_CALLBACK_W optional
, "Ptr", Context ; void* optional
, "Ptr", DeviceInfoSet ; HDEVINFO optional
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA* optional
, "Int") ; return: BOOL●SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupInstallFromInfSectionW(void*, void*, char*, dword, void*, char*, dword, void*, void*, int, void*)")
# 呼び出し: SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
# Owner : HWND optional -> "void*"
# InfHandle : void* -> "void*"
# SectionName : LPCWSTR -> "char*"
# Flags : DWORD -> "dword"
# RelativeKeyRoot : HKEY optional -> "void*"
# SourceRootPath : LPCWSTR optional -> "char*"
# CopyFlags : DWORD -> "dword"
# MsgHandler : PSP_FILE_CALLBACK_W optional -> "void*"
# Context : void* optional -> "void*"
# DeviceInfoSet : HDEVINFO optional -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn SetupInstallFromInfSectionW(
Owner: ?*anyopaque, // HWND optional
InfHandle: ?*anyopaque, // void*
SectionName: [*c]const u16, // LPCWSTR
Flags: u32, // DWORD
RelativeKeyRoot: ?*anyopaque, // HKEY optional
SourceRootPath: [*c]const u16, // LPCWSTR optional
CopyFlags: u32, // DWORD
MsgHandler: ?*anyopaque, // PSP_FILE_CALLBACK_W optional
Context: ?*anyopaque, // void* optional
DeviceInfoSet: isize, // HDEVINFO optional
DeviceInfoData: [*c]SP_DEVINFO_DATA // SP_DEVINFO_DATA* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupInstallFromInfSectionW(
Owner: pointer, # HWND optional
InfHandle: pointer, # void*
SectionName: WideCString, # LPCWSTR
Flags: uint32, # DWORD
RelativeKeyRoot: pointer, # HKEY optional
SourceRootPath: WideCString, # LPCWSTR optional
CopyFlags: uint32, # DWORD
MsgHandler: pointer, # PSP_FILE_CALLBACK_W optional
Context: pointer, # void* optional
DeviceInfoSet: int, # HDEVINFO optional
DeviceInfoData: ptr SP_DEVINFO_DATA # SP_DEVINFO_DATA* optional
): int32 {.importc: "SetupInstallFromInfSectionW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
int SetupInstallFromInfSectionW(
void* Owner, // HWND optional
void* InfHandle, // void*
const(wchar)* SectionName, // LPCWSTR
uint Flags, // DWORD
void* RelativeKeyRoot, // HKEY optional
const(wchar)* SourceRootPath, // LPCWSTR optional
uint CopyFlags, // DWORD
void* MsgHandler, // PSP_FILE_CALLBACK_W optional
void* Context, // void* optional
ptrdiff_t DeviceInfoSet, // HDEVINFO optional
SP_DEVINFO_DATA* DeviceInfoData // SP_DEVINFO_DATA* optional
);ccall((:SetupInstallFromInfSectionW, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, UInt32, Ptr{Cvoid}, Cwstring, UInt32, Ptr{Cvoid}, Ptr{Cvoid}, Int, Ptr{SP_DEVINFO_DATA}),
Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
# Owner : HWND optional -> Ptr{Cvoid}
# InfHandle : void* -> Ptr{Cvoid}
# SectionName : LPCWSTR -> Cwstring
# Flags : DWORD -> UInt32
# RelativeKeyRoot : HKEY optional -> Ptr{Cvoid}
# SourceRootPath : LPCWSTR optional -> Cwstring
# CopyFlags : DWORD -> UInt32
# MsgHandler : PSP_FILE_CALLBACK_W optional -> Ptr{Cvoid}
# Context : void* optional -> Ptr{Cvoid}
# DeviceInfoSet : HDEVINFO optional -> Int
# DeviceInfoData : SP_DEVINFO_DATA* optional -> Ptr{SP_DEVINFO_DATA}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupInstallFromInfSectionW(
void* Owner,
void* InfHandle,
const uint16_t* SectionName,
uint32_t Flags,
void* RelativeKeyRoot,
const uint16_t* SourceRootPath,
uint32_t CopyFlags,
void* MsgHandler,
void* Context,
intptr_t DeviceInfoSet,
void* DeviceInfoData);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
-- Owner : HWND optional
-- InfHandle : void*
-- SectionName : LPCWSTR
-- Flags : DWORD
-- RelativeKeyRoot : HKEY optional
-- SourceRootPath : LPCWSTR optional
-- CopyFlags : DWORD
-- MsgHandler : PSP_FILE_CALLBACK_W optional
-- Context : void* optional
-- DeviceInfoSet : HDEVINFO optional
-- DeviceInfoData : SP_DEVINFO_DATA* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupInstallFromInfSectionW = lib.func('__stdcall', 'SetupInstallFromInfSectionW', 'int32_t', ['void *', 'void *', 'str16', 'uint32_t', 'void *', 'str16', 'uint32_t', 'void *', 'void *', 'intptr_t', 'void *']);
// SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
// Owner : HWND optional -> 'void *'
// InfHandle : void* -> 'void *'
// SectionName : LPCWSTR -> 'str16'
// Flags : DWORD -> 'uint32_t'
// RelativeKeyRoot : HKEY optional -> 'void *'
// SourceRootPath : LPCWSTR optional -> 'str16'
// CopyFlags : DWORD -> 'uint32_t'
// MsgHandler : PSP_FILE_CALLBACK_W optional -> 'void *'
// Context : void* optional -> 'void *'
// DeviceInfoSet : HDEVINFO optional -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupInstallFromInfSectionW: { parameters: ["pointer", "pointer", "buffer", "u32", "pointer", "buffer", "u32", "pointer", "pointer", "isize", "pointer"], result: "i32" },
});
// lib.symbols.SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData)
// Owner : HWND optional -> "pointer"
// InfHandle : void* -> "pointer"
// SectionName : LPCWSTR -> "buffer"
// Flags : DWORD -> "u32"
// RelativeKeyRoot : HKEY optional -> "pointer"
// SourceRootPath : LPCWSTR optional -> "buffer"
// CopyFlags : DWORD -> "u32"
// MsgHandler : PSP_FILE_CALLBACK_W optional -> "pointer"
// Context : void* optional -> "pointer"
// DeviceInfoSet : HDEVINFO optional -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupInstallFromInfSectionW(
void* Owner,
void* InfHandle,
const uint16_t* SectionName,
uint32_t Flags,
void* RelativeKeyRoot,
const uint16_t* SourceRootPath,
uint32_t CopyFlags,
void* MsgHandler,
void* Context,
intptr_t DeviceInfoSet,
void* DeviceInfoData);
C, "SETUPAPI.dll");
// $ffi->SetupInstallFromInfSectionW(Owner, InfHandle, SectionName, Flags, RelativeKeyRoot, SourceRootPath, CopyFlags, MsgHandler, Context, DeviceInfoSet, DeviceInfoData);
// Owner : HWND optional
// InfHandle : void*
// SectionName : LPCWSTR
// Flags : DWORD
// RelativeKeyRoot : HKEY optional
// SourceRootPath : LPCWSTR optional
// CopyFlags : DWORD
// MsgHandler : PSP_FILE_CALLBACK_W optional
// Context : void* optional
// DeviceInfoSet : HDEVINFO optional
// DeviceInfoData : SP_DEVINFO_DATA* optional
// 構造体/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 Setupapi extends StdCallLibrary {
Setupapi INSTANCE = Native.load("setupapi", Setupapi.class, W32APIOptions.UNICODE_OPTIONS);
boolean SetupInstallFromInfSectionW(
Pointer Owner, // HWND optional
Pointer InfHandle, // void*
WString SectionName, // LPCWSTR
int Flags, // DWORD
Pointer RelativeKeyRoot, // HKEY optional
WString SourceRootPath, // LPCWSTR optional
int CopyFlags, // DWORD
Callback MsgHandler, // PSP_FILE_CALLBACK_W optional
Pointer Context, // void* optional
long DeviceInfoSet, // HDEVINFO optional
Pointer DeviceInfoData // SP_DEVINFO_DATA* optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupInstallFromInfSectionW = SetupInstallFromInfSectionW(
Owner : Void*, # HWND optional
InfHandle : Void*, # void*
SectionName : UInt16*, # LPCWSTR
Flags : UInt32, # DWORD
RelativeKeyRoot : Void*, # HKEY optional
SourceRootPath : UInt16*, # LPCWSTR optional
CopyFlags : UInt32, # DWORD
MsgHandler : Void*, # PSP_FILE_CALLBACK_W optional
Context : Void*, # void* optional
DeviceInfoSet : LibC::SSizeT, # HDEVINFO optional
DeviceInfoData : SP_DEVINFO_DATA* # SP_DEVINFO_DATA* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupInstallFromInfSectionWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Void>, IntPtr, Pointer<Void>);
typedef SetupInstallFromInfSectionWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final SetupInstallFromInfSectionW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupInstallFromInfSectionWNative, SetupInstallFromInfSectionWDart>('SetupInstallFromInfSectionW');
// Owner : HWND optional -> Pointer<Void>
// InfHandle : void* -> Pointer<Void>
// SectionName : LPCWSTR -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// RelativeKeyRoot : HKEY optional -> Pointer<Void>
// SourceRootPath : LPCWSTR optional -> Pointer<Utf16>
// CopyFlags : DWORD -> Uint32
// MsgHandler : PSP_FILE_CALLBACK_W optional -> Pointer<Void>
// Context : void* optional -> Pointer<Void>
// DeviceInfoSet : HDEVINFO optional -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupInstallFromInfSectionW(
Owner: THandle; // HWND optional
InfHandle: Pointer; // void*
SectionName: PWideChar; // LPCWSTR
Flags: DWORD; // DWORD
RelativeKeyRoot: THandle; // HKEY optional
SourceRootPath: PWideChar; // LPCWSTR optional
CopyFlags: DWORD; // DWORD
MsgHandler: Pointer; // PSP_FILE_CALLBACK_W optional
Context: Pointer; // void* optional
DeviceInfoSet: NativeInt; // HDEVINFO optional
DeviceInfoData: Pointer // SP_DEVINFO_DATA* optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupInstallFromInfSectionW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupInstallFromInfSectionW"
c_SetupInstallFromInfSectionW :: Ptr () -> Ptr () -> CWString -> Word32 -> Ptr () -> CWString -> Word32 -> Ptr () -> Ptr () -> CIntPtr -> Ptr () -> IO CInt
-- Owner : HWND optional -> Ptr ()
-- InfHandle : void* -> Ptr ()
-- SectionName : LPCWSTR -> CWString
-- Flags : DWORD -> Word32
-- RelativeKeyRoot : HKEY optional -> Ptr ()
-- SourceRootPath : LPCWSTR optional -> CWString
-- CopyFlags : DWORD -> Word32
-- MsgHandler : PSP_FILE_CALLBACK_W optional -> Ptr ()
-- Context : void* optional -> Ptr ()
-- DeviceInfoSet : HDEVINFO optional -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupinstallfrominfsectionw =
foreign "SetupInstallFromInfSectionW"
((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> intptr_t @-> (ptr void) @-> returning int32_t)
(* Owner : HWND optional -> (ptr void) *)
(* InfHandle : void* -> (ptr void) *)
(* SectionName : LPCWSTR -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* RelativeKeyRoot : HKEY optional -> (ptr void) *)
(* SourceRootPath : LPCWSTR optional -> (ptr uint16_t) *)
(* CopyFlags : DWORD -> uint32_t *)
(* MsgHandler : PSP_FILE_CALLBACK_W optional -> (ptr void) *)
(* Context : void* optional -> (ptr void) *)
(* DeviceInfoSet : HDEVINFO optional -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupInstallFromInfSectionW" setup-install-from-inf-section-w :convention :stdcall) :int32
(owner :pointer) ; HWND optional
(inf-handle :pointer) ; void*
(section-name (:string :encoding :utf-16le)) ; LPCWSTR
(flags :uint32) ; DWORD
(relative-key-root :pointer) ; HKEY optional
(source-root-path (:string :encoding :utf-16le)) ; LPCWSTR optional
(copy-flags :uint32) ; DWORD
(msg-handler :pointer) ; PSP_FILE_CALLBACK_W optional
(context :pointer) ; void* optional
(device-info-set :int64) ; HDEVINFO optional
(device-info-data :pointer)) ; SP_DEVINFO_DATA* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupInstallFromInfSectionW = Win32::API::More->new('SETUPAPI',
'BOOL SetupInstallFromInfSectionW(HANDLE Owner, LPVOID InfHandle, LPCWSTR SectionName, DWORD Flags, HANDLE RelativeKeyRoot, LPCWSTR SourceRootPath, DWORD CopyFlags, LPVOID MsgHandler, LPVOID Context, LPARAM DeviceInfoSet, LPVOID DeviceInfoData)');
# my $ret = $SetupInstallFromInfSectionW->Call($Owner, $InfHandle, $SectionName, $Flags, $RelativeKeyRoot, $SourceRootPath, $CopyFlags, $MsgHandler, $Context, $DeviceInfoSet, $DeviceInfoData);
# Owner : HWND optional -> HANDLE
# InfHandle : void* -> LPVOID
# SectionName : LPCWSTR -> LPCWSTR
# Flags : DWORD -> DWORD
# RelativeKeyRoot : HKEY optional -> HANDLE
# SourceRootPath : LPCWSTR optional -> LPCWSTR
# CopyFlags : DWORD -> DWORD
# MsgHandler : PSP_FILE_CALLBACK_W optional -> LPVOID
# Context : void* optional -> LPVOID
# DeviceInfoSet : HDEVINFO optional -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SetupInstallFromInfSectionA (ANSI版) — INFのセクションに従いファイルコピーやレジストリ設定を実行する。