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

SetupCopyErrorA

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

シグネチャ

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

DWORD SetupCopyErrorA(
    HWND hwndParent,
    LPCSTR DialogTitle,   // optional
    LPCSTR DiskName,   // optional
    LPCSTR PathToSource,
    LPCSTR SourceFile,
    LPCSTR TargetPathFile,   // optional
    DWORD Win32ErrorCode,
    DWORD Style,
    LPSTR PathBuffer,   // optional
    DWORD PathBufferSize,
    DWORD* PathRequiredSize   // optional
);

パラメーター

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

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

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

DiskNameLPCSTRinoptional

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

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

PathToSourceLPCSTRin

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

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

SourceFileLPCSTRin

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

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

TargetPathFileLPCSTRinoptional

名前変更操作およびコピー操作の対象ファイルのフル パスを指定する 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

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

PathBufferLPSTRoutoptional

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

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

PathBufferSizeDWORDin

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

バッファー サイズは、null 終端文字を含めて少なくとも MAX_PATH 文字にしてください。

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

戻り値の型: DWORD

公式ドキュメント

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

戻り値

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

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

解説(Remarks)

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

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

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

メモ

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

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

各言語での呼び出し定義

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

DWORD SetupCopyErrorA(
    HWND hwndParent,
    LPCSTR DialogTitle,   // optional
    LPCSTR DiskName,   // optional
    LPCSTR PathToSource,
    LPCSTR SourceFile,
    LPCSTR TargetPathFile,   // optional
    DWORD Win32ErrorCode,
    DWORD Style,
    LPSTR PathBuffer,   // optional
    DWORD PathBufferSize,
    DWORD* PathRequiredSize   // optional
);
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint SetupCopyErrorA(
    IntPtr hwndParent,   // HWND
    [MarshalAs(UnmanagedType.LPStr)] string DialogTitle,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string DiskName,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] string PathToSource,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string SourceFile,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string TargetPathFile,   // LPCSTR optional
    uint Win32ErrorCode,   // DWORD
    uint Style,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder PathBuffer,   // LPSTR optional, out
    uint PathBufferSize,   // DWORD
    IntPtr PathRequiredSize   // DWORD* optional, out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupCopyErrorA(
    hwndParent As IntPtr,   ' HWND
    <MarshalAs(UnmanagedType.LPStr)> DialogTitle As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> DiskName As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> PathToSource As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> SourceFile As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> TargetPathFile As String,   ' LPCSTR optional
    Win32ErrorCode As UInteger,   ' DWORD
    Style As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> PathBuffer As System.Text.StringBuilder,   ' LPSTR optional, out
    PathBufferSize As UInteger,   ' DWORD
    PathRequiredSize As IntPtr   ' DWORD* optional, out
) As UInteger
End Function
' hwndParent : HWND
' DialogTitle : LPCSTR optional
' DiskName : LPCSTR optional
' PathToSource : LPCSTR
' SourceFile : LPCSTR
' TargetPathFile : LPCSTR optional
' Win32ErrorCode : DWORD
' Style : DWORD
' PathBuffer : LPSTR optional, out
' PathBufferSize : DWORD
' PathRequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupCopyErrorA Lib "setupapi" ( _
    ByVal hwndParent As LongPtr, _
    ByVal DialogTitle As String, _
    ByVal DiskName As String, _
    ByVal PathToSource As String, _
    ByVal SourceFile As String, _
    ByVal TargetPathFile As String, _
    ByVal Win32ErrorCode As Long, _
    ByVal Style As Long, _
    ByVal PathBuffer As String, _
    ByVal PathBufferSize As Long, _
    ByVal PathRequiredSize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupCopyErrorA = ctypes.windll.setupapi.SetupCopyErrorA
