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

SetupInstallFileExA

関数
使用中状態の通知付きで単一ファイルをインストールする(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupInstallFileExA(
    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
    BOOL* FileWasInUse
);

パラメーター

名前方向説明
InfHandlevoid*inoptional対象の開いているINFハンドル。NULL可。
InfContextINFCONTEXT*inoptionalコピー情報を含む行を示すINFCONTEXT構造体へのポインタ。NULL可。
SourceFileLPCSTRinoptionalコピー元ファイル名(ANSI)。InfContext使用時はNULL可。
SourcePathRootLPCSTRinoptionalソースのルートパス(ANSI)。NULL可。
DestinationNameLPCSTRinoptionalコピー先のファイル名(ANSI)。NULLで元名を使う。
CopyStyleSP_COPY_STYLEinコピー動作を制御するスタイルフラグ。上書きやバージョン確認等を指定する。
CopyMsgHandlerPSP_FILE_CALLBACK_Ainoptionalコピー進行を通知するコールバック関数。NULL可。
Contextvoid*inoptionalコールバックへ渡す任意のユーザーコンテキスト。NULL可。
FileWasInUseBOOL*out対象ファイルが使用中で再起動が必要かを受け取る出力ポインタ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupInstallFileExA(
    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
    BOOL* FileWasInUse
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupInstallFileExA(
    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
    out bool FileWasInUse   // BOOL* out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupInstallFileExA(
    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
    <Out> ByRef FileWasInUse As Boolean   ' BOOL* out
) As <MarshalAs(UnmanagedType.Bool)> 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
' FileWasInUse : BOOL* out
Declare PtrSafe Function SetupInstallFileExA 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, _
    ByRef FileWasInUse As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupInstallFileExA = setupapi.NewProc("SetupInstallFileExA")
)

// 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), FileWasInUse (BOOL* out)
r1, _, err := procSetupInstallFileExA.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),
	uintptr(FileWasInUse),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupInstallFileExA(
  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
  FileWasInUse: Pointer   // BOOL* out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupInstallFileExA';
result := DllCall("SETUPAPI\SetupInstallFileExA"
    , "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
    , "Ptr", FileWasInUse   ; BOOL* out
    , "Int")   ; return: BOOL
●SetupInstallFileExA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse) = DLL("SETUPAPI.dll", "bool SetupInstallFileExA(void*, void*, char*, char*, char*, dword, void*, void*, void*)")
# 呼び出し: SetupInstallFileExA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse)
# 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*"
# FileWasInUse : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupInstallFileExA(
    InfHandle: ?*anyopaque, // void* optional
    InfContext: [*c]INFCONTEXT, // INFCONTEXT* optional
    SourceFile: [*c]const u8, // LPCSTR optional
    SourcePathRoot: [*c]const u8, // LPCSTR optional
    DestinationName: [*c]const u8, // LPCSTR optional
    CopyStyle: u32, // SP_COPY_STYLE
    CopyMsgHandler: ?*anyopaque, // PSP_FILE_CALLBACK_A optional
    Context: ?*anyopaque, // void* optional
    FileWasInUse: [*c]i32 // BOOL* out
) callconv(std.os.windows.WINAPI) i32;
proc SetupInstallFileExA(
    InfHandle: pointer,  # void* optional
    InfContext: ptr INFCONTEXT,  # INFCONTEXT* optional
    SourceFile: cstring,  # LPCSTR optional
    SourcePathRoot: cstring,  # LPCSTR optional
    DestinationName: cstring,  # LPCSTR optional
    CopyStyle: uint32,  # SP_COPY_STYLE
    CopyMsgHandler: pointer,  # PSP_FILE_CALLBACK_A optional
    Context: pointer,  # void* optional
    FileWasInUse: ptr int32  # BOOL* out
): int32 {.importc: "SetupInstallFileExA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupInstallFileExA(
    void* InfHandle,   // void* optional
    INFCONTEXT* InfContext,   // INFCONTEXT* optional
    const(char)* SourceFile,   // LPCSTR optional
    const(char)* SourcePathRoot,   // LPCSTR optional
    const(char)* DestinationName,   // LPCSTR optional
    uint CopyStyle,   // SP_COPY_STYLE
    void* CopyMsgHandler,   // PSP_FILE_CALLBACK_A optional
    void* Context,   // void* optional
    int* FileWasInUse   // BOOL* out
);
ccall((:SetupInstallFileExA, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{INFCONTEXT}, Cstring, Cstring, Cstring, UInt32, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Int32}),
      InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse)
