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

SetupCopyErrorW

関数
ファイルコピーエラーを通知するダイアログを表示する(Unicode)。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD SetupCopyErrorW(
    HWND hwndParent,
    LPCWSTR DialogTitle,   // optional
    LPCWSTR DiskName,   // optional
    LPCWSTR PathToSource,
    LPCWSTR SourceFile,
    LPCWSTR TargetPathFile,   // optional
    DWORD Win32ErrorCode,
    DWORD Style,
    LPWSTR PathBuffer,   // optional
    DWORD PathBufferSize,
    DWORD* PathRequiredSize   // optional
);

パラメーター

名前方向説明
hwndParentHWNDinこのダイアログ ボックスの親ウィンドウのハンドル。
DialogTitleLPCWSTRinoptional

ダイアログ ボックスのタイトルを指定する null 終端文字列への省略可能なポインター。

このパラメーターには NULL を指定できます。NULL を指定した場合は、既定のタイトルである "Copy Error" (システムの言語にローカライズされたもの) が使用されます。

DiskNameLPCWSTRinoptional

挿入するディスクの名前を指定する null 終端文字列への省略可能なポインター。

このパラメーターには NULL を指定できます。NULL を指定した場合は、既定の名前である "(Unknown)" (システムの言語にローカライズされたもの) が使用されます。

PathToSourceLPCWSTRin

操作が失敗したソース ファイルのパス部分へのポインター (例: F:\x86)。

null 終端文字列を使用してください。

SourceFileLPCWSTRin

操作が失敗したファイルのファイル名部分を指定する null 終端文字列へのポインター。

null 終端文字列を使用してください。このファイル名は、ユーザーが [詳細] ボタンまたは [参照] ボタンをクリックしたときに表示されます。SetupCopyError 関数は、圧縮形式の名前を使用してファイルを検索します。そのため、cmd.exe を渡しても、ソース メディア上に実際には cmd.ex_ として存在していることを気にする必要はありません。

TargetPathFileLPCWSTRinoptional

名前の変更操作およびコピー操作の対象ファイルのフル パスを指定する null 終端文字列への省略可能なポインター。

null 終端文字列を使用してください。このパラメーターには NULL を指定できます。TargetPathFile を指定しない場合は、"(Unknown)" (システムの言語にローカライズされたもの) が使用されます。

Win32ErrorCodeDWORDin

エラーが発生した場合、このメンバーは システム エラー コード です。

エラーが発生しない場合は NO_ERROR です。

StyleDWORDin

ダイアログ ボックスの表示形式と動作を制御するフラグ。

このパラメーターには、次のいずれかのフラグを指定できます。

IDF_NOBROWSE

参照オプションを表示しません。

IDF_NOSKIP

ファイルのスキップ オプションを表示しません。

IDF_NODETAILS

詳細オプションを表示しません。

このフラグを設定した場合、TargetPathFile パラメーターと Win32ErrorCode パラメーターは省略できます。

IDF_NOCOMPRESSED

ソース ファイルの圧縮版を検索しません。

IDF_OEMDISK

操作のソースが、ハードウェア製造元から提供されたディスクであることを示します。

IDF_NOBEEP

ダイアログ ボックスが最初に表示されるときに、ユーザーの注意を引くためのビープ音を鳴らさないようにします。

IDF_NOFOREGROUND

ダイアログ ボックスがフォアグラウンド ウィンドウにならないようにします。

IDF_WARNIFSKIP

ファイルをスキップするとインストールに影響する可能性があることをユーザーに警告します。

PathBufferLPWSTRoutoptional

ユーザーがダイアログ ボックスで指定した場所のパス (ファイル名を除く) を、この関数が返すための変数への省略可能なポインター。null 終端文字列を使用してください。

null 終端文字列は、コピー先バッファーのサイズを超えないようにする必要があります。バッファー不足エラーを避けるため、PathBuffer は少なくとも MAX_PATH のサイズにしてください。 詳細については、このトピックの「解説」セクションを参照してください。

PathBufferSizeDWORDin

PathBuffer が指すバッファーのサイズ (文字単位)。

バッファー サイズは、null 終端文字を含めて少なくとも MAX_PATH 文字にする必要があります。

PathRequiredSizeDWORD*outoptional

必要なバッファー サイズ (null 終端文字を含む文字単位) を、この関数が返すための変数への省略可能なポインター。

- Style.IDF_NOBEEP

ダイアログ ボックスが最初に表示されるときに、ユーザーの注意を引くためのビープ音を鳴らさないようにします。

- Style.IDF_NOBROWSE

参照オプションを表示しません。

- Style.IDF_NOCOMPRESSED

