ReplaceFileFromAppW
関数シグネチャ
// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>
BOOL ReplaceFileFromAppW(
LPCWSTR lpReplacedFileName,
LPCWSTR lpReplacementFileName,
LPCWSTR lpBackupFileName, // optional
DWORD dwReplaceFlags,
void* lpExclude, // optional
void* lpReserved // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| lpReplacedFileName | LPCWSTR | in | "\\?\" を前置せずに MAX_PATH の制限を解除する方法については、Naming Files, Paths, and Namespaces の「Maximum Path Length Limitation」セクションを参照してください。 このファイルは GENERIC_READ、DELETE、SYNCHRONIZE のアクセス権で開かれます。共有モードは FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE です。 呼び出し元は、置き換えられるファイルに対する書き込みアクセス権を持っている必要があります。詳細については、File Security and Access Rights を参照してください。 | ||||||||
| lpReplacementFileName | LPCWSTR | in | lpReplacedFileName ファイルを置き換えるファイルの名前です。 "\\?\" を前置せずに MAX_PATH の制限を解除する方法については、Naming Files, Paths, and Namespaces の「Maximum Path Length Limitation」セクションを参照してください。 この関数は、すべての属性と ACL を保持できるように、SYNCHRONIZE、GENERIC_READ、GENERIC_WRITE、DELETE、WRITE_DAC のアクセス権でこのファイルを開こうとします。これが失敗した場合、関数は SYNCHRONIZE、GENERIC_READ、DELETE、WRITE_DAC のアクセス権でファイルを開こうとします。共有モードは指定されません。 | ||||||||
| lpBackupFileName | LPCWSTR | inoptional | lpReplacedFileName ファイルのバックアップコピーとして機能するファイルの名前です。このパラメーターが NULL の場合、バックアップファイルは作成されません。バックアップファイルの実装の詳細については、「解説」セクションを参照してください。 "\\?\" を前置せずに MAX_PATH の制限を解除する方法については、Naming Files, Paths, and Namespaces の「Maximum Path Length Limitation」セクションを参照してください。 | ||||||||
| dwReplaceFlags | DWORD | in | 置き換えオプションです。このパラメーターには、次の値を 1 つ以上指定できます。
| ||||||||
| lpExclude | void* | optional | 将来の使用のために予約されています。 | ||||||||
| lpReserved | void* | optional | 将来の使用のために予約されています。 |
戻り値の型: BOOL
公式ドキュメント
あるファイルを別のファイルで置き換えます。オプションで元のファイルのバックアップコピーを作成できます。この関数の動作は ReplaceFile と同一ですが、この関数はユニバーサル Windows プラットフォーム (UWP) アプリのセキュリティモデルに従います。
戻り値
関数が成功した場合、戻り値は 0 以外の値になります。
関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、GetLastError を呼び出します。この関数で発生する可能性のあるエラーコードは次のとおりです。
| リターンコード/値 | 説明 |
|---|---|
| ERROR_UNABLE_TO_MOVE_REPLACEMENT 1176 (0x498) | 置き換えるファイルの名前を変更できませんでした。lpBackupFileName が指定されていた場合、置き換えられるファイルと置き換えるファイルは元のファイル名を保持します。それ以外の場合、置き換えられるファイルはもはや存在せず、置き換えるファイルが元の名前で存在します。 |
| ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 1177 (0x499) | 置き換えるファイルを移動できませんでした。置き換えるファイルは元の名前のまま存在しますが、置き換える対象のファイルからファイルストリームと属性を継承しています。置き換えられる対象のファイルは別の名前で引き続き存在します。lpBackupFileName が指定されている場合、それが置き換えられたファイルの名前になります。 |
| ERROR_UNABLE_TO_REMOVE_REPLACED 1175 (0x497) | 置き換えられるファイルを削除できませんでした。置き換えられるファイルと置き換えるファイルは元のファイル名を保持します。 |
ERROR_INVALID_PARAMETER など、その他のエラーが返された場合、置き換えられるファイルと置き換えるファイルは元のファイル名を保持します。このシナリオでは、バックアップファイルは存在せず、置き換えるファイルが置き換えられるファイルのすべての属性とストリームを継承しているという保証はありません。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>
BOOL ReplaceFileFromAppW(
LPCWSTR lpReplacedFileName,
LPCWSTR lpReplacementFileName,
LPCWSTR lpBackupFileName, // optional
DWORD dwReplaceFlags,
void* lpExclude, // optional
void* lpReserved // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling = true)]
static extern bool ReplaceFileFromAppW(
[MarshalAs(UnmanagedType.LPWStr)] string lpReplacedFileName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpReplacementFileName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpBackupFileName, // LPCWSTR optional
uint dwReplaceFlags, // DWORD
IntPtr lpExclude, // void* optional
IntPtr lpReserved // void* optional
);<DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function ReplaceFileFromAppW(
<MarshalAs(UnmanagedType.LPWStr)> lpReplacedFileName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpReplacementFileName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpBackupFileName As String, ' LPCWSTR optional
dwReplaceFlags As UInteger, ' DWORD
lpExclude As IntPtr, ' void* optional
lpReserved As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' lpReplacedFileName : LPCWSTR
' lpReplacementFileName : LPCWSTR
' lpBackupFileName : LPCWSTR optional
' dwReplaceFlags : DWORD
' lpExclude : void* optional
' lpReserved : void* optional
Declare PtrSafe Function ReplaceFileFromAppW Lib "api-ms-win-core-file-fromapp-l1-1-0" ( _
ByVal lpReplacedFileName As LongPtr, _
ByVal lpReplacementFileName As LongPtr, _
ByVal lpBackupFileName As LongPtr, _
ByVal dwReplaceFlags As Long, _
ByVal lpExclude As LongPtr, _
ByVal lpReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ReplaceFileFromAppW = ctypes.windll.LoadLibrary("api-ms-win-core-file-fromapp-l1-1-0.dll").ReplaceFileFromAppW
ReplaceFileFromAppW.restype = wintypes.BOOL
ReplaceFileFromAppW.argtypes = [
wintypes.LPCWSTR, # lpReplacedFileName : LPCWSTR
wintypes.LPCWSTR, # lpReplacementFileName : LPCWSTR
wintypes.LPCWSTR, # lpBackupFileName : LPCWSTR optional
wintypes.DWORD, # dwReplaceFlags : DWORD
ctypes.POINTER(None), # lpExclude : void* optional
ctypes.POINTER(None), # lpReserved : void* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-file-fromapp-l1-1-0.dll')
ReplaceFileFromAppW = Fiddle::Function.new(
lib['ReplaceFileFromAppW'],
[
Fiddle::TYPE_VOIDP, # lpReplacedFileName : LPCWSTR
Fiddle::TYPE_VOIDP, # lpReplacementFileName : LPCWSTR
Fiddle::TYPE_VOIDP, # lpBackupFileName : LPCWSTR optional
-Fiddle::TYPE_INT, # dwReplaceFlags : DWORD
Fiddle::TYPE_VOIDP, # lpExclude : void* optional
Fiddle::TYPE_VOIDP, # lpReserved : void* optional
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-core-file-fromapp-l1-1-0")]
extern "system" {
fn ReplaceFileFromAppW(
lpReplacedFileName: *const u16, // LPCWSTR
lpReplacementFileName: *const u16, // LPCWSTR
lpBackupFileName: *const u16, // LPCWSTR optional
dwReplaceFlags: u32, // DWORD
lpExclude: *mut (), // void* optional
lpReserved: *mut () // void* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll")]
public static extern bool ReplaceFileFromAppW([MarshalAs(UnmanagedType.LPWStr)] string lpReplacedFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpReplacementFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpBackupFileName, uint dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-file-fromapp-l1-1-0_ReplaceFileFromAppW' -Namespace Win32 -PassThru
# $api::ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved)#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#func global ReplaceFileFromAppW "ReplaceFileFromAppW" sptr, sptr, sptr, sptr, sptr, sptr
; ReplaceFileFromAppW lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved ; 戻り値は stat
; lpReplacedFileName : LPCWSTR -> "sptr"
; lpReplacementFileName : LPCWSTR -> "sptr"
; lpBackupFileName : LPCWSTR optional -> "sptr"
; dwReplaceFlags : DWORD -> "sptr"
; lpExclude : void* optional -> "sptr"
; lpReserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#cfunc global ReplaceFileFromAppW "ReplaceFileFromAppW" wstr, wstr, wstr, int, sptr, sptr
; res = ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved)
; lpReplacedFileName : LPCWSTR -> "wstr"
; lpReplacementFileName : LPCWSTR -> "wstr"
; lpBackupFileName : LPCWSTR optional -> "wstr"
; dwReplaceFlags : DWORD -> "int"
; lpExclude : void* optional -> "sptr"
; lpReserved : void* optional -> "sptr"; BOOL ReplaceFileFromAppW(LPCWSTR lpReplacedFileName, LPCWSTR lpReplacementFileName, LPCWSTR lpBackupFileName, DWORD dwReplaceFlags, void* lpExclude, void* lpReserved)
#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#cfunc global ReplaceFileFromAppW "ReplaceFileFromAppW" wstr, wstr, wstr, int, intptr, intptr
; res = ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved)
; lpReplacedFileName : LPCWSTR -> "wstr"
; lpReplacementFileName : LPCWSTR -> "wstr"
; lpBackupFileName : LPCWSTR optional -> "wstr"
; dwReplaceFlags : DWORD -> "int"
; lpExclude : void* optional -> "intptr"
; lpReserved : void* optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_core_file_fromapp_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-file-fromapp-l1-1-0.dll")
procReplaceFileFromAppW = api_ms_win_core_file_fromapp_l1_1_0.NewProc("ReplaceFileFromAppW")
)
// lpReplacedFileName (LPCWSTR), lpReplacementFileName (LPCWSTR), lpBackupFileName (LPCWSTR optional), dwReplaceFlags (DWORD), lpExclude (void* optional), lpReserved (void* optional)
r1, _, err := procReplaceFileFromAppW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpReplacedFileName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpReplacementFileName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpBackupFileName))),
uintptr(dwReplaceFlags),
uintptr(lpExclude),
uintptr(lpReserved),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ReplaceFileFromAppW(
lpReplacedFileName: PWideChar; // LPCWSTR
lpReplacementFileName: PWideChar; // LPCWSTR
lpBackupFileName: PWideChar; // LPCWSTR optional
dwReplaceFlags: DWORD; // DWORD
lpExclude: Pointer; // void* optional
lpReserved: Pointer // void* optional
): BOOL; stdcall;
external 'api-ms-win-core-file-fromapp-l1-1-0.dll' name 'ReplaceFileFromAppW';result := DllCall("api-ms-win-core-file-fromapp-l1-1-0\ReplaceFileFromAppW"
, "WStr", lpReplacedFileName ; LPCWSTR
, "WStr", lpReplacementFileName ; LPCWSTR
, "WStr", lpBackupFileName ; LPCWSTR optional
, "UInt", dwReplaceFlags ; DWORD
, "Ptr", lpExclude ; void* optional
, "Ptr", lpReserved ; void* optional
, "Int") ; return: BOOL●ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved) = DLL("api-ms-win-core-file-fromapp-l1-1-0.dll", "bool ReplaceFileFromAppW(char*, char*, char*, dword, void*, void*)")
# 呼び出し: ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved)
# lpReplacedFileName : LPCWSTR -> "char*"
# lpReplacementFileName : LPCWSTR -> "char*"
# lpBackupFileName : LPCWSTR optional -> "char*"
# dwReplaceFlags : DWORD -> "dword"
# lpExclude : void* optional -> "void*"
# lpReserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "api-ms-win-core-file-fromapp-l1-1-0" fn ReplaceFileFromAppW(
lpReplacedFileName: [*c]const u16, // LPCWSTR
lpReplacementFileName: [*c]const u16, // LPCWSTR
lpBackupFileName: [*c]const u16, // LPCWSTR optional
dwReplaceFlags: u32, // DWORD
lpExclude: ?*anyopaque, // void* optional
lpReserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc ReplaceFileFromAppW(
lpReplacedFileName: WideCString, # LPCWSTR
lpReplacementFileName: WideCString, # LPCWSTR
lpBackupFileName: WideCString, # LPCWSTR optional
dwReplaceFlags: uint32, # DWORD
lpExclude: pointer, # void* optional
lpReserved: pointer # void* optional
): int32 {.importc: "ReplaceFileFromAppW", stdcall, dynlib: "api-ms-win-core-file-fromapp-l1-1-0.dll".}pragma(lib, "api-ms-win-core-file-fromapp-l1-1-0");
extern(Windows)
int ReplaceFileFromAppW(
const(wchar)* lpReplacedFileName, // LPCWSTR
const(wchar)* lpReplacementFileName, // LPCWSTR
const(wchar)* lpBackupFileName, // LPCWSTR optional
uint dwReplaceFlags, // DWORD
void* lpExclude, // void* optional
void* lpReserved // void* optional
);ccall((:ReplaceFileFromAppW, "api-ms-win-core-file-fromapp-l1-1-0.dll"), stdcall, Int32,
(Cwstring, Cwstring, Cwstring, UInt32, Ptr{Cvoid}, Ptr{Cvoid}),
lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved)
# lpReplacedFileName : LPCWSTR -> Cwstring
# lpReplacementFileName : LPCWSTR -> Cwstring
# lpBackupFileName : LPCWSTR optional -> Cwstring
# dwReplaceFlags : DWORD -> UInt32
# lpExclude : void* optional -> Ptr{Cvoid}
# lpReserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ReplaceFileFromAppW(
const uint16_t* lpReplacedFileName,
const uint16_t* lpReplacementFileName,
const uint16_t* lpBackupFileName,
uint32_t dwReplaceFlags,
void* lpExclude,
void* lpReserved);
]]
local api-ms-win-core-file-fromapp-l1-1-0 = ffi.load("api-ms-win-core-file-fromapp-l1-1-0")
-- api-ms-win-core-file-fromapp-l1-1-0.ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved)
-- lpReplacedFileName : LPCWSTR
-- lpReplacementFileName : LPCWSTR
-- lpBackupFileName : LPCWSTR optional
-- dwReplaceFlags : DWORD
-- lpExclude : void* optional
-- lpReserved : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-file-fromapp-l1-1-0.dll');
const ReplaceFileFromAppW = lib.func('__stdcall', 'ReplaceFileFromAppW', 'int32_t', ['str16', 'str16', 'str16', 'uint32_t', 'void *', 'void *']);
// ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved)
// lpReplacedFileName : LPCWSTR -> 'str16'
// lpReplacementFileName : LPCWSTR -> 'str16'
// lpBackupFileName : LPCWSTR optional -> 'str16'
// dwReplaceFlags : DWORD -> 'uint32_t'
// lpExclude : void* optional -> 'void *'
// lpReserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-file-fromapp-l1-1-0.dll", {
ReplaceFileFromAppW: { parameters: ["buffer", "buffer", "buffer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved)
// lpReplacedFileName : LPCWSTR -> "buffer"
// lpReplacementFileName : LPCWSTR -> "buffer"
// lpBackupFileName : LPCWSTR optional -> "buffer"
// dwReplaceFlags : DWORD -> "u32"
// lpExclude : void* optional -> "pointer"
// lpReserved : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ReplaceFileFromAppW(
const uint16_t* lpReplacedFileName,
const uint16_t* lpReplacementFileName,
const uint16_t* lpBackupFileName,
uint32_t dwReplaceFlags,
void* lpExclude,
void* lpReserved);
C, "api-ms-win-core-file-fromapp-l1-1-0.dll");
// $ffi->ReplaceFileFromAppW(lpReplacedFileName, lpReplacementFileName, lpBackupFileName, dwReplaceFlags, lpExclude, lpReserved);
// lpReplacedFileName : LPCWSTR
// lpReplacementFileName : LPCWSTR
// lpBackupFileName : LPCWSTR optional
// dwReplaceFlags : DWORD
// lpExclude : void* optional
// lpReserved : void* optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Api-ms-win-core-file-fromapp-l1-1-0 extends StdCallLibrary {
Api-ms-win-core-file-fromapp-l1-1-0 INSTANCE = Native.load("api-ms-win-core-file-fromapp-l1-1-0", Api-ms-win-core-file-fromapp-l1-1-0.class);
boolean ReplaceFileFromAppW(
WString lpReplacedFileName, // LPCWSTR
WString lpReplacementFileName, // LPCWSTR
WString lpBackupFileName, // LPCWSTR optional
int dwReplaceFlags, // DWORD
Pointer lpExclude, // void* optional
Pointer lpReserved // void* optional
);
}@[Link("api-ms-win-core-file-fromapp-l1-1-0")]
lib Libapi-ms-win-core-file-fromapp-l1-1-0
fun ReplaceFileFromAppW = ReplaceFileFromAppW(
lpReplacedFileName : UInt16*, # LPCWSTR
lpReplacementFileName : UInt16*, # LPCWSTR
lpBackupFileName : UInt16*, # LPCWSTR optional
dwReplaceFlags : UInt32, # DWORD
lpExclude : Void*, # void* optional
lpReserved : Void* # void* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ReplaceFileFromAppWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Void>);
typedef ReplaceFileFromAppWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>);
final ReplaceFileFromAppW = DynamicLibrary.open('api-ms-win-core-file-fromapp-l1-1-0.dll')
.lookupFunction<ReplaceFileFromAppWNative, ReplaceFileFromAppWDart>('ReplaceFileFromAppW');
// lpReplacedFileName : LPCWSTR -> Pointer<Utf16>
// lpReplacementFileName : LPCWSTR -> Pointer<Utf16>
// lpBackupFileName : LPCWSTR optional -> Pointer<Utf16>
// dwReplaceFlags : DWORD -> Uint32
// lpExclude : void* optional -> Pointer<Void>
// lpReserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ReplaceFileFromAppW(
lpReplacedFileName: PWideChar; // LPCWSTR
lpReplacementFileName: PWideChar; // LPCWSTR
lpBackupFileName: PWideChar; // LPCWSTR optional
dwReplaceFlags: DWORD; // DWORD
lpExclude: Pointer; // void* optional
lpReserved: Pointer // void* optional
): BOOL; stdcall;
external 'api-ms-win-core-file-fromapp-l1-1-0.dll' name 'ReplaceFileFromAppW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ReplaceFileFromAppW"
c_ReplaceFileFromAppW :: CWString -> CWString -> CWString -> Word32 -> Ptr () -> Ptr () -> IO CInt
-- lpReplacedFileName : LPCWSTR -> CWString
-- lpReplacementFileName : LPCWSTR -> CWString
-- lpBackupFileName : LPCWSTR optional -> CWString
-- dwReplaceFlags : DWORD -> Word32
-- lpExclude : void* optional -> Ptr ()
-- lpReserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let replacefilefromappw =
foreign "ReplaceFileFromAppW"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* lpReplacedFileName : LPCWSTR -> (ptr uint16_t) *)
(* lpReplacementFileName : LPCWSTR -> (ptr uint16_t) *)
(* lpBackupFileName : LPCWSTR optional -> (ptr uint16_t) *)
(* dwReplaceFlags : DWORD -> uint32_t *)
(* lpExclude : void* optional -> (ptr void) *)
(* lpReserved : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-file-fromapp-l1-1-0 (t "api-ms-win-core-file-fromapp-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-file-fromapp-l1-1-0)
(cffi:defcfun ("ReplaceFileFromAppW" replace-file-from-app-w :convention :stdcall) :int32
(lp-replaced-file-name (:string :encoding :utf-16le)) ; LPCWSTR
(lp-replacement-file-name (:string :encoding :utf-16le)) ; LPCWSTR
(lp-backup-file-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-replace-flags :uint32) ; DWORD
(lp-exclude :pointer) ; void* optional
(lp-reserved :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ReplaceFileFromAppW = Win32::API::More->new('api-ms-win-core-file-fromapp-l1-1-0',
'BOOL ReplaceFileFromAppW(LPCWSTR lpReplacedFileName, LPCWSTR lpReplacementFileName, LPCWSTR lpBackupFileName, DWORD dwReplaceFlags, LPVOID lpExclude, LPVOID lpReserved)');
# my $ret = $ReplaceFileFromAppW->Call($lpReplacedFileName, $lpReplacementFileName, $lpBackupFileName, $dwReplaceFlags, $lpExclude, $lpReserved);
# lpReplacedFileName : LPCWSTR -> LPCWSTR
# lpReplacementFileName : LPCWSTR -> LPCWSTR
# lpBackupFileName : LPCWSTR optional -> LPCWSTR
# dwReplaceFlags : DWORD -> DWORD
# lpExclude : void* optional -> LPVOID
# lpReserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。