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

SetupQueueCopyW

関数
ファイルキューにコピー操作を追加する(Unicode)。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupQueueCopyW(
    void* QueueHandle,
    LPCWSTR SourceRootPath,   // optional
    LPCWSTR SourcePath,   // optional
    LPCWSTR SourceFilename,
    LPCWSTR SourceDescription,   // optional
    LPCWSTR SourceTagfile,   // optional
    LPCWSTR TargetDirectory,
    LPCWSTR TargetFilename,   // optional
    DWORD CopyStyle
);

パラメーター

名前方向説明
QueueHandlevoid*inSetupOpenFileQueueで取得したファイルキューのハンドル。コピー操作を登録する対象を指す。
SourceRootPathLPCWSTRinoptionalソースファイルが存在するルートパス。配布メディアの先頭ディレクトリを示す。
SourcePathLPCWSTRinoptionalソースルート配下の相対パス部分。不要ならNULL指定可。
SourceFilenameLPCWSTRinコピー元のファイル名のみを指定する。圧縮名でも可。
SourceDescriptionLPCWSTRinoptionalプロンプト表示時に用いるソースの説明文字列。NULL可。
SourceTagfileLPCWSTRinoptionalソースメディアを識別するタグファイル名。NULL可。
TargetDirectoryLPCWSTRinコピー先の絶対ディレクトリパスを指定する。
TargetFilenameLPCWSTRinoptionalコピー先のファイル名。NULLならソース名を流用する。
CopyStyleDWORDinSP_COPY_*系のコピー動作フラグ。上書きや遅延の挙動を制御する。

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupQueueCopyW(
    void* QueueHandle,
    LPCWSTR SourceRootPath,   // optional
    LPCWSTR SourcePath,   // optional
    LPCWSTR SourceFilename,
    LPCWSTR SourceDescription,   // optional
    LPCWSTR SourceTagfile,   // optional
    LPCWSTR TargetDirectory,
    LPCWSTR TargetFilename,   // optional
    DWORD CopyStyle
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupQueueCopyW(
    IntPtr QueueHandle,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string SourceRootPath,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string SourcePath,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string SourceFilename,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string SourceDescription,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string SourceTagfile,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string TargetDirectory,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string TargetFilename,   // LPCWSTR optional
    uint CopyStyle   // DWORD
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupQueueCopyW(
    QueueHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> SourceRootPath As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> SourcePath As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> SourceFilename As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> SourceDescription As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> SourceTagfile As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> TargetDirectory As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> TargetFilename As String,   ' LPCWSTR optional
    CopyStyle As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' QueueHandle : void*
' SourceRootPath : LPCWSTR optional
' SourcePath : LPCWSTR optional
' SourceFilename : LPCWSTR
' SourceDescription : LPCWSTR optional
' SourceTagfile : LPCWSTR optional
' TargetDirectory : LPCWSTR
' TargetFilename : LPCWSTR optional
' CopyStyle : DWORD
Declare PtrSafe Function SetupQueueCopyW Lib "setupapi" ( _
    ByVal QueueHandle As LongPtr, _
    ByVal SourceRootPath As LongPtr, _
    ByVal SourcePath As LongPtr, _
    ByVal SourceFilename As LongPtr, _
    ByVal SourceDescription As LongPtr, _
    ByVal SourceTagfile As LongPtr, _
    ByVal TargetDirectory As LongPtr, _
    ByVal TargetFilename As LongPtr, _
    ByVal CopyStyle 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

SetupQueueCopyW = ctypes.windll.setupapi.SetupQueueCopyW
SetupQueueCopyW.restype = wintypes.BOOL
SetupQueueCopyW.argtypes = [
    ctypes.POINTER(None),  # QueueHandle : void*
    wintypes.LPCWSTR,  # SourceRootPath : LPCWSTR optional
    wintypes.LPCWSTR,  # SourcePath : LPCWSTR optional
    wintypes.LPCWSTR,  # SourceFilename : LPCWSTR
    wintypes.LPCWSTR,  # SourceDescription : LPCWSTR optional
    wintypes.LPCWSTR,  # SourceTagfile : LPCWSTR optional
    wintypes.LPCWSTR,  # TargetDirectory : LPCWSTR
    wintypes.LPCWSTR,  # TargetFilename : LPCWSTR optional
    wintypes.DWORD,  # CopyStyle : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupQueueCopyW = Fiddle::Function.new(
  lib['SetupQueueCopyW'],
  [
    Fiddle::TYPE_VOIDP,  # QueueHandle : void*
    Fiddle::TYPE_VOIDP,  # SourceRootPath : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # SourcePath : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # SourceFilename : LPCWSTR
    Fiddle::TYPE_VOIDP,  # SourceDescription : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # SourceTagfile : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # TargetDirectory : LPCWSTR
    Fiddle::TYPE_VOIDP,  # TargetFilename : LPCWSTR optional
    -Fiddle::TYPE_INT,  # CopyStyle : DWORD
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupQueueCopyW(
        QueueHandle: *mut (),  // void*
        SourceRootPath: *const u16,  // LPCWSTR optional
        SourcePath: *const u16,  // LPCWSTR optional
        SourceFilename: *const u16,  // LPCWSTR
        SourceDescription: *const u16,  // LPCWSTR optional
        SourceTagfile: *const u16,  // LPCWSTR optional
        TargetDirectory: *const u16,  // LPCWSTR
        TargetFilename: *const u16,  // LPCWSTR optional
        CopyStyle: u32  // DWORD
    ) -> 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 SetupQueueCopyW(IntPtr QueueHandle, [MarshalAs(UnmanagedType.LPWStr)] string SourceRootPath, [MarshalAs(UnmanagedType.LPWStr)] string SourcePath, [MarshalAs(UnmanagedType.LPWStr)] string SourceFilename, [MarshalAs(UnmanagedType.LPWStr)] string SourceDescription, [MarshalAs(UnmanagedType.LPWStr)] string SourceTagfile, [MarshalAs(UnmanagedType.LPWStr)] string TargetDirectory, [MarshalAs(UnmanagedType.LPWStr)] string TargetFilename, uint CopyStyle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupQueueCopyW' -Namespace Win32 -PassThru
# $api::SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle)
#uselib "SETUPAPI.dll"
#func global SetupQueueCopyW "SetupQueueCopyW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupQueueCopyW QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle   ; 戻り値は stat
; QueueHandle : void* -> "wptr"
; SourceRootPath : LPCWSTR optional -> "wptr"
; SourcePath : LPCWSTR optional -> "wptr"
; SourceFilename : LPCWSTR -> "wptr"
; SourceDescription : LPCWSTR optional -> "wptr"
; SourceTagfile : LPCWSTR optional -> "wptr"
; TargetDirectory : LPCWSTR -> "wptr"
; TargetFilename : LPCWSTR optional -> "wptr"
; CopyStyle : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SETUPAPI.dll"
#cfunc global SetupQueueCopyW "SetupQueueCopyW" sptr, wstr, wstr, wstr, wstr, wstr, wstr, wstr, int
; res = SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle)
; QueueHandle : void* -> "sptr"
; SourceRootPath : LPCWSTR optional -> "wstr"
; SourcePath : LPCWSTR optional -> "wstr"
; SourceFilename : LPCWSTR -> "wstr"
; SourceDescription : LPCWSTR optional -> "wstr"
; SourceTagfile : LPCWSTR optional -> "wstr"
; TargetDirectory : LPCWSTR -> "wstr"
; TargetFilename : LPCWSTR optional -> "wstr"
; CopyStyle : DWORD -> "int"
; BOOL SetupQueueCopyW(void* QueueHandle, LPCWSTR SourceRootPath, LPCWSTR SourcePath, LPCWSTR SourceFilename, LPCWSTR SourceDescription, LPCWSTR SourceTagfile, LPCWSTR TargetDirectory, LPCWSTR TargetFilename, DWORD CopyStyle)
#uselib "SETUPAPI.dll"
#cfunc global SetupQueueCopyW "SetupQueueCopyW" intptr, wstr, wstr, wstr, wstr, wstr, wstr, wstr, int
; res = SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle)
; QueueHandle : void* -> "intptr"
; SourceRootPath : LPCWSTR optional -> "wstr"
; SourcePath : LPCWSTR optional -> "wstr"
; SourceFilename : LPCWSTR -> "wstr"
; SourceDescription : LPCWSTR optional -> "wstr"
; SourceTagfile : LPCWSTR optional -> "wstr"
; TargetDirectory : LPCWSTR -> "wstr"
; TargetFilename : LPCWSTR optional -> "wstr"
; CopyStyle : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupQueueCopyW = setupapi.NewProc("SetupQueueCopyW")
)

// QueueHandle (void*), SourceRootPath (LPCWSTR optional), SourcePath (LPCWSTR optional), SourceFilename (LPCWSTR), SourceDescription (LPCWSTR optional), SourceTagfile (LPCWSTR optional), TargetDirectory (LPCWSTR), TargetFilename (LPCWSTR optional), CopyStyle (DWORD)
r1, _, err := procSetupQueueCopyW.Call(
	uintptr(QueueHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceRootPath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourcePath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceFilename))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceDescription))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceTagfile))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetDirectory))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetFilename))),
	uintptr(CopyStyle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupQueueCopyW(
  QueueHandle: Pointer;   // void*
  SourceRootPath: PWideChar;   // LPCWSTR optional
  SourcePath: PWideChar;   // LPCWSTR optional
  SourceFilename: PWideChar;   // LPCWSTR
  SourceDescription: PWideChar;   // LPCWSTR optional
  SourceTagfile: PWideChar;   // LPCWSTR optional
  TargetDirectory: PWideChar;   // LPCWSTR
  TargetFilename: PWideChar;   // LPCWSTR optional
  CopyStyle: DWORD   // DWORD
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupQueueCopyW';
result := DllCall("SETUPAPI\SetupQueueCopyW"
    , "Ptr", QueueHandle   ; void*
    , "WStr", SourceRootPath   ; LPCWSTR optional
    , "WStr", SourcePath   ; LPCWSTR optional
    , "WStr", SourceFilename   ; LPCWSTR
    , "WStr", SourceDescription   ; LPCWSTR optional
    , "WStr", SourceTagfile   ; LPCWSTR optional
    , "WStr", TargetDirectory   ; LPCWSTR
    , "WStr", TargetFilename   ; LPCWSTR optional
    , "UInt", CopyStyle   ; DWORD
    , "Int")   ; return: BOOL
●SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle) = DLL("SETUPAPI.dll", "bool SetupQueueCopyW(void*, char*, char*, char*, char*, char*, char*, char*, dword)")
# 呼び出し: SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle)
# QueueHandle : void* -> "void*"
# SourceRootPath : LPCWSTR optional -> "char*"
# SourcePath : LPCWSTR optional -> "char*"
# SourceFilename : LPCWSTR -> "char*"
# SourceDescription : LPCWSTR optional -> "char*"
# SourceTagfile : LPCWSTR optional -> "char*"
# TargetDirectory : LPCWSTR -> "char*"
# TargetFilename : LPCWSTR optional -> "char*"
# CopyStyle : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "setupapi" fn SetupQueueCopyW(
    QueueHandle: ?*anyopaque, // void*
    SourceRootPath: [*c]const u16, // LPCWSTR optional
    SourcePath: [*c]const u16, // LPCWSTR optional
    SourceFilename: [*c]const u16, // LPCWSTR
    SourceDescription: [*c]const u16, // LPCWSTR optional
    SourceTagfile: [*c]const u16, // LPCWSTR optional
    TargetDirectory: [*c]const u16, // LPCWSTR
    TargetFilename: [*c]const u16, // LPCWSTR optional
    CopyStyle: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetupQueueCopyW(
    QueueHandle: pointer,  # void*
    SourceRootPath: WideCString,  # LPCWSTR optional
    SourcePath: WideCString,  # LPCWSTR optional
    SourceFilename: WideCString,  # LPCWSTR
    SourceDescription: WideCString,  # LPCWSTR optional
    SourceTagfile: WideCString,  # LPCWSTR optional
    TargetDirectory: WideCString,  # LPCWSTR
    TargetFilename: WideCString,  # LPCWSTR optional
    CopyStyle: uint32  # DWORD
): int32 {.importc: "SetupQueueCopyW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
int SetupQueueCopyW(
    void* QueueHandle,   // void*
    const(wchar)* SourceRootPath,   // LPCWSTR optional
    const(wchar)* SourcePath,   // LPCWSTR optional
    const(wchar)* SourceFilename,   // LPCWSTR
    const(wchar)* SourceDescription,   // LPCWSTR optional
    const(wchar)* SourceTagfile,   // LPCWSTR optional
    const(wchar)* TargetDirectory,   // LPCWSTR
    const(wchar)* TargetFilename,   // LPCWSTR optional
    uint CopyStyle   // DWORD
);
ccall((:SetupQueueCopyW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, Cwstring, Cwstring, Cwstring, Cwstring, Cwstring, Cwstring, UInt32),
      QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle)
# QueueHandle : void* -> Ptr{Cvoid}
# SourceRootPath : LPCWSTR optional -> Cwstring
# SourcePath : LPCWSTR optional -> Cwstring
# SourceFilename : LPCWSTR -> Cwstring
# SourceDescription : LPCWSTR optional -> Cwstring
# SourceTagfile : LPCWSTR optional -> Cwstring
# TargetDirectory : LPCWSTR -> Cwstring
# TargetFilename : LPCWSTR optional -> Cwstring
# CopyStyle : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupQueueCopyW(
    void* QueueHandle,
    const uint16_t* SourceRootPath,
    const uint16_t* SourcePath,
    const uint16_t* SourceFilename,
    const uint16_t* SourceDescription,
    const uint16_t* SourceTagfile,
    const uint16_t* TargetDirectory,
    const uint16_t* TargetFilename,
    uint32_t CopyStyle);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle)