# InfHandle : void* optional -> Ptr{Cvoid}
# InfContext : INFCONTEXT* optional -> Ptr{INFCONTEXT}
# SourceFile : LPCSTR optional -> Cstring
# SourcePathRoot : LPCSTR optional -> Cstring
# DestinationName : LPCSTR optional -> Cstring
# CopyStyle : SP_COPY_STYLE -> UInt32
# CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> Ptr{Cvoid}
# Context : void* optional -> Ptr{Cvoid}
# FileWasInUse : BOOL* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupInstallFileExA(
    void* InfHandle,
    void* InfContext,
    const char* SourceFile,
    const char* SourcePathRoot,
    const char* DestinationName,
    uint32_t CopyStyle,
    void* CopyMsgHandler,
    void* Context,
    int32_t* FileWasInUse);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupInstallFileExA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse)
-- 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
-- FileWasInUse : BOOL* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupInstallFileExA = lib.func('__stdcall', 'SetupInstallFileExA', 'int32_t', ['void *', 'void *', 'str', 'str', 'str', 'uint32_t', 'void *', 'void *', 'int32_t *']);
// SetupInstallFileExA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse)
// InfHandle : void* optional -> 'void *'
// InfContext : INFCONTEXT* optional -> 'void *'
// SourceFile : LPCSTR optional -> 'str'
// SourcePathRoot : LPCSTR optional -> 'str'
// DestinationName : LPCSTR optional -> 'str'
// CopyStyle : SP_COPY_STYLE -> 'uint32_t'
// CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> 'void *'
// Context : void* optional -> 'void *'
// FileWasInUse : BOOL* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupInstallFileExA: { parameters: ["pointer", "pointer", "buffer", "buffer", "buffer", "u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SetupInstallFileExA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse)
// InfHandle : void* optional -> "pointer"
// InfContext : INFCONTEXT* optional -> "pointer"
// SourceFile : LPCSTR optional -> "buffer"
// SourcePathRoot : LPCSTR optional -> "buffer"
// DestinationName : LPCSTR optional -> "buffer"
// CopyStyle : SP_COPY_STYLE -> "u32"
// CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> "pointer"
// Context : void* optional -> "pointer"
// FileWasInUse : BOOL* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupInstallFileExA(
    void* InfHandle,
    void* InfContext,
    const char* SourceFile,
    const char* SourcePathRoot,
    const char* DestinationName,
    uint32_t CopyStyle,
    void* CopyMsgHandler,
    void* Context,
    int32_t* FileWasInUse);