SetupCopyErrorA.restype = wintypes.DWORD
SetupCopyErrorA.argtypes = [
    wintypes.HANDLE,  # hwndParent : HWND
    wintypes.LPCSTR,  # DialogTitle : LPCSTR optional
    wintypes.LPCSTR,  # DiskName : LPCSTR optional
    wintypes.LPCSTR,  # PathToSource : LPCSTR
    wintypes.LPCSTR,  # SourceFile : LPCSTR
    wintypes.LPCSTR,  # TargetPathFile : LPCSTR optional
    wintypes.DWORD,  # Win32ErrorCode : DWORD
    wintypes.DWORD,  # Style : DWORD
    wintypes.LPSTR,  # PathBuffer : LPSTR 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')
SetupCopyErrorA = Fiddle::Function.new(
  lib['SetupCopyErrorA'],
  [
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND
    Fiddle::TYPE_VOIDP,  # DialogTitle : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # DiskName : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # PathToSource : LPCSTR
    Fiddle::TYPE_VOIDP,  # SourceFile : LPCSTR
    Fiddle::TYPE_VOIDP,  # TargetPathFile : LPCSTR optional
    -Fiddle::TYPE_INT,  # Win32ErrorCode : DWORD
    -Fiddle::TYPE_INT,  # Style : DWORD
    Fiddle::TYPE_VOIDP,  # PathBuffer : LPSTR optional, out
    -Fiddle::TYPE_INT,  # PathBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # PathRequiredSize : DWORD* optional, out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupCopyErrorA(
        hwndParent: *mut core::ffi::c_void,  // HWND
        DialogTitle: *const u8,  // LPCSTR optional
        DiskName: *const u8,  // LPCSTR optional
        PathToSource: *const u8,  // LPCSTR
        SourceFile: *const u8,  // LPCSTR
        TargetPathFile: *const u8,  // LPCSTR optional
        Win32ErrorCode: u32,  // DWORD
        Style: u32,  // DWORD
        PathBuffer: *mut u8,  // LPSTR 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.Ansi, SetLastError = true)]
public static extern uint SetupCopyErrorA(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPStr)] string DialogTitle, [MarshalAs(UnmanagedType.LPStr)] string DiskName, [MarshalAs(UnmanagedType.LPStr)] string PathToSource, [MarshalAs(UnmanagedType.LPStr)] string SourceFile, [MarshalAs(UnmanagedType.LPStr)] string TargetPathFile, uint Win32ErrorCode, uint Style, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder PathBuffer, uint PathBufferSize, IntPtr PathRequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupCopyErrorA' -Namespace Win32 -PassThru
# $api::SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
#uselib "SETUPAPI.dll"
#func global SetupCopyErrorA "SetupCopyErrorA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupCopyErrorA hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, varptr(PathBuffer), PathBufferSize, varptr(PathRequiredSize)   ; 戻り値は stat
; hwndParent : HWND -> "sptr"
; DialogTitle : LPCSTR optional -> "sptr"
; DiskName : LPCSTR optional -> "sptr"
; PathToSource : LPCSTR -> "sptr"
; SourceFile : LPCSTR -> "sptr"
; TargetPathFile : LPCSTR optional -> "sptr"
; Win32ErrorCode : DWORD -> "sptr"
; Style : DWORD -> "sptr"
; PathBuffer : LPSTR optional, out -> "sptr"
; PathBufferSize : DWORD -> "sptr"
; PathRequiredSize : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupCopyErrorA "SetupCopyErrorA" sptr, str, str, str, str, str, int, int, var, int, var
; res = SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
; hwndParent : HWND -> "sptr"
; DialogTitle : LPCSTR optional -> "str"
; DiskName : LPCSTR optional -> "str"
; PathToSource : LPCSTR -> "str"
; SourceFile : LPCSTR -> "str"
; TargetPathFile : LPCSTR optional -> "str"
; Win32ErrorCode : DWORD -> "int"
; Style : DWORD -> "int"
; PathBuffer : LPSTR optional, out -> "var"
; PathBufferSize : DWORD -> "int"
; PathRequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD SetupCopyErrorA(HWND hwndParent, LPCSTR DialogTitle, LPCSTR DiskName, LPCSTR PathToSource, LPCSTR SourceFile, LPCSTR TargetPathFile, DWORD Win32ErrorCode, DWORD Style, LPSTR PathBuffer, DWORD PathBufferSize, DWORD* PathRequiredSize)
#uselib "SETUPAPI.dll"
#cfunc global SetupCopyErrorA "SetupCopyErrorA" intptr, str, str, str, str, str, int, int, var, int, var
; res = SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
; hwndParent : HWND -> "intptr"
; DialogTitle : LPCSTR optional -> "str"
; DiskName : LPCSTR optional -> "str"
; PathToSource : LPCSTR -> "str"
; SourceFile : LPCSTR -> "str"
; TargetPathFile : LPCSTR optional -> "str"
; Win32ErrorCode : DWORD -> "int"
; Style : DWORD -> "int"
; PathBuffer : LPSTR 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")
	procSetupCopyErrorA = setupapi.NewProc("SetupCopyErrorA")
)

// hwndParent (HWND), DialogTitle (LPCSTR optional), DiskName (LPCSTR optional), PathToSource (LPCSTR), SourceFile (LPCSTR), TargetPathFile (LPCSTR optional), Win32ErrorCode (DWORD), Style (DWORD), PathBuffer (LPSTR optional, out), PathBufferSize (DWORD), PathRequiredSize (DWORD* optional, out)
r1, _, err := procSetupCopyErrorA.Call(
	uintptr(hwndParent),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DialogTitle))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DiskName))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(PathToSource))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SourceFile))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(TargetPathFile))),
	uintptr(Win32ErrorCode),
	uintptr(Style),
	uintptr(PathBuffer),
	uintptr(PathBufferSize),
	uintptr(PathRequiredSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function SetupCopyErrorA(
  hwndParent: THandle;   // HWND
  DialogTitle: PAnsiChar;   // LPCSTR optional
  DiskName: PAnsiChar;   // LPCSTR optional
  PathToSource: PAnsiChar;   // LPCSTR
  SourceFile: PAnsiChar;   // LPCSTR
  TargetPathFile: PAnsiChar;   // LPCSTR optional
  Win32ErrorCode: DWORD;   // DWORD
  Style: DWORD;   // DWORD
  PathBuffer: PAnsiChar;   // LPSTR optional, out
  PathBufferSize: DWORD;   // DWORD
  PathRequiredSize: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'SETUPAPI.dll' name 'SetupCopyErrorA';
result := DllCall("SETUPAPI\SetupCopyErrorA"
    , "Ptr", hwndParent   ; HWND
    , "AStr", DialogTitle   ; LPCSTR optional
    , "AStr", DiskName   ; LPCSTR optional
    , "AStr", PathToSource   ; LPCSTR
    , "AStr", SourceFile   ; LPCSTR
    , "AStr", TargetPathFile   ; LPCSTR optional
    , "UInt", Win32ErrorCode   ; DWORD
    , "UInt", Style   ; DWORD
    , "Ptr", PathBuffer   ; LPSTR optional, out
    , "UInt", PathBufferSize   ; DWORD
    , "Ptr", PathRequiredSize   ; DWORD* optional, out
    , "UInt")   ; return: DWORD
●SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize) = DLL("SETUPAPI.dll", "dword SetupCopyErrorA(void*, char*, char*, char*, char*, char*, dword, dword, char*, dword, void*)")
# 呼び出し: SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
# hwndParent : HWND -> "void*"
# DialogTitle : LPCSTR optional -> "char*"
# DiskName : LPCSTR optional -> "char*"
# PathToSource : LPCSTR -> "char*"
# SourceFile : LPCSTR -> "char*"
# TargetPathFile : LPCSTR optional -> "char*"
# Win32ErrorCode : DWORD -> "dword"
# Style : DWORD -> "dword"
# PathBuffer : LPSTR optional, out -> "char*"
# PathBufferSize : DWORD -> "dword"
# PathRequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupCopyErrorA(
    hwndParent: ?*anyopaque, // HWND
    DialogTitle: [*c]const u8, // LPCSTR optional
    DiskName: [*c]const u8, // LPCSTR optional
    PathToSource: [*c]const u8, // LPCSTR
    SourceFile: [*c]const u8, // LPCSTR
    TargetPathFile: [*c]const u8, // LPCSTR optional
    Win32ErrorCode: u32, // DWORD
    Style: u32, // DWORD
    PathBuffer: [*c]u8, // LPSTR optional, out
    PathBufferSize: u32, // DWORD
    PathRequiredSize: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) u32;