-- QueueHandle : void*
-- SourceRootPath : LPCWSTR optional
-- SourcePath : LPCWSTR optional
-- SourceFilename : LPCWSTR
-- SourceDescription : LPCWSTR optional
-- SourceTagfile : LPCWSTR optional
-- TargetDirectory : LPCWSTR
-- TargetFilename : LPCWSTR optional
-- CopyStyle : DWORD
-- 構造体/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 SetupQueueCopyW = lib.func('__stdcall', 'SetupQueueCopyW', 'int32_t', ['void *', 'str16', 'str16', 'str16', 'str16', 'str16', 'str16', 'str16', 'uint32_t']);
// SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle)
// QueueHandle : void* -> 'void *'
// SourceRootPath : LPCWSTR optional -> 'str16'
// SourcePath : LPCWSTR optional -> 'str16'
// SourceFilename : LPCWSTR -> 'str16'
// SourceDescription : LPCWSTR optional -> 'str16'
// SourceTagfile : LPCWSTR optional -> 'str16'
// TargetDirectory : LPCWSTR -> 'str16'
// TargetFilename : LPCWSTR optional -> 'str16'
// CopyStyle : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupQueueCopyW: { parameters: ["pointer", "buffer", "buffer", "buffer", "buffer", "buffer", "buffer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle)
// QueueHandle : void* -> "pointer"
// SourceRootPath : LPCWSTR optional -> "buffer"
// SourcePath : LPCWSTR optional -> "buffer"
// SourceFilename : LPCWSTR -> "buffer"
// SourceDescription : LPCWSTR optional -> "buffer"
// SourceTagfile : LPCWSTR optional -> "buffer"
// TargetDirectory : LPCWSTR -> "buffer"
// TargetFilename : LPCWSTR optional -> "buffer"
// CopyStyle : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupQueueCopyW(
    void* QueueHandle,
    const uint16_t* SourceRootPath,
    const uint16_t* SourcePath,
    const uint16_t* SourceFilename,
    const uint16_t* SourceDescription,
    const uint16_t* SourceTagfile,
    const uint16_t* TargetDirectory,
    const uint16_t* TargetFilename,
    uint32_t CopyStyle);