C, "SETUPAPI.dll");
// $ffi->SetupInstallFileExA(InfHandle, InfContext, SourceFile, SourcePathRoot, DestinationName, CopyStyle, CopyMsgHandler, Context, FileWasInUse);
// 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
// FileWasInUse : BOOL* out
// 構造体/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.ASCII_OPTIONS);
    boolean SetupInstallFileExA(
        Pointer InfHandle,   // void* optional
        Pointer InfContext,   // INFCONTEXT* optional
        String SourceFile,   // LPCSTR optional
        String SourcePathRoot,   // LPCSTR optional
        String DestinationName,   // LPCSTR optional
        int CopyStyle,   // SP_COPY_STYLE
        Callback CopyMsgHandler,   // PSP_FILE_CALLBACK_A optional
        Pointer Context,   // void* optional
        IntByReference FileWasInUse   // BOOL* out
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupInstallFileExA = SetupInstallFileExA(
    InfHandle : Void*,   # void* optional
    InfContext : INFCONTEXT*,   # INFCONTEXT* optional
    SourceFile : UInt8*,   # LPCSTR optional
    SourcePathRoot : UInt8*,   # LPCSTR optional
    DestinationName : UInt8*,   # LPCSTR optional
    CopyStyle : UInt32,   # SP_COPY_STYLE
    CopyMsgHandler : Void*,   # PSP_FILE_CALLBACK_A optional
    Context : Void*,   # void* optional
    FileWasInUse : Int32*   # BOOL* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupInstallFileExANative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Int32>);
typedef SetupInstallFileExADart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Void>, Pointer<Void>, Pointer<Int32>);
final SetupInstallFileExA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupInstallFileExANative, SetupInstallFileExADart>('SetupInstallFileExA');
// InfHandle : void* optional -> Pointer<Void>
// InfContext : INFCONTEXT* optional -> Pointer<Void>
// SourceFile : LPCSTR optional -> Pointer<Utf8>
// SourcePathRoot : LPCSTR optional -> Pointer<Utf8>
// DestinationName : LPCSTR optional -> Pointer<Utf8>
// CopyStyle : SP_COPY_STYLE -> Uint32
// CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> Pointer<Void>
// Context : void* optional -> Pointer<Void>
// FileWasInUse : BOOL* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupInstallFileExA(
  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
  FileWasInUse: Pointer   // BOOL* out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupInstallFileExA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupInstallFileExA"
  c_SetupInstallFileExA :: Ptr () -> Ptr () -> CString -> CString -> CString -> Word32 -> Ptr () -> Ptr () -> Ptr CInt -> IO CInt
-- InfHandle : void* optional -> Ptr ()
-- InfContext : INFCONTEXT* optional -> Ptr ()
-- SourceFile : LPCSTR optional -> CString
-- SourcePathRoot : LPCSTR optional -> CString
-- DestinationName : LPCSTR optional -> CString
-- CopyStyle : SP_COPY_STYLE -> Word32
-- CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> Ptr ()
-- Context : void* optional -> Ptr ()
-- FileWasInUse : BOOL* out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupinstallfileexa =
  foreign "SetupInstallFileExA"
    ((ptr void) @-> (ptr void) @-> string @-> string @-> string @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* InfHandle : void* optional -> (ptr void) *)
(* InfContext : INFCONTEXT* optional -> (ptr void) *)
(* SourceFile : LPCSTR optional -> string *)
(* SourcePathRoot : LPCSTR optional -> string *)
(* DestinationName : LPCSTR optional -> string *)
(* CopyStyle : SP_COPY_STYLE -> uint32_t *)
(* CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> (ptr void) *)
(* Context : void* optional -> (ptr void) *)
(* FileWasInUse : BOOL* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupInstallFileExA" setup-install-file-ex-a :convention :stdcall) :int32
  (inf-handle :pointer)   ; void* optional
  (inf-context :pointer)   ; INFCONTEXT* optional
  (source-file :string)   ; LPCSTR optional
  (source-path-root :string)   ; LPCSTR optional
  (destination-name :string)   ; LPCSTR optional
  (copy-style :uint32)   ; SP_COPY_STYLE
  (copy-msg-handler :pointer)   ; PSP_FILE_CALLBACK_A optional
  (context :pointer)   ; void* optional
  (file-was-in-use :pointer))   ; BOOL* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupInstallFileExA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupInstallFileExA(LPVOID InfHandle, LPVOID InfContext, LPCSTR SourceFile, LPCSTR SourcePathRoot, LPCSTR DestinationName, DWORD CopyStyle, LPVOID CopyMsgHandler, LPVOID Context, LPVOID FileWasInUse)');
# my $ret = $SetupInstallFileExA->Call($InfHandle, $InfContext, $SourceFile, $SourcePathRoot, $DestinationName, $CopyStyle, $CopyMsgHandler, $Context, $FileWasInUse);
# InfHandle : void* optional -> LPVOID
# InfContext : INFCONTEXT* optional -> LPVOID
# SourceFile : LPCSTR optional -> LPCSTR
# SourcePathRoot : LPCSTR optional -> LPCSTR
# DestinationName : LPCSTR optional -> LPCSTR
# CopyStyle : SP_COPY_STYLE -> DWORD
# CopyMsgHandler : PSP_FILE_CALLBACK_A optional -> LPVOID
# Context : void* optional -> LPVOID
# FileWasInUse : BOOL* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

文字セット違い
類似 API
使用する型