ソース ファイルの圧縮版を検索しません。

- Style.IDF_NODETAILS

詳細オプションを表示しません。

このフラグを設定した場合、TargetPathFile パラメーターと Win32ErrorCode パラメーターは省略できます。

- Style.IDF_NOFOREGROUND

ダイアログ ボックスがフォアグラウンド ウィンドウにならないようにします。

- Style.IDF_NOSKIP

ファイルのスキップ オプションを表示しません。

- Style.IDF_OEMDISK

操作のソースが、ハードウェア製造元から提供されたディスクであることを示します。

- Style.IDF_WARNIFSKIP

ファイルをスキップするとインストールに影響する可能性があることをユーザーに警告します。

戻り値の型: DWORD

公式ドキュメント

SetupCopyError 関数は、ファイルのコピー エラーをユーザーに通知するためのダイアログ ボックスを生成します。(Unicode)

戻り値

この関数は、次のいずれかの値を返します。

拡張エラー情報を取得するには、 GetLastError を呼び出します。

解説(Remarks)

PathBufferNULLPathBufferSize に 0 (ゼロ) を指定してこの関数を呼び出した場合、この関数は、指定されたデータを格納するために必要なバッファー サイズを PathRequiredSize が指す変数に格納します。

関数が成功した場合、戻り値は NO_ERROR です。それ以外の場合、戻り値は規定された値のいずれかになります。

バッファー不足エラーを避けるため、ReturnBuffer は少なくとも MAX_PATH のサイズにしてください。

メモ

setupapi.h ヘッダーは SetupCopyError をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版が自動的に選択されます。エンコードに依存しないエイリアスの使用と、エンコードに依存しないわけではないコードを混在させると、不一致が生じてコンパイル エラーや実行時エラーの原因になることがあります。詳細については、関数プロトタイプの規則を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD SetupCopyErrorW(
    HWND hwndParent,
    LPCWSTR DialogTitle,   // optional
    LPCWSTR DiskName,   // optional
    LPCWSTR PathToSource,
    LPCWSTR SourceFile,
    LPCWSTR TargetPathFile,   // optional
    DWORD Win32ErrorCode,
    DWORD Style,
    LPWSTR PathBuffer,   // optional
    DWORD PathBufferSize,
    DWORD* PathRequiredSize   // optional
);
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint SetupCopyErrorW(
    IntPtr hwndParent,   // HWND
    [MarshalAs(UnmanagedType.LPWStr)] string DialogTitle,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string DiskName,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string PathToSource,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string SourceFile,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string TargetPathFile,   // LPCWSTR optional
    uint Win32ErrorCode,   // DWORD
    uint Style,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder PathBuffer,   // LPWSTR optional, out
    uint PathBufferSize,   // DWORD
    IntPtr PathRequiredSize   // DWORD* optional, out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupCopyErrorW(
    hwndParent As IntPtr,   ' HWND
    <MarshalAs(UnmanagedType.LPWStr)> DialogTitle As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> DiskName As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> PathToSource As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> SourceFile As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> TargetPathFile As String,   ' LPCWSTR optional
    Win32ErrorCode As UInteger,   ' DWORD
    Style As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> PathBuffer As System.Text.StringBuilder,   ' LPWSTR optional, out
    PathBufferSize As UInteger,   ' DWORD
    PathRequiredSize As IntPtr   ' DWORD* optional, out
) As UInteger
End Function
' hwndParent : HWND
' DialogTitle : LPCWSTR optional
' DiskName : LPCWSTR optional
' PathToSource : LPCWSTR
' SourceFile : LPCWSTR
' TargetPathFile : LPCWSTR optional
' Win32ErrorCode : DWORD
' Style : DWORD
' PathBuffer : LPWSTR optional, out
' PathBufferSize : DWORD
' PathRequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupCopyErrorW Lib "setupapi" ( _
    ByVal hwndParent As LongPtr, _
    ByVal DialogTitle As LongPtr, _
    ByVal DiskName As LongPtr, _
    ByVal PathToSource As LongPtr, _
    ByVal SourceFile As LongPtr, _
    ByVal TargetPathFile As LongPtr, _
    ByVal Win32ErrorCode As Long, _
    ByVal Style As Long, _
    ByVal PathBuffer As LongPtr, _
    ByVal PathBufferSize As Long, _
    ByVal PathRequiredSize 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

