ホーム › Devices.DeviceAndDriverInstallation › SetupInstallFileW
SetupInstallFileW
関数INF情報に基づき単一ファイルをコピーしてインストールする(Unicode)。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupInstallFileW(
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
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| 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 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupInstallFileW(
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
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupInstallFileW(
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
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupInstallFileW(
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
) 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
Declare PtrSafe Function SetupInstallFileW 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) 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
SetupInstallFileW = ctypes.windll.setupapi.SetupInstallFileW
SetupInstallFileW.restype = wintypes.BOOL
SetupInstallFileW.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
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupInstallFileW = Fiddle::Function.new(
lib['SetupInstallFileW'],
[
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_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupInstallFileW(
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
) -> 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 SetupInstallFileW(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);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupInstallFileW' -Namespace Win32 -PassThru
# $api::SetupInstallFileW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context)#uselib "SETUPAPI.dll"
#func global SetupInstallFileW "SetupInstallFileW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupInstallFileW InfHandle, varptr(InfContext), SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context ; 戻り値は 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"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupInstallFileW "SetupInstallFileW" sptr, var, wstr, wstr, wstr, int, sptr, sptr ; res = SetupInstallFileW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context) ; 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" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupInstallFileW "SetupInstallFileW" sptr, sptr, wstr, wstr, wstr, int, sptr, sptr ; res = SetupInstallFileW(InfHandle, varptr(InfContext), SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context) ; 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" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupInstallFileW(void* InfHandle, INFCONTEXT* InfContext, LPCWSTR SourceFile, LPCWSTR SourcePathRoot, LPCWSTR DestinationName, SP_COPY_STYLE CopyStyle, PSP_FILE_CALLBACK_W CopyMsgHandler, void* Context) #uselib "SETUPAPI.dll" #cfunc global SetupInstallFileW "SetupInstallFileW" intptr, var, wstr, wstr, wstr, int, intptr, intptr ; res = SetupInstallFileW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context) ; 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" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupInstallFileW(void* InfHandle, INFCONTEXT* InfContext, LPCWSTR SourceFile, LPCWSTR SourcePathRoot, LPCWSTR DestinationName, SP_COPY_STYLE CopyStyle, PSP_FILE_CALLBACK_W CopyMsgHandler, void* Context) #uselib "SETUPAPI.dll" #cfunc global SetupInstallFileW "SetupInstallFileW" intptr, intptr, wstr, wstr, wstr, int, intptr, intptr ; res = SetupInstallFileW(InfHandle, varptr(InfContext), SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context) ; 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" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupInstallFileW = setupapi.NewProc("SetupInstallFileW")
)
// 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)
r1, _, err := procSetupInstallFileW.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),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupInstallFileW(
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
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupInstallFileW';result := DllCall("SETUPAPI\SetupInstallFileW"
, "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
, "Int") ; return: BOOL●SetupInstallFileW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context) = DLL("SETUPAPI.dll", "bool SetupInstallFileW(void*, void*, char*, char*, char*, dword, void*, void*)")
# 呼び出し: SetupInstallFileW(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context)
# 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*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。