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

SetupInstallFileW

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

シグネチャ

// 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
);

パラメーター

名前方向説明
InfHandlevoid*inoptional対象の開いているINFハンドル。NULL可。
InfContextINFCONTEXT*inoptionalコピー情報を含む行を示すINFCONTEXT構造体へのポインタ。NULL可。
SourceFileLPCWSTRinoptionalコピー元ファイル名(Unicode)。InfContext使用時はNULL可。
SourcePathRootLPCWSTRinoptionalソースのルートパス(Unicode)。NULL可。
DestinationNameLPCWSTRinoptionalコピー先のファイル名(Unicode)。NULLで元名を使う。
CopyStyleSP_COPY_STYLEinコピー動作を制御するスタイルフラグ。上書きやバージョン確認等を指定する。
CopyMsgHandlerPSP_FILE_CALLBACK_Winoptionalコピー進行を通知するコールバック関数。NULL可。
Contextvoid*inoptionalコールバックへ渡す任意のユーザーコンテキスト。NULL可。

戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // BOOL
function 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 版の利用を推奨。
const std = @import("std");

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

typedef SetupInstallFileWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Void>);
typedef SetupInstallFileWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>);
final SetupInstallFileW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupInstallFileWNative, SetupInstallFileWDart>('SetupInstallFileW');
// InfHandle : void* optional -> Pointer<Void>
// InfContext : INFCONTEXT* optional -> Pointer<Void>
// SourceFile : LPCWSTR optional -> Pointer<Utf16>
// SourcePathRoot : LPCWSTR optional -> Pointer<Utf16>
// DestinationName : LPCWSTR optional -> Pointer<Utf16>
// CopyStyle : SP_COPY_STYLE -> Uint32
// CopyMsgHandler : PSP_FILE_CALLBACK_W optional -> Pointer<Void>
// Context : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function 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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

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

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

関連項目

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