SetupCopyErrorW = ctypes.windll.setupapi.SetupCopyErrorW
SetupCopyErrorW.restype = wintypes.DWORD
SetupCopyErrorW.argtypes = [
    wintypes.HANDLE,  # hwndParent : HWND
    wintypes.LPCWSTR,  # DialogTitle : LPCWSTR optional
    wintypes.LPCWSTR,  # DiskName : LPCWSTR optional
    wintypes.LPCWSTR,  # PathToSource : LPCWSTR
    wintypes.LPCWSTR,  # SourceFile : LPCWSTR
    wintypes.LPCWSTR,  # TargetPathFile : LPCWSTR optional
    wintypes.DWORD,  # Win32ErrorCode : DWORD
    wintypes.DWORD,  # Style : DWORD
    wintypes.LPWSTR,  # PathBuffer : LPWSTR optional, out
    wintypes.DWORD,  # PathBufferSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # PathRequiredSize : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupCopyErrorW = Fiddle::Function.new(
  lib['SetupCopyErrorW'],
  [
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND
    Fiddle::TYPE_VOIDP,  # DialogTitle : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # DiskName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # PathToSource : LPCWSTR
    Fiddle::TYPE_VOIDP,  # SourceFile : LPCWSTR
    Fiddle::TYPE_VOIDP,  # TargetPathFile : LPCWSTR optional
    -Fiddle::TYPE_INT,  # Win32ErrorCode : DWORD
    -Fiddle::TYPE_INT,  # Style : DWORD
    Fiddle::TYPE_VOIDP,  # PathBuffer : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # PathBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # PathRequiredSize : DWORD* optional, out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupCopyErrorW(
        hwndParent: *mut core::ffi::c_void,  // HWND
        DialogTitle: *const u16,  // LPCWSTR optional
        DiskName: *const u16,  // LPCWSTR optional
        PathToSource: *const u16,  // LPCWSTR
        SourceFile: *const u16,  // LPCWSTR
        TargetPathFile: *const u16,  // LPCWSTR optional
        Win32ErrorCode: u32,  // DWORD
        Style: u32,  // DWORD
        PathBuffer: *mut u16,  // LPWSTR optional, out
        PathBufferSize: u32,  // DWORD
        PathRequiredSize: *mut u32  // DWORD* optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint SetupCopyErrorW(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPWStr)] string DialogTitle, [MarshalAs(UnmanagedType.LPWStr)] string DiskName, [MarshalAs(UnmanagedType.LPWStr)] string PathToSource, [MarshalAs(UnmanagedType.LPWStr)] string SourceFile, [MarshalAs(UnmanagedType.LPWStr)] string TargetPathFile, uint Win32ErrorCode, uint Style, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder PathBuffer, uint PathBufferSize, IntPtr PathRequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupCopyErrorW' -Namespace Win32 -PassThru
# $api::SetupCopyErrorW(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
#uselib "SETUPAPI.dll"
#func global SetupCopyErrorW "SetupCopyErrorW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupCopyErrorW hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, varptr(PathBuffer), PathBufferSize, varptr(PathRequiredSize)   ; 戻り値は stat
; hwndParent : HWND -> "wptr"
; DialogTitle : LPCWSTR optional -> "wptr"
; DiskName : LPCWSTR optional -> "wptr"
; PathToSource : LPCWSTR -> "wptr"
; SourceFile : LPCWSTR -> "wptr"
; TargetPathFile : LPCWSTR optional -> "wptr"
; Win32ErrorCode : DWORD -> "wptr"
; Style : DWORD -> "wptr"
; PathBuffer : LPWSTR optional, out -> "wptr"
; PathBufferSize : DWORD -> "wptr"
; PathRequiredSize : DWORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupCopyErrorW "SetupCopyErrorW" sptr, wstr, wstr, wstr, wstr, wstr, int, int, var, int, var
; res = SetupCopyErrorW(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
; hwndParent : HWND -> "sptr"
; DialogTitle : LPCWSTR optional -> "wstr"
; DiskName : LPCWSTR optional -> "wstr"
; PathToSource : LPCWSTR -> "wstr"
; SourceFile : LPCWSTR -> "wstr"
; TargetPathFile : LPCWSTR optional -> "wstr"
; Win32ErrorCode : DWORD -> "int"
; Style : DWORD -> "int"
; PathBuffer : LPWSTR optional, out -> "var"
; PathBufferSize : DWORD -> "int"
; PathRequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD SetupCopyErrorW(HWND hwndParent, LPCWSTR DialogTitle, LPCWSTR DiskName, LPCWSTR PathToSource, LPCWSTR SourceFile, LPCWSTR TargetPathFile, DWORD Win32ErrorCode, DWORD Style, LPWSTR PathBuffer, DWORD PathBufferSize, DWORD* PathRequiredSize)
#uselib "SETUPAPI.dll"
#cfunc global SetupCopyErrorW "SetupCopyErrorW" intptr, wstr, wstr, wstr, wstr, wstr, int, int, var, int, var
; res = SetupCopyErrorW(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
; hwndParent : HWND -> "intptr"
; DialogTitle : LPCWSTR optional -> "wstr"
; DiskName : LPCWSTR optional -> "wstr"
; PathToSource : LPCWSTR -> "wstr"
; SourceFile : LPCWSTR -> "wstr"
; TargetPathFile : LPCWSTR optional -> "wstr"
; Win32ErrorCode : DWORD -> "int"
; Style : DWORD -> "int"
; PathBuffer : LPWSTR optional, out -> "var"
; PathBufferSize : DWORD -> "int"
; PathRequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupCopyErrorW = setupapi.NewProc("SetupCopyErrorW")
)

// hwndParent (HWND), DialogTitle (LPCWSTR optional), DiskName (LPCWSTR optional), PathToSource (LPCWSTR), SourceFile (LPCWSTR), TargetPathFile (LPCWSTR optional), Win32ErrorCode (DWORD), Style (DWORD), PathBuffer (LPWSTR optional, out), PathBufferSize (DWORD), PathRequiredSize (DWORD* optional, out)
r1, _, err := procSetupCopyErrorW.Call(
	uintptr(hwndParent),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DialogTitle))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DiskName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(PathToSource))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SourceFile))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetPathFile))),
	uintptr(Win32ErrorCode),
	uintptr(Style),
	uintptr(PathBuffer),
	uintptr(PathBufferSize),
	uintptr(PathRequiredSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function SetupCopyErrorW(
  hwndParent: THandle;   // HWND
  DialogTitle: PWideChar;   // LPCWSTR optional
  DiskName: PWideChar;   // LPCWSTR optional
  PathToSource: PWideChar;   // LPCWSTR
  SourceFile: PWideChar;   // LPCWSTR
  TargetPathFile: PWideChar;   // LPCWSTR optional
  Win32ErrorCode: DWORD;   // DWORD
  Style: DWORD;   // DWORD
  PathBuffer: PWideChar;   // LPWSTR optional, out
  PathBufferSize: DWORD;   // DWORD
  PathRequiredSize: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'SETUPAPI.dll' name 'SetupCopyErrorW';
result := DllCall("SETUPAPI\SetupCopyErrorW"
    , "Ptr", hwndParent   ; HWND
    , "WStr", DialogTitle   ; LPCWSTR optional
    , "WStr", DiskName   ; LPCWSTR optional
    , "WStr", PathToSource   ; LPCWSTR
    , "WStr", SourceFile   ; LPCWSTR
    , "WStr", TargetPathFile   ; LPCWSTR optional
    , "UInt", Win32ErrorCode   ; DWORD
    , "UInt", Style   ; DWORD
    , "Ptr", PathBuffer   ; LPWSTR optional, out
    , "UInt", PathBufferSize   ; DWORD
    , "Ptr", PathRequiredSize   ; DWORD* optional, out
    , "UInt")   ; return: DWORD
●SetupCopyErrorW(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize) = DLL("SETUPAPI.dll", "dword SetupCopyErrorW(void*, char*, char*, char*, char*, char*, dword, dword, char*, dword, void*)")
# 呼び出し: SetupCopyErrorW(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
# hwndParent : HWND -> "void*"
# DialogTitle : LPCWSTR optional -> "char*"
# DiskName : LPCWSTR optional -> "char*"
# PathToSource : LPCWSTR -> "char*"
# SourceFile : LPCWSTR -> "char*"
# TargetPathFile : LPCWSTR optional -> "char*"
# Win32ErrorCode : DWORD -> "dword"
# Style : DWORD -> "dword"
# PathBuffer : LPWSTR optional, out -> "char*"
# PathBufferSize : DWORD -> "dword"
# PathRequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

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

typedef SetupCopyErrorWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Uint32, Pointer<Utf16>, Uint32, Pointer<Uint32>);
typedef SetupCopyErrorWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, int, Pointer<Utf16>, int, Pointer<Uint32>);
final SetupCopyErrorW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupCopyErrorWNative, SetupCopyErrorWDart>('SetupCopyErrorW');
// hwndParent : HWND -> Pointer<Void>
// DialogTitle : LPCWSTR optional -> Pointer<Utf16>
// DiskName : LPCWSTR optional -> Pointer<Utf16>
// PathToSource : LPCWSTR -> Pointer<Utf16>
// SourceFile : LPCWSTR -> Pointer<Utf16>
// TargetPathFile : LPCWSTR optional -> Pointer<Utf16>
// Win32ErrorCode : DWORD -> Uint32
// Style : DWORD -> Uint32
// PathBuffer : LPWSTR optional, out -> Pointer<Utf16>
// PathBufferSize : DWORD -> Uint32
// PathRequiredSize : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupCopyErrorW(
  hwndParent: THandle;   // HWND
  DialogTitle: PWideChar;   // LPCWSTR optional
  DiskName: PWideChar;   // LPCWSTR optional
  PathToSource: PWideChar;   // LPCWSTR
  SourceFile: PWideChar;   // LPCWSTR
  TargetPathFile: PWideChar;   // LPCWSTR optional
  Win32ErrorCode: DWORD;   // DWORD
  Style: DWORD;   // DWORD
  PathBuffer: PWideChar;   // LPWSTR optional, out
  PathBufferSize: DWORD;   // DWORD
  PathRequiredSize: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'SETUPAPI.dll' name 'SetupCopyErrorW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupCopyErrorW"
  c_SetupCopyErrorW :: Ptr () -> CWString -> CWString -> CWString -> CWString -> CWString -> Word32 -> Word32 -> CWString -> Word32 -> Ptr Word32 -> IO Word32