C, "SETUPAPI.dll");
// $ffi->SetupQueueCopyW(QueueHandle, SourceRootPath, SourcePath, SourceFilename, SourceDescription, SourceTagfile, TargetDirectory, TargetFilename, CopyStyle);
// QueueHandle : void*
// SourceRootPath : LPCWSTR optional
// SourcePath : LPCWSTR optional
// SourceFilename : LPCWSTR
// SourceDescription : LPCWSTR optional
// SourceTagfile : LPCWSTR optional
// TargetDirectory : LPCWSTR
// TargetFilename : LPCWSTR optional
// CopyStyle : DWORD
// 構造体/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 SetupQueueCopyW(
        Pointer QueueHandle,   // void*
        WString SourceRootPath,   // LPCWSTR optional
        WString SourcePath,   // LPCWSTR optional
        WString SourceFilename,   // LPCWSTR
        WString SourceDescription,   // LPCWSTR optional
        WString SourceTagfile,   // LPCWSTR optional
        WString TargetDirectory,   // LPCWSTR
        WString TargetFilename,   // LPCWSTR optional
        int CopyStyle   // DWORD
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupQueueCopyW = SetupQueueCopyW(
    QueueHandle : Void*,   # void*
    SourceRootPath : UInt16*,   # LPCWSTR optional
    SourcePath : UInt16*,   # LPCWSTR optional
    SourceFilename : UInt16*,   # LPCWSTR
    SourceDescription : UInt16*,   # LPCWSTR optional
    SourceTagfile : UInt16*,   # LPCWSTR optional
    TargetDirectory : UInt16*,   # LPCWSTR
    TargetFilename : UInt16*,   # LPCWSTR optional
    CopyStyle : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupQueueCopyWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef SetupQueueCopyWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int);
