ホーム › Devices.DeviceAndDriverInstallation › SetupInstallFileExW
SetupInstallFileExW
関数使用中状態の通知付きで単一ファイルをインストールする(Unicode)。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupInstallFileExW(
void* InfHandle, // optional
INFCONTEXT* InfContext, // optional
LPCWSTR SourceFile, // optional
LPCWSTR SourcePathRoot, // optional
LPCWSTR DestinationName, // optional
SP_COPY_STYLE CopyStyle,
PSP_FILE_CALLBACK_W CopyMsgHandler, // optional
void* Context, // optional
BOOL* FileWasInUse
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| InfHandle | void* | inoptional |
| InfContext | INFCONTEXT* | inoptional |
| SourceFile | LPCWSTR | inoptional |
| SourcePathRoot | LPCWSTR | inoptional |
| DestinationName | LPCWSTR | inoptional |
| CopyStyle | SP_COPY_STYLE | in |
| CopyMsgHandler | PSP_FILE_CALLBACK_W | inoptional |
| Context | void* | inoptional |
| FileWasInUse | BOOL* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupInstallFileExW(
void* InfHandle, // optional
INFCONTEXT* InfContext, // optional
LPCWSTR SourceFile, // optional
LPCWSTR SourcePathRoot, // optional
LPCWSTR DestinationName, // optional
SP_COPY_STYLE CopyStyle,
PSP_FILE_CALLBACK_W CopyMsgHandler, // optional
void* Context, // optional
BOOL* FileWasInUse
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupInstallFileExW(
IntPtr InfHandle, // void* optional
IntPtr InfContext, // INFCONTEXT* optional
[MarshalAs(UnmanagedType.LPWStr)] string SourceFile, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string SourcePathRoot, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string DestinationName, // LPCWSTR optional
uint CopyStyle, // SP_COPY_STYLE
IntPtr CopyMsgHandler, // PSP_FILE_CALLBACK_W optional
IntPtr Context, // void* optional
out int FileWasInUse // BOOL* out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupInstallFileExW(
InfHandle As IntPtr, ' void* optional
InfContext As IntPtr, ' INFCONTEXT* optional
<MarshalAs(UnmanagedType.LPWStr)> SourceFile As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> SourcePathRoot As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> DestinationName As String, ' LPCWSTR optional
CopyStyle As UInteger, ' SP_COPY_STYLE
CopyMsgHandler As IntPtr, ' PSP_FILE_CALLBACK_W optional
Context As IntPtr, ' void* optional
<Out> ByRef FileWasInUse As Integer ' BOOL* out
) As Boolean
End Function' InfHandle : void* optional
' InfContext : INFCONTEXT* optional
' SourceFile : LPCWSTR optional
' SourcePathRoot : LPCWSTR optional
' DestinationName : LPCWSTR optional
' CopyStyle : SP_COPY_STYLE
' CopyMsgHandler : PSP_FILE_CALLBACK_W optional
' Context : void* optional
' FileWasInUse : BOOL* out
Declare PtrSafe Function SetupInstallFileExW Lib "setupapi" ( _
ByVal InfHandle As LongPtr, _
ByVal InfContext As LongPtr, _
ByVal SourceFile As LongPtr, _
ByVal SourcePathRoot As LongPtr, _
ByVal DestinationName As LongPtr, _
ByVal CopyStyle As Long, _
ByVal CopyMsgHandler As LongPtr, _
ByVal Context As LongPtr, _
ByRef FileWasInUse As Long) 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
SetupInstallFileExW = ctypes.windll.setupapi.SetupInstallFileExW
SetupInstallFileExW.restype = wintypes.BOOL
SetupInstallFileExW.argtypes = [
ctypes.POINTER(None), # InfHandle : void* optional
ctypes.c_void_p, # InfContext : INFCONTEXT* optional
wintypes.LPCWSTR, # SourceFile : LPCWSTR optional
wintypes.LPCWSTR, # SourcePathRoot : LPCWSTR optional
wintypes.LPCWSTR, # DestinationName : LPCWSTR optional
wintypes.DWORD, # CopyStyle : SP_COPY_STYLE
ctypes.c_void_p, # CopyMsgHandler : PSP_FILE_CALLBACK_W optional
ctypes.POINTER(None), # Context : void* optional
ctypes.c_void_p, # FileWasInUse : BOOL* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupInstallFileExW = Fiddle::Function.new(
lib['SetupInstallFileExW'],
[
Fiddle::TYPE_VOIDP, # InfHandle : void* optional
Fiddle::TYPE_VOIDP, # InfContext : INFCONTEXT* optional
Fiddle::TYPE_VOIDP, # SourceFile : LPCWSTR optional
Fiddle::TYPE_VOIDP, # SourcePathRoot : LPCWSTR optional
Fiddle::TYPE_VOIDP, # DestinationName : LPCWSTR optional
-Fiddle::TYPE_INT, # CopyStyle : SP_COPY_STYLE
Fiddle::TYPE_VOIDP, # CopyMsgHandler : PSP_FILE_CALLBACK_W optional
Fiddle::TYPE_VOIDP, # Context : void* optional
Fiddle::TYPE_VOIDP, # FileWasInUse : BOOL* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupInstallFileExW(
InfHandle: *mut (), // void* optional
InfContext: *mut INFCONTEXT, // INFCONTEXT* optional
SourceFile: *const u16, // LPCWSTR optional
SourcePathRoot: *const u16, // LPCWSTR optional
DestinationName: *const u16, // LPCWSTR optional
CopyStyle: u32, // SP_COPY_STYLE
CopyMsgHandler: *const core::ffi::c_void, // PSP_FILE_CALLBACK_W optional
Context: *mut (), // void* optional
FileWasInUse: *mut i32 // BOOL* out
) -> 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 SetupInstallFileExW(IntPtr InfHandle, IntPtr InfContext, [MarshalAs(UnmanagedType.LPWStr)] string SourceFile, [MarshalAs(UnmanagedType.LPWStr)] string SourcePathRoot, [MarshalAs(UnmanagedType.LPWStr)] string DestinationName, uint CopyStyle, IntPtr CopyMsgHandler, IntPtr Context, out int FileWasInUse);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupInstallFileExW' -Namespace Win32 -PassThru
# $api::SetupInstallFileExW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse)#uselib "SETUPAPI.dll"
#func global SetupInstallFileExW "SetupInstallFileExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupInstallFileExW InfHandle, varptr(InfContext), SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse ; 戻り値は stat
; InfHandle : void* optional -> "wptr"
; InfContext : INFCONTEXT* optional -> "wptr"
; SourceFile : LPCWSTR optional -> "wptr"
; SourcePathRoot : LPCWSTR optional -> "wptr"
; DestinationName : LPCWSTR optional -> "wptr"
; CopyStyle : SP_COPY_STYLE -> "wptr"
; CopyMsgHandler : PSP_FILE_CALLBACK_W optional -> "wptr"
; Context : void* optional -> "wptr"
; FileWasInUse : BOOL* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupInstallFileExW "SetupInstallFileExW" sptr, var, wstr, wstr, wstr, int, sptr, sptr, int ; res = SetupInstallFileExW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse) ; InfHandle : void* optional -> "sptr" ; InfContext : INFCONTEXT* optional -> "var" ; SourceFile : LPCWSTR optional -> "wstr" ; SourcePathRoot : LPCWSTR optional -> "wstr" ; DestinationName : LPCWSTR optional -> "wstr" ; CopyStyle : SP_COPY_STYLE -> "int" ; CopyMsgHandler : PSP_FILE_CALLBACK_W optional -> "sptr" ; Context : void* optional -> "sptr" ; FileWasInUse : BOOL* out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupInstallFileExW "SetupInstallFileExW" sptr, sptr, wstr, wstr, wstr, int, sptr, sptr, int ; res = SetupInstallFileExW(InfHandle, varptr(InfContext), SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse) ; InfHandle : void* optional -> "sptr" ; InfContext : INFCONTEXT* optional -> "sptr" ; SourceFile : LPCWSTR optional -> "wstr" ; SourcePathRoot : LPCWSTR optional -> "wstr" ; DestinationName : LPCWSTR optional -> "wstr" ; CopyStyle : SP_COPY_STYLE -> "int" ; CopyMsgHandler : PSP_FILE_CALLBACK_W optional -> "sptr" ; Context : void* optional -> "sptr" ; FileWasInUse : BOOL* out -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupInstallFileExW(void* InfHandle, INFCONTEXT* InfContext, LPCWSTR SourceFile, LPCWSTR SourcePathRoot, LPCWSTR DestinationName, SP_COPY_STYLE CopyStyle, PSP_FILE_CALLBACK_W CopyMsgHandler, void* Context, BOOL* FileWasInUse) #uselib "SETUPAPI.dll" #cfunc global SetupInstallFileExW "SetupInstallFileExW" intptr, var, wstr, wstr, wstr, int, intptr, intptr, int ; res = SetupInstallFileExW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse) ; InfHandle : void* optional -> "intptr" ; InfContext : INFCONTEXT* optional -> "var" ; SourceFile : LPCWSTR optional -> "wstr" ; SourcePathRoot : LPCWSTR optional -> "wstr" ; DestinationName : LPCWSTR optional -> "wstr" ; CopyStyle : SP_COPY_STYLE -> "int" ; CopyMsgHandler : PSP_FILE_CALLBACK_W optional -> "intptr" ; Context : void* optional -> "intptr" ; FileWasInUse : BOOL* out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupInstallFileExW(void* InfHandle, INFCONTEXT* InfContext, LPCWSTR SourceFile, LPCWSTR SourcePathRoot, LPCWSTR DestinationName, SP_COPY_STYLE CopyStyle, PSP_FILE_CALLBACK_W CopyMsgHandler, void* Context, BOOL* FileWasInUse) #uselib "SETUPAPI.dll" #cfunc global SetupInstallFileExW "SetupInstallFileExW" intptr, intptr, wstr, wstr, wstr, int, intptr, intptr, int ; res = SetupInstallFileExW(InfHandle, varptr(InfContext), SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse) ; InfHandle : void* optional -> "intptr" ; InfContext : INFCONTEXT* optional -> "intptr" ; SourceFile : LPCWSTR optional -> "wstr" ; SourcePathRoot : LPCWSTR optional -> "wstr" ; DestinationName : LPCWSTR optional -> "wstr" ; CopyStyle : SP_COPY_STYLE -> "int" ; CopyMsgHandler : PSP_FILE_CALLBACK_W optional -> "intptr" ; Context : void* optional -> "intptr" ; FileWasInUse : BOOL* out -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupInstallFileExW = setupapi.NewProc("SetupInstallFileExW")
)
// InfHandle (void* optional), InfContext (INFCONTEXT* optional), SourceFile (LPCWSTR optional), SourcePathRoot (LPCWSTR optional), DestinationName (LPCWSTR optional), CopyStyle (SP_COPY_STYLE), CopyMsgHandler (PSP_FILE_CALLBACK_W optional), Context (void* optional), FileWasInUse (BOOL* out)
r1, _, err := procSetupInstallFileExW.Call(
uintptr(InfHandle),
uintptr(InfContext),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceFile))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourcePathRoot))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DestinationName))),
uintptr(CopyStyle),
uintptr(CopyMsgHandler),
uintptr(Context),
uintptr(FileWasInUse),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupInstallFileExW(
InfHandle: Pointer; // void* optional
InfContext: Pointer; // INFCONTEXT* optional
SourceFile: PWideChar; // LPCWSTR optional
SourcePathRoot: PWideChar; // LPCWSTR optional
DestinationName: PWideChar; // LPCWSTR optional
CopyStyle: DWORD; // SP_COPY_STYLE
CopyMsgHandler: Pointer; // PSP_FILE_CALLBACK_W optional
Context: Pointer; // void* optional
FileWasInUse: Pointer // BOOL* out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupInstallFileExW';result := DllCall("SETUPAPI\SetupInstallFileExW"
, "Ptr", InfHandle ; void* optional
, "Ptr", InfContext ; INFCONTEXT* optional
, "WStr", SourceFile ; LPCWSTR optional
, "WStr", SourcePathRoot ; LPCWSTR optional
, "WStr", DestinationName ; LPCWSTR optional
, "UInt", CopyStyle ; SP_COPY_STYLE
, "Ptr", CopyMsgHandler ; PSP_FILE_CALLBACK_W optional
, "Ptr", Context ; void* optional
, "Ptr", FileWasInUse ; BOOL* out
, "Int") ; return: BOOL●SetupInstallFileExW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse) = DLL("SETUPAPI.dll", "bool SetupInstallFileExW(void*, void*, char*, char*, char*, dword, void*, void*, void*)")
# 呼び出し: SetupInstallFileExW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse)
# InfHandle : void* optional -> "void*"
# InfContext : INFCONTEXT* optional -> "void*"
# SourceFile : LPCWSTR optional -> "char*"
# SourcePathRoot : LPCWSTR optional -> "char*"
# DestinationName : LPCWSTR optional -> "char*"
# CopyStyle : SP_COPY_STYLE -> "dword"
# CopyMsgHandler : PSP_FILE_CALLBACK_W optional -> "void*"
# Context : void* optional -> "void*"
# FileWasInUse : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。