-- hwndParent : HWND -> Ptr ()
-- DialogTitle : LPCWSTR optional -> CWString
-- DiskName : LPCWSTR optional -> CWString
-- PathToSource : LPCWSTR -> CWString
-- SourceFile : LPCWSTR -> CWString
-- TargetPathFile : LPCWSTR optional -> CWString
-- Win32ErrorCode : DWORD -> Word32
-- Style : DWORD -> Word32
-- PathBuffer : LPWSTR optional, out -> CWString
-- PathBufferSize : DWORD -> Word32
-- PathRequiredSize : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupcopyerrorw =
  foreign "SetupCopyErrorW"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> returning uint32_t)
(* hwndParent : HWND -> (ptr void) *)
(* DialogTitle : LPCWSTR optional -> (ptr uint16_t) *)
(* DiskName : LPCWSTR optional -> (ptr uint16_t) *)
(* PathToSource : LPCWSTR -> (ptr uint16_t) *)
(* SourceFile : LPCWSTR -> (ptr uint16_t) *)
(* TargetPathFile : LPCWSTR optional -> (ptr uint16_t) *)
(* Win32ErrorCode : DWORD -> uint32_t *)
(* Style : DWORD -> uint32_t *)
(* PathBuffer : LPWSTR optional, out -> (ptr uint16_t) *)
(* PathBufferSize : DWORD -> uint32_t *)
(* PathRequiredSize : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupCopyErrorW" setup-copy-error-w :convention :stdcall) :uint32
  (hwnd-parent :pointer)   ; HWND
  (dialog-title (:string :encoding :utf-16le))   ; LPCWSTR optional
  (disk-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (path-to-source (:string :encoding :utf-16le))   ; LPCWSTR
  (source-file (:string :encoding :utf-16le))   ; LPCWSTR
  (target-path-file (:string :encoding :utf-16le))   ; LPCWSTR optional
  (win32-error-code :uint32)   ; DWORD
  (style :uint32)   ; DWORD
  (path-buffer :pointer)   ; LPWSTR optional, out
  (path-buffer-size :uint32)   ; DWORD
  (path-required-size :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupCopyErrorW = Win32::API::More->new('SETUPAPI',
    'DWORD SetupCopyErrorW(HANDLE hwndParent, LPCWSTR DialogTitle, LPCWSTR DiskName, LPCWSTR PathToSource, LPCWSTR SourceFile, LPCWSTR TargetPathFile, DWORD Win32ErrorCode, DWORD Style, LPWSTR PathBuffer, DWORD PathBufferSize, LPVOID PathRequiredSize)');
# my $ret = $SetupCopyErrorW->Call($hwndParent, $DialogTitle, $DiskName, $PathToSource, $SourceFile, $TargetPathFile, $Win32ErrorCode, $Style, $PathBuffer, $PathBufferSize, $PathRequiredSize);
# hwndParent : HWND -> HANDLE
# DialogTitle : LPCWSTR optional -> LPCWSTR
# DiskName : LPCWSTR optional -> LPCWSTR
# PathToSource : LPCWSTR -> LPCWSTR
# SourceFile : LPCWSTR -> LPCWSTR
# TargetPathFile : LPCWSTR optional -> LPCWSTR
# Win32ErrorCode : DWORD -> DWORD
# Style : DWORD -> DWORD
# PathBuffer : LPWSTR optional, out -> LPWSTR
# PathBufferSize : DWORD -> DWORD
# PathRequiredSize : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目