ホーム › Devices.DeviceAndDriverInstallation › SetupCopyErrorW
SetupCopyErrorW
関数ファイルコピーエラーを通知するダイアログを表示する(Unicode)。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | in | エラーダイアログの親ウィンドウハンドル。NULL可。 |
| DialogTitle | LPCWSTR | inoptional | ダイアログのタイトル文字列(Unicode)。NULLで既定値を使う。 |
| DiskName | LPCWSTR | inoptional | 対象ディスク/メディアの表示名(Unicode)。NULL可。 |
| PathToSource | LPCWSTR | in | ソースの検索パス(Unicode)。 |
| SourceFile | LPCWSTR | in | コピー元ファイル名(Unicode)。 |
| TargetPathFile | LPCWSTR | inoptional | コピー先のフルパスファイル名(Unicode)。 |
| Win32ErrorCode | DWORD | in | 発生したWin32エラーコード。表示メッセージの決定に使う。 |
| Style | DWORD | in | ダイアログの表示動作を制御するスタイルフラグ。 |
| PathBuffer | LPWSTR | outoptional | ユーザーが指定した新しいソースパスを受け取るバッファ(Unicode)。NULL可。 |
| PathBufferSize | DWORD | in | PathBufferのサイズ(文字数)。 |
| PathRequiredSize | DWORD* | outoptional | パスに必要なバッファサイズを受け取る出力ポインタ。NULL可。 |
戻り値の型: DWORD
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupCopyErrorW "SetupCopyErrorW" sptr, wstr, wstr, wstr, wstr, wstr, int, int, sptr, int, sptr ; res = SetupCopyErrorW(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, varptr(PathBuffer), PathBufferSize, varptr(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 -> "sptr" ; PathBufferSize : DWORD -> "int" ; PathRequiredSize : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, int, intptr ; res = SetupCopyErrorW(hwndParent, DialogTitle, DiskName, PathToSource, SourceFile, TargetPathFile, Win32ErrorCode, Style, varptr(PathBuffer), PathBufferSize, varptr(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 -> "intptr" ; PathBufferSize : DWORD -> "int" ; PathRequiredSize : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // DWORDfunction 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 変換を行う。関連項目
文字セット違い
- f SetupCopyErrorA (ANSI版) — ファイルコピーエラーを通知するダイアログを表示する(ANSI)。