final SetupQueueCopyW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupQueueCopyWNative, SetupQueueCopyWDart>('SetupQueueCopyW');
// QueueHandle : void* -> Pointer<Void>
// SourceRootPath : LPCWSTR optional -> Pointer<Utf16>
// SourcePath : LPCWSTR optional -> Pointer<Utf16>
// SourceFilename : LPCWSTR -> Pointer<Utf16>
// SourceDescription : LPCWSTR optional -> Pointer<Utf16>
// SourceTagfile : LPCWSTR optional -> Pointer<Utf16>
// TargetDirectory : LPCWSTR -> Pointer<Utf16>
// TargetFilename : LPCWSTR optional -> Pointer<Utf16>
// CopyStyle : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupQueueCopyW(
  QueueHandle: Pointer;   // void*
  SourceRootPath: PWideChar;   // LPCWSTR optional
  SourcePath: PWideChar;   // LPCWSTR optional
  SourceFilename: PWideChar;   // LPCWSTR
  SourceDescription: PWideChar;   // LPCWSTR optional
  SourceTagfile: PWideChar;   // LPCWSTR optional
  TargetDirectory: PWideChar;   // LPCWSTR
  TargetFilename: PWideChar;   // LPCWSTR optional
  CopyStyle: DWORD   // DWORD
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupQueueCopyW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupQueueCopyW"
  c_SetupQueueCopyW :: Ptr () -> CWString -> CWString -> CWString -> CWString -> CWString -> CWString -> CWString -> Word32 -> IO CInt
