Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupInstallFileA

SetupInstallFileA

関数
INF情報に基づき単一ファイルをコピーしてインストールする(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupInstallFileA(
    void* InfHandle,   // optional
    INFCONTEXT* InfContext,   // optional
    LPCSTR SourceFile,   // optional
    LPCSTR SourcePathRoot,   // optional
    LPCSTR DestinationName,   // optional
    SP_COPY_STYLE CopyStyle,
    PSP_FILE_CALLBACK_A CopyMsgHandler,   // optional
    void* Context   // optional
);

パラメーター

名前方向
InfHandlevoid*inoptional
InfContextINFCONTEXT*inoptional
SourceFileLPCSTRinoptional
SourcePathRootLPCSTRinoptional
DestinationNameLPCSTRinoptional
CopyStyleSP_COPY_STYLEin
CopyMsgHandlerPSP_FILE_CALLBACK_Ainoptional
Contextvoid*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupInstallFileA(
    void* InfHandle,   // optional
    INFCONTEXT* InfContext,   // optional
    LPCSTR SourceFile,   // optional
    LPCSTR SourcePathRoot,   // optional
    LPCSTR DestinationName,   // optional
    SP_COPY_STYLE CopyStyle,
    PSP_FILE_CALLBACK_A CopyMsgHandler,   // optional
    void* Context   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupInstallFileA(
    IntPtr InfHandle,   // void* optional
    IntPtr InfContext,   // INFCONTEXT* optional
    [MarshalAs(UnmanagedType.LPStr)] string SourceFile,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string SourcePathRoot,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string DestinationName,   // LPCSTR optional
    uint CopyStyle,   // SP_COPY_STYLE
    IntPtr CopyMsgHandler,   // PSP_FILE_CALLBACK_A optional
    IntPtr Context   // void* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupInstallFileA(
    InfHandle As IntPtr,   ' void* optional
    InfContext As IntPtr,   ' INFCONTEXT* optional
    <MarshalAs(UnmanagedType.LPStr)> SourceFile As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> SourcePathRoot As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> DestinationName As String,   ' LPCSTR optional
    CopyStyle As UInteger,   ' SP_COPY_STYLE
    CopyMsgHandler As IntPtr,   ' PSP_FILE_CALLBACK_A optional
    Context As IntPtr   ' void* optional
) As Boolean
End Function
' InfHandle : void* optional
' InfContext : INFCONTEXT* optional
' SourceFile : LPCSTR optional
' SourcePathRoot : LPCSTR optional
' DestinationName : LPCSTR optional
' CopyStyle : SP_COPY_STYLE
' CopyMsgHandler : PSP_FILE_CALLBACK_A optional
' Context : void* optional
Declare PtrSafe Function SetupInstallFileA Lib "setupapi" ( _
    ByVal InfHandle As LongPtr, _
    ByVal InfContext As LongPtr, _
    ByVal SourceFile As String, _
    ByVal SourcePathRoot As String, _
    ByVal DestinationName As String, _
    ByVal CopyStyle As Long, _
    ByVal CopyMsgHandler As LongPtr, _
    ByVal Context As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupInstallFileA = ctypes.windll.setupapi.SetupInstallFileA
SetupInstallFileA.restype = wintypes.BOOL
SetupInstallFileA.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void* optional
    ctypes.c_void_p,  # InfContext : INFCONTEXT* optional
    wintypes.LPCSTR,  # SourceFile : LPCSTR optional
    wintypes.LPCSTR,  # SourcePathRoot : LPCSTR optional
    wintypes.LPCSTR,  # DestinationName : LPCSTR optional
    wintypes.DWORD,  # CopyStyle : SP_COPY_STYLE
    ctypes.c_void_p,  # CopyMsgHandler : PSP_FILE_CALLBACK_A 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')
SetupInstallFileA = Fiddle::Function.new(
  lib['SetupInstallFileA'],
  [
    Fiddle::TYPE_VOIDP,  # InfHandle : void* optional
    Fiddle::TYPE_VOIDP,  # InfContext : INFCONTEXT* optional
    Fiddle::TYPE_VOIDP,  # SourceFile : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # SourcePathRoot : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # DestinationName : LPCSTR optional
    -Fiddle::TYPE_INT,  # CopyStyle : SP_COPY_STYLE
    Fiddle::TYPE_VOIDP,  # CopyMsgHandler : PSP_FILE_CALLBACK_A optional
    Fiddle::TYPE_VOIDP,  # Context : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupInstallFileA(
        InfHandle: *mut (),  // void* optional
        InfContext: *mut INFCONTEXT,  // INFCONTEXT* optional
        SourceFile: *const u8,  // LPCSTR optional
        SourcePathRoot: *const u8,  // LPCSTR optional
        DestinationName: *const u8,  // LPCSTR optional
        CopyStyle: u32,  // SP_COPY_STYLE
        CopyMsgHandler: *const core::ffi::c_void,  // PSP_FILE_CALLBACK_A 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.Ansi, SetLastError = true)]
public static extern bool SetupInstallFileA(IntPtr InfHandle, IntPtr InfContext, [MarshalAs(UnmanagedType.LPStr)] string SourceFile, [MarshalAs(UnmanagedType.LPStr)] string SourcePathRoot, [MarshalAs(UnmanagedType.LPStr)] string DestinationName, uint CopyStyle, IntPtr CopyMsgHandler, IntPtr Context);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupInstallFileA' -Namespace Win32 -PassThru
# $api::SetupInstallFileA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context)
#uselib "SETUPAPI.dll"
#func global SetupInstallFileA "SetupInstallFileA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupInstallFileA InfHandle, varptr(InfContext), SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context   ; 戻り値は stat
; InfHandle : void* optional -> "sptr"
; InfContext : INFCONTEXT* optional -> "sptr"
; SourceFile : LPCSTR optional -> "sptr"
; SourcePathRoot : LPCSTR optional -> "sptr"
; DestinationName : LPCSTR optional -> "sptr"
; CopyStyle : SP_COPY_STYLE -> "sptr"
; CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> "sptr"
; Context : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupInstallFileA "SetupInstallFileA" sptr, var, str, str, str, int, sptr, sptr
; res = SetupInstallFileA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context)
; InfHandle : void* optional -> "sptr"
; InfContext : INFCONTEXT* optional -> "var"
; SourceFile : LPCSTR optional -> "str"
; SourcePathRoot : LPCSTR optional -> "str"
; DestinationName : LPCSTR optional -> "str"
; CopyStyle : SP_COPY_STYLE -> "int"
; CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> "sptr"
; Context : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupInstallFileA(void* InfHandle, INFCONTEXT* InfContext, LPCSTR SourceFile, LPCSTR SourcePathRoot, LPCSTR DestinationName, SP_COPY_STYLE CopyStyle, PSP_FILE_CALLBACK_A CopyMsgHandler, void* Context)
#uselib "SETUPAPI.dll"
#cfunc global SetupInstallFileA "SetupInstallFileA" intptr, var, str, str, str, int, intptr, intptr
; res = SetupInstallFileA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context)
; InfHandle : void* optional -> "intptr"
; InfContext : INFCONTEXT* optional -> "var"
; SourceFile : LPCSTR optional -> "str"
; SourcePathRoot : LPCSTR optional -> "str"
; DestinationName : LPCSTR optional -> "str"
; CopyStyle : SP_COPY_STYLE -> "int"
; CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> "intptr"
; Context : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupInstallFileA = setupapi.NewProc("SetupInstallFileA")
)

// InfHandle (void* optional), InfContext (INFCONTEXT* optional), SourceFile (LPCSTR optional), SourcePathRoot (LPCSTR optional), DestinationName (LPCSTR optional), CopyStyle (SP_COPY_STYLE), CopyMsgHandler (PSP_FILE_CALLBACK_A optional), Context (void* optional)
r1, _, err := procSetupInstallFileA.Call(
	uintptr(InfHandle),
	uintptr(InfContext),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SourceFile))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SourcePathRoot))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DestinationName))),
	uintptr(CopyStyle),
	uintptr(CopyMsgHandler),
	uintptr(Context),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupInstallFileA(
  InfHandle: Pointer;   // void* optional
  InfContext: Pointer;   // INFCONTEXT* optional
  SourceFile: PAnsiChar;   // LPCSTR optional
  SourcePathRoot: PAnsiChar;   // LPCSTR optional
  DestinationName: PAnsiChar;   // LPCSTR optional
  CopyStyle: DWORD;   // SP_COPY_STYLE
  CopyMsgHandler: Pointer;   // PSP_FILE_CALLBACK_A optional
  Context: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupInstallFileA';
result := DllCall("SETUPAPI\SetupInstallFileA"
    , "Ptr", InfHandle   ; void* optional
    , "Ptr", InfContext   ; INFCONTEXT* optional
    , "AStr", SourceFile   ; LPCSTR optional
    , "AStr", SourcePathRoot   ; LPCSTR optional
    , "AStr", DestinationName   ; LPCSTR optional
    , "UInt", CopyStyle   ; SP_COPY_STYLE
    , "Ptr", CopyMsgHandler   ; PSP_FILE_CALLBACK_A optional
    , "Ptr", Context   ; void* optional
    , "Int")   ; return: BOOL
●SetupInstallFileA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context) = DLL("SETUPAPI.dll", "bool SetupInstallFileA(void*, void*, char*, char*, char*, dword, void*, void*)")
# 呼び出し: SetupInstallFileA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context)
# InfHandle : void* optional -> "void*"
# InfContext : INFCONTEXT* optional -> "void*"
# SourceFile : LPCSTR optional -> "char*"
# SourcePathRoot : LPCSTR optional -> "char*"
# DestinationName : LPCSTR optional -> "char*"
# CopyStyle : SP_COPY_STYLE -> "dword"
# CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> "void*"
# Context : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。