proc SetupCopyErrorA(
    hwndParent: pointer,  # HWND
    DialogTitle: cstring,  # LPCSTR optional
    DiskName: cstring,  # LPCSTR optional
    PathToSource: cstring,  # LPCSTR
    SourceFile: cstring,  # LPCSTR
    TargetPathFile: cstring,  # LPCSTR optional
    Win32ErrorCode: uint32,  # DWORD
    Style: uint32,  # DWORD
    PathBuffer: ptr char,  # LPSTR optional, out
    PathBufferSize: uint32,  # DWORD
    PathRequiredSize: ptr uint32  # DWORD* optional, out
): uint32 {.importc: "SetupCopyErrorA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
uint SetupCopyErrorA(
    void* hwndParent,   // HWND
    const(char)* DialogTitle,   // LPCSTR optional
    const(char)* DiskName,   // LPCSTR optional
    const(char)* PathToSource,   // LPCSTR
    const(char)* SourceFile,   // LPCSTR
    const(char)* TargetPathFile,   // LPCSTR optional
    uint Win32ErrorCode,   // DWORD
    uint Style,   // DWORD
    char* PathBuffer,   // LPSTR optional, out
    uint PathBufferSize,   // DWORD
    uint* PathRequiredSize   // DWORD* optional, out
);
ccall((:SetupCopyErrorA, "SETUPAPI.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Cstring, Cstring, Cstring, Cstring, Cstring, UInt32, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}),
      hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
# hwndParent : HWND -> Ptr{Cvoid}
# DialogTitle : LPCSTR optional -> Cstring
# DiskName : LPCSTR optional -> Cstring
# PathToSource : LPCSTR -> Cstring
# SourceFile : LPCSTR -> Cstring
# TargetPathFile : LPCSTR optional -> Cstring
# Win32ErrorCode : DWORD -> UInt32
# Style : DWORD -> UInt32
# PathBuffer : LPSTR optional, out -> Ptr{UInt8}
# PathBufferSize : DWORD -> UInt32
# PathRequiredSize : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t SetupCopyErrorA(
    void* hwndParent,
    const char* DialogTitle,
    const char* DiskName,
    const char* PathToSource,
    const char* SourceFile,
    const char* TargetPathFile,
    uint32_t Win32ErrorCode,
    uint32_t Style,
    char* PathBuffer,
    uint32_t PathBufferSize,
    uint32_t* PathRequiredSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
-- hwndParent : HWND
-- DialogTitle : LPCSTR optional
-- DiskName : LPCSTR optional
-- PathToSource : LPCSTR
-- SourceFile : LPCSTR
-- TargetPathFile : LPCSTR optional
-- Win32ErrorCode : DWORD
-- Style : DWORD
-- PathBuffer : LPSTR optional, out
-- PathBufferSize : DWORD
-- PathRequiredSize : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupCopyErrorA = lib.func('__stdcall', 'SetupCopyErrorA', 'uint32_t', ['void *', 'str', 'str', 'str', 'str', 'str', 'uint32_t', 'uint32_t', 'char *', 'uint32_t', 'uint32_t *']);
// SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
// hwndParent : HWND -> 'void *'
// DialogTitle : LPCSTR optional -> 'str'
// DiskName : LPCSTR optional -> 'str'
// PathToSource : LPCSTR -> 'str'
// SourceFile : LPCSTR -> 'str'
// TargetPathFile : LPCSTR optional -> 'str'
// Win32ErrorCode : DWORD -> 'uint32_t'
// Style : DWORD -> 'uint32_t'
// PathBuffer : LPSTR optional, out -> 'char *'
// PathBufferSize : DWORD -> 'uint32_t'
// PathRequiredSize : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupCopyErrorA: { parameters: ["pointer", "buffer", "buffer", "buffer", "buffer", "buffer", "u32", "u32", "buffer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize)
// hwndParent : HWND -> "pointer"
// DialogTitle : LPCSTR optional -> "buffer"
// DiskName : LPCSTR optional -> "buffer"
// PathToSource : LPCSTR -> "buffer"
// SourceFile : LPCSTR -> "buffer"
// TargetPathFile : LPCSTR optional -> "buffer"
// Win32ErrorCode : DWORD -> "u32"
// Style : DWORD -> "u32"
// PathBuffer : LPSTR optional, out -> "buffer"
// PathBufferSize : DWORD -> "u32"
// PathRequiredSize : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t SetupCopyErrorA(
    void* hwndParent,
    const char* DialogTitle,
    const char* DiskName,
    const char* PathToSource,
    const char* SourceFile,
    const char* TargetPathFile,
    uint32_t Win32ErrorCode,
    uint32_t Style,
    char* PathBuffer,
    uint32_t PathBufferSize,
    uint32_t* PathRequiredSize);
C, "SETUPAPI.dll");
// $ffi->SetupCopyErrorA(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, PathBuffer, PathBufferSize, PathRequiredSize);
// hwndParent : HWND
// DialogTitle : LPCSTR optional
// DiskName : LPCSTR optional
// PathToSource : LPCSTR
// SourceFile : LPCSTR
// TargetPathFile : LPCSTR optional
// Win32ErrorCode : DWORD
// Style : DWORD
// PathBuffer : LPSTR 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.ASCII_OPTIONS);
    int SetupCopyErrorA(
        Pointer hwndParent,   // HWND
        String DialogTitle,   // LPCSTR optional
        String DiskName,   // LPCSTR optional
        String PathToSource,   // LPCSTR
        String SourceFile,   // LPCSTR
        String TargetPathFile,   // LPCSTR optional
        int Win32ErrorCode,   // DWORD
        int Style,   // DWORD
        byte[] PathBuffer,   // LPSTR optional, out
        int PathBufferSize,   // DWORD
        IntByReference PathRequiredSize   // DWORD* optional, out
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupCopyErrorA = SetupCopyErrorA(
    hwndParent : Void*,   # HWND
    DialogTitle : UInt8*,   # LPCSTR optional
    DiskName : UInt8*,   # LPCSTR optional
    PathToSource : UInt8*,   # LPCSTR
    SourceFile : UInt8*,   # LPCSTR
    TargetPathFile : UInt8*,   # LPCSTR optional
    Win32ErrorCode : UInt32,   # DWORD
    Style : UInt32,   # DWORD
    PathBuffer : UInt8*,   # LPSTR 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 SetupCopyErrorANative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Uint32, Uint32, Pointer<Utf8>, Uint32, Pointer<Uint32>);
typedef SetupCopyErrorADart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, int, int, Pointer<Utf8>, int, Pointer<Uint32>);
final SetupCopyErrorA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupCopyErrorANative, SetupCopyErrorADart>('SetupCopyErrorA');
// hwndParent : HWND -> Pointer<Void>
// DialogTitle : LPCSTR optional -> Pointer<Utf8>
// DiskName : LPCSTR optional -> Pointer<Utf8>
// PathToSource : LPCSTR -> Pointer<Utf8>
// SourceFile : LPCSTR -> Pointer<Utf8>
// TargetPathFile : LPCSTR optional -> Pointer<Utf8>
// Win32ErrorCode : DWORD -> Uint32
// Style : DWORD -> Uint32
// PathBuffer : LPSTR optional, out -> Pointer<Utf8>
// PathBufferSize : DWORD -> Uint32
// PathRequiredSize : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupCopyErrorA(
  hwndParent: THandle;   // HWND
  DialogTitle: PAnsiChar;   // LPCSTR optional
  DiskName: PAnsiChar;   // LPCSTR optional
  PathToSource: PAnsiChar;   // LPCSTR
  SourceFile: PAnsiChar;   // LPCSTR
  TargetPathFile: PAnsiChar;   // LPCSTR optional
  Win32ErrorCode: DWORD;   // DWORD
  Style: DWORD;   // DWORD
  PathBuffer: PAnsiChar;   // LPSTR optional, out
  PathBufferSize: DWORD;   // DWORD
  PathRequiredSize: Pointer   // DWORD* optional, out
): DWORD; stdcall;
  external 'SETUPAPI.dll' name 'SetupCopyErrorA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let setupcopyerrora =
  foreign "SetupCopyErrorA"
    ((ptr void) @-> string @-> string @-> string @-> string @-> string @-> uint32_t @-> uint32_t @-> string @-> uint32_t @-> (ptr uint32_t) @-> returning uint32_t)
(* hwndParent : HWND -> (ptr void) *)
(* DialogTitle : LPCSTR optional -> string *)
(* DiskName : LPCSTR optional -> string *)
(* PathToSource : LPCSTR -> string *)
(* SourceFile : LPCSTR -> string *)
(* TargetPathFile : LPCSTR optional -> string *)
(* Win32ErrorCode : DWORD -> uint32_t *)
(* Style : DWORD -> uint32_t *)
(* PathBuffer : LPSTR optional, out -> string *)
(* 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 ("SetupCopyErrorA" setup-copy-error-a :convention :stdcall) :uint32
  (hwnd-parent :pointer)   ; HWND
  (dialog-title :string)   ; LPCSTR optional
  (disk-name :string)   ; LPCSTR optional
  (path-to-source :string)   ; LPCSTR
  (source-file :string)   ; LPCSTR
  (target-path-file :string)   ; LPCSTR optional
  (win32-error-code :uint32)   ; DWORD
  (style :uint32)   ; DWORD
  (path-buffer :pointer)   ; LPSTR 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 $SetupCopyErrorA = Win32::API::More->new('SETUPAPI',
    'DWORD SetupCopyErrorA(HANDLE hwndParent, LPCSTR DialogTitle, LPCSTR DiskName, LPCSTR PathToSource, LPCSTR SourceFile, LPCSTR TargetPathFile, DWORD Win32ErrorCode, DWORD Style, LPSTR PathBuffer, DWORD PathBufferSize, LPVOID PathRequiredSize)');
# my $ret = $SetupCopyErrorA->Call($hwndParent, $DialogTitle, $DiskName, $PathToSource, $SourceFile, $TargetPathFile, $Win32ErrorCode, $Style, $PathBuffer, $PathBufferSize, $PathRequiredSize);
# hwndParent : HWND -> HANDLE
# DialogTitle : LPCSTR optional -> LPCSTR
# DiskName : LPCSTR optional -> LPCSTR
# PathToSource : LPCSTR -> LPCSTR
# SourceFile : LPCSTR -> LPCSTR
# TargetPathFile : LPCSTR optional -> LPCSTR
# Win32ErrorCode : DWORD -> DWORD
# Style : DWORD -> DWORD
# PathBuffer : LPSTR optional, out -> LPSTR
# PathBufferSize : DWORD -> DWORD
# PathRequiredSize : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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