ホーム › 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 |
| InfHandle | void* | in |
| SectionName | LPCWSTR | in |
| Flags | DWORD | in |
| RelativeKeyRoot | HKEY | inoptional |
| SourceRootPath | LPCWSTR | inoptional |
| CopyFlags | DWORD | in |
| MsgHandler | PSP_FILE_CALLBACK_W | inoptional |
| Context | void* | inoptional |
| DeviceInfoSet | HDEVINFO | inoptional |
| DeviceInfoData | SP_DEVINFO_DATA* | inoptional |
戻り値の型: 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 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 版の利用を推奨。