-- QueueHandle : void* -> Ptr ()
-- SourceRootPath : LPCWSTR optional -> CWString
-- SourcePath : LPCWSTR optional -> CWString
-- SourceFilename : LPCWSTR -> CWString
-- SourceDescription : LPCWSTR optional -> CWString
-- SourceTagfile : LPCWSTR optional -> CWString
-- TargetDirectory : LPCWSTR -> CWString
-- TargetFilename : LPCWSTR optional -> CWString
-- CopyStyle : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupqueuecopyw =
  foreign "SetupQueueCopyW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* QueueHandle : void* -> (ptr void) *)
(* SourceRootPath : LPCWSTR optional -> (ptr uint16_t) *)
(* SourcePath : LPCWSTR optional -> (ptr uint16_t) *)
(* SourceFilename : LPCWSTR -> (ptr uint16_t) *)
(* SourceDescription : LPCWSTR optional -> (ptr uint16_t) *)
(* SourceTagfile : LPCWSTR optional -> (ptr uint16_t) *)
(* TargetDirectory : LPCWSTR -> (ptr uint16_t) *)
(* TargetFilename : LPCWSTR optional -> (ptr uint16_t) *)
(* CopyStyle : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupQueueCopyW" setup-queue-copy-w :convention :stdcall) :int32
  (queue-handle :pointer)   ; void*
  (source-root-path (:string :encoding :utf-16le))   ; LPCWSTR optional
  (source-path (:string :encoding :utf-16le))   ; LPCWSTR optional
  (source-filename (:string :encoding :utf-16le))   ; LPCWSTR
  (source-description (:string :encoding :utf-16le))   ; LPCWSTR optional
  (source-tagfile (:string :encoding :utf-16le))   ; LPCWSTR optional
  (target-directory (:string :encoding :utf-16le))   ; LPCWSTR
  (target-filename (:string :encoding :utf-16le))   ; LPCWSTR optional
  (copy-style :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupQueueCopyW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupQueueCopyW(LPVOID QueueHandle, LPCWSTR SourceRootPath, LPCWSTR SourcePath, LPCWSTR SourceFilename, LPCWSTR SourceDescription, LPCWSTR SourceTagfile, LPCWSTR TargetDirectory, LPCWSTR TargetFilename, DWORD CopyStyle)');
# my $ret = $SetupQueueCopyW->Call($QueueHandle, $SourceRootPath, $SourcePath, $SourceFilename, $SourceDescription, $SourceTagfile, $TargetDirectory, $TargetFilename, $CopyStyle);
# QueueHandle : void* -> LPVOID
# SourceRootPath : LPCWSTR optional -> LPCWSTR
# SourcePath : LPCWSTR optional -> LPCWSTR
# SourceFilename : LPCWSTR -> LPCWSTR
# SourceDescription : LPCWSTR optional -> LPCWSTR
# SourceTagfile : LPCWSTR optional -> LPCWSTR
# TargetDirectory : LPCWSTR -> LPCWSTR
# TargetFilename : LPCWSTR optional -> LPCWSTR
# CopyStyle : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い