Win32 API 日本語リファレンス
ホームStorage.FileSystem › CreateFile2FromAppW

CreateFile2FromAppW

関数
アプリコンテナから拡張指定でファイルを作成または開く。
DLLapi-ms-win-core-file-fromapp-l1-1-0.dll呼出規約winapi

シグネチャ

// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>

HANDLE CreateFile2FromAppW(
    LPCWSTR lpFileName,
    DWORD dwDesiredAccess,
    DWORD dwShareMode,
    DWORD dwCreationDisposition,
    CREATEFILE2_EXTENDED_PARAMETERS* pCreateExParams   // optional
);

パラメーター

名前方向
lpFileNameLPCWSTRin
dwDesiredAccessDWORDin
dwShareModeDWORDin
dwCreationDispositionDWORDin
pCreateExParamsCREATEFILE2_EXTENDED_PARAMETERS*inoptional

戻り値の型: HANDLE

各言語での呼び出し定義

// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>

HANDLE CreateFile2FromAppW(
    LPCWSTR lpFileName,
    DWORD dwDesiredAccess,
    DWORD dwShareMode,
    DWORD dwCreationDisposition,
    CREATEFILE2_EXTENDED_PARAMETERS* pCreateExParams   // optional
);
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling = true)]
static extern IntPtr CreateFile2FromAppW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName,   // LPCWSTR
    uint dwDesiredAccess,   // DWORD
    uint dwShareMode,   // DWORD
    uint dwCreationDisposition,   // DWORD
    IntPtr pCreateExParams   // CREATEFILE2_EXTENDED_PARAMETERS* optional
);
<DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function CreateFile2FromAppW(
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String,   ' LPCWSTR
    dwDesiredAccess As UInteger,   ' DWORD
    dwShareMode As UInteger,   ' DWORD
    dwCreationDisposition As UInteger,   ' DWORD
    pCreateExParams As IntPtr   ' CREATEFILE2_EXTENDED_PARAMETERS* optional
) As IntPtr
End Function
' lpFileName : LPCWSTR
' dwDesiredAccess : DWORD
' dwShareMode : DWORD
' dwCreationDisposition : DWORD
' pCreateExParams : CREATEFILE2_EXTENDED_PARAMETERS* optional
Declare PtrSafe Function CreateFile2FromAppW Lib "api-ms-win-core-file-fromapp-l1-1-0" ( _
    ByVal lpFileName As LongPtr, _
    ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, _
    ByVal dwCreationDisposition As Long, _
    ByVal pCreateExParams As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateFile2FromAppW = ctypes.windll.LoadLibrary("api-ms-win-core-file-fromapp-l1-1-0.dll").CreateFile2FromAppW
CreateFile2FromAppW.restype = ctypes.c_void_p
CreateFile2FromAppW.argtypes = [
    wintypes.LPCWSTR,  # lpFileName : LPCWSTR
    wintypes.DWORD,  # dwDesiredAccess : DWORD
    wintypes.DWORD,  # dwShareMode : DWORD
    wintypes.DWORD,  # dwCreationDisposition : DWORD
    ctypes.c_void_p,  # pCreateExParams : CREATEFILE2_EXTENDED_PARAMETERS* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-file-fromapp-l1-1-0.dll')
CreateFile2FromAppW = Fiddle::Function.new(
  lib['CreateFile2FromAppW'],
  [
    Fiddle::TYPE_VOIDP,  # lpFileName : LPCWSTR
    -Fiddle::TYPE_INT,  # dwDesiredAccess : DWORD
    -Fiddle::TYPE_INT,  # dwShareMode : DWORD
    -Fiddle::TYPE_INT,  # dwCreationDisposition : DWORD
    Fiddle::TYPE_VOIDP,  # pCreateExParams : CREATEFILE2_EXTENDED_PARAMETERS* optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "api-ms-win-core-file-fromapp-l1-1-0")]
extern "system" {
    fn CreateFile2FromAppW(
        lpFileName: *const u16,  // LPCWSTR
        dwDesiredAccess: u32,  // DWORD
        dwShareMode: u32,  // DWORD
        dwCreationDisposition: u32,  // DWORD
        pCreateExParams: *mut CREATEFILE2_EXTENDED_PARAMETERS  // CREATEFILE2_EXTENDED_PARAMETERS* optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll")]
public static extern IntPtr CreateFile2FromAppW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, uint dwDesiredAccess, uint dwShareMode, uint dwCreationDisposition, IntPtr pCreateExParams);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-file-fromapp-l1-1-0_CreateFile2FromAppW' -Namespace Win32 -PassThru
# $api::CreateFile2FromAppW(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, pCreateExParams)
#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#func global CreateFile2FromAppW "CreateFile2FromAppW" sptr, sptr, sptr, sptr, sptr
; CreateFile2FromAppW lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, varptr(pCreateExParams)   ; 戻り値は stat
; lpFileName : LPCWSTR -> "sptr"
; dwDesiredAccess : DWORD -> "sptr"
; dwShareMode : DWORD -> "sptr"
; dwCreationDisposition : DWORD -> "sptr"
; pCreateExParams : CREATEFILE2_EXTENDED_PARAMETERS* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#cfunc global CreateFile2FromAppW "CreateFile2FromAppW" wstr, int, int, int, var
; res = CreateFile2FromAppW(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, pCreateExParams)
; lpFileName : LPCWSTR -> "wstr"
; dwDesiredAccess : DWORD -> "int"
; dwShareMode : DWORD -> "int"
; dwCreationDisposition : DWORD -> "int"
; pCreateExParams : CREATEFILE2_EXTENDED_PARAMETERS* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE CreateFile2FromAppW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, CREATEFILE2_EXTENDED_PARAMETERS* pCreateExParams)
#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#cfunc global CreateFile2FromAppW "CreateFile2FromAppW" wstr, int, int, int, var
; res = CreateFile2FromAppW(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, pCreateExParams)
; lpFileName : LPCWSTR -> "wstr"
; dwDesiredAccess : DWORD -> "int"
; dwShareMode : DWORD -> "int"
; dwCreationDisposition : DWORD -> "int"
; pCreateExParams : CREATEFILE2_EXTENDED_PARAMETERS* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
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")
	procCreateFile2FromAppW = api_ms_win_core_file_fromapp_l1_1_0.NewProc("CreateFile2FromAppW")
)

// lpFileName (LPCWSTR), dwDesiredAccess (DWORD), dwShareMode (DWORD), dwCreationDisposition (DWORD), pCreateExParams (CREATEFILE2_EXTENDED_PARAMETERS* optional)
r1, _, err := procCreateFile2FromAppW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
	uintptr(dwDesiredAccess),
	uintptr(dwShareMode),
	uintptr(dwCreationDisposition),
	uintptr(pCreateExParams),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function CreateFile2FromAppW(
  lpFileName: PWideChar;   // LPCWSTR
  dwDesiredAccess: DWORD;   // DWORD
  dwShareMode: DWORD;   // DWORD
  dwCreationDisposition: DWORD;   // DWORD
  pCreateExParams: Pointer   // CREATEFILE2_EXTENDED_PARAMETERS* optional
): THandle; stdcall;
  external 'api-ms-win-core-file-fromapp-l1-1-0.dll' name 'CreateFile2FromAppW';
result := DllCall("api-ms-win-core-file-fromapp-l1-1-0\CreateFile2FromAppW"
    , "WStr", lpFileName   ; LPCWSTR
    , "UInt", dwDesiredAccess   ; DWORD
    , "UInt", dwShareMode   ; DWORD
    , "UInt", dwCreationDisposition   ; DWORD
    , "Ptr", pCreateExParams   ; CREATEFILE2_EXTENDED_PARAMETERS* optional
    , "Ptr")   ; return: HANDLE
●CreateFile2FromAppW(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, pCreateExParams) = DLL("api-ms-win-core-file-fromapp-l1-1-0.dll", "void* CreateFile2FromAppW(char*, dword, dword, dword, void*)")
# 呼び出し: CreateFile2FromAppW(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, pCreateExParams)
# lpFileName : LPCWSTR -> "char*"
# dwDesiredAccess : DWORD -> "dword"
# dwShareMode : DWORD -> "dword"
# dwCreationDisposition : DWORD -> "dword"
# pCreateExParams : CREATEFILE2_EXTENDED_PARAMETERS* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。