ホーム › Storage.FileSystem › CreateFileFromAppW
CreateFileFromAppW
関数アプリコンテナからファイルを作成または開く。
シグネチャ
// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>
HANDLE CreateFileFromAppW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
SECURITY_ATTRIBUTES* lpSecurityAttributes, // optional
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpFileName | LPCWSTR | in |
| dwDesiredAccess | DWORD | in |
| dwShareMode | DWORD | in |
| lpSecurityAttributes | SECURITY_ATTRIBUTES* | inoptional |
| dwCreationDisposition | DWORD | in |
| dwFlagsAndAttributes | DWORD | in |
| hTemplateFile | HANDLE | inoptional |
戻り値の型: HANDLE
各言語での呼び出し定義
// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>
HANDLE CreateFileFromAppW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
SECURITY_ATTRIBUTES* lpSecurityAttributes, // optional
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile // optional
);[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling = true)]
static extern IntPtr CreateFileFromAppW(
[MarshalAs(UnmanagedType.LPWStr)] string lpFileName, // LPCWSTR
uint dwDesiredAccess, // DWORD
uint dwShareMode, // DWORD
IntPtr lpSecurityAttributes, // SECURITY_ATTRIBUTES* optional
uint dwCreationDisposition, // DWORD
uint dwFlagsAndAttributes, // DWORD
IntPtr hTemplateFile // HANDLE optional
);<DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function CreateFileFromAppW(
<MarshalAs(UnmanagedType.LPWStr)> lpFileName As String, ' LPCWSTR
dwDesiredAccess As UInteger, ' DWORD
dwShareMode As UInteger, ' DWORD
lpSecurityAttributes As IntPtr, ' SECURITY_ATTRIBUTES* optional
dwCreationDisposition As UInteger, ' DWORD
dwFlagsAndAttributes As UInteger, ' DWORD
hTemplateFile As IntPtr ' HANDLE optional
) As IntPtr
End Function' lpFileName : LPCWSTR
' dwDesiredAccess : DWORD
' dwShareMode : DWORD
' lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
' dwCreationDisposition : DWORD
' dwFlagsAndAttributes : DWORD
' hTemplateFile : HANDLE optional
Declare PtrSafe Function CreateFileFromAppW Lib "api-ms-win-core-file-fromapp-l1-1-0" ( _
ByVal lpFileName As LongPtr, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As LongPtr, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CreateFileFromAppW = ctypes.windll.LoadLibrary("api-ms-win-core-file-fromapp-l1-1-0.dll").CreateFileFromAppW
CreateFileFromAppW.restype = ctypes.c_void_p
CreateFileFromAppW.argtypes = [
wintypes.LPCWSTR, # lpFileName : LPCWSTR
wintypes.DWORD, # dwDesiredAccess : DWORD
wintypes.DWORD, # dwShareMode : DWORD
ctypes.c_void_p, # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
wintypes.DWORD, # dwCreationDisposition : DWORD
wintypes.DWORD, # dwFlagsAndAttributes : DWORD
wintypes.HANDLE, # hTemplateFile : HANDLE optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-file-fromapp-l1-1-0.dll')
CreateFileFromAppW = Fiddle::Function.new(
lib['CreateFileFromAppW'],
[
Fiddle::TYPE_VOIDP, # lpFileName : LPCWSTR
-Fiddle::TYPE_INT, # dwDesiredAccess : DWORD
-Fiddle::TYPE_INT, # dwShareMode : DWORD
Fiddle::TYPE_VOIDP, # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
-Fiddle::TYPE_INT, # dwCreationDisposition : DWORD
-Fiddle::TYPE_INT, # dwFlagsAndAttributes : DWORD
Fiddle::TYPE_VOIDP, # hTemplateFile : HANDLE optional
],
Fiddle::TYPE_VOIDP)#[link(name = "api-ms-win-core-file-fromapp-l1-1-0")]
extern "system" {
fn CreateFileFromAppW(
lpFileName: *const u16, // LPCWSTR
dwDesiredAccess: u32, // DWORD
dwShareMode: u32, // DWORD
lpSecurityAttributes: *mut SECURITY_ATTRIBUTES, // SECURITY_ATTRIBUTES* optional
dwCreationDisposition: u32, // DWORD
dwFlagsAndAttributes: u32, // DWORD
hTemplateFile: *mut core::ffi::c_void // HANDLE 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 CreateFileFromAppW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-file-fromapp-l1-1-0_CreateFileFromAppW' -Namespace Win32 -PassThru
# $api::CreateFileFromAppW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#func global CreateFileFromAppW "CreateFileFromAppW" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CreateFileFromAppW lpFileName, dwDesiredAccess, dwShareMode, varptr(lpSecurityAttributes), dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile ; 戻り値は stat
; lpFileName : LPCWSTR -> "sptr"
; dwDesiredAccess : DWORD -> "sptr"
; dwShareMode : DWORD -> "sptr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "sptr"
; dwCreationDisposition : DWORD -> "sptr"
; dwFlagsAndAttributes : DWORD -> "sptr"
; hTemplateFile : HANDLE optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll" #cfunc global CreateFileFromAppW "CreateFileFromAppW" wstr, int, int, var, int, int, sptr ; res = CreateFileFromAppW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile) ; lpFileName : LPCWSTR -> "wstr" ; dwDesiredAccess : DWORD -> "int" ; dwShareMode : DWORD -> "int" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var" ; dwCreationDisposition : DWORD -> "int" ; dwFlagsAndAttributes : DWORD -> "int" ; hTemplateFile : HANDLE optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll" #cfunc global CreateFileFromAppW "CreateFileFromAppW" wstr, int, int, sptr, int, int, sptr ; res = CreateFileFromAppW(lpFileName, dwDesiredAccess, dwShareMode, varptr(lpSecurityAttributes), dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile) ; lpFileName : LPCWSTR -> "wstr" ; dwDesiredAccess : DWORD -> "int" ; dwShareMode : DWORD -> "int" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "sptr" ; dwCreationDisposition : DWORD -> "int" ; dwFlagsAndAttributes : DWORD -> "int" ; hTemplateFile : HANDLE optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HANDLE CreateFileFromAppW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, SECURITY_ATTRIBUTES* lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) #uselib "api-ms-win-core-file-fromapp-l1-1-0.dll" #cfunc global CreateFileFromAppW "CreateFileFromAppW" wstr, int, int, var, int, int, intptr ; res = CreateFileFromAppW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile) ; lpFileName : LPCWSTR -> "wstr" ; dwDesiredAccess : DWORD -> "int" ; dwShareMode : DWORD -> "int" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var" ; dwCreationDisposition : DWORD -> "int" ; dwFlagsAndAttributes : DWORD -> "int" ; hTemplateFile : HANDLE optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HANDLE CreateFileFromAppW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, SECURITY_ATTRIBUTES* lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) #uselib "api-ms-win-core-file-fromapp-l1-1-0.dll" #cfunc global CreateFileFromAppW "CreateFileFromAppW" wstr, int, int, intptr, int, int, intptr ; res = CreateFileFromAppW(lpFileName, dwDesiredAccess, dwShareMode, varptr(lpSecurityAttributes), dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile) ; lpFileName : LPCWSTR -> "wstr" ; dwDesiredAccess : DWORD -> "int" ; dwShareMode : DWORD -> "int" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "intptr" ; dwCreationDisposition : DWORD -> "int" ; dwFlagsAndAttributes : DWORD -> "int" ; hTemplateFile : HANDLE optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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")
procCreateFileFromAppW = api_ms_win_core_file_fromapp_l1_1_0.NewProc("CreateFileFromAppW")
)
// lpFileName (LPCWSTR), dwDesiredAccess (DWORD), dwShareMode (DWORD), lpSecurityAttributes (SECURITY_ATTRIBUTES* optional), dwCreationDisposition (DWORD), dwFlagsAndAttributes (DWORD), hTemplateFile (HANDLE optional)
r1, _, err := procCreateFileFromAppW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
uintptr(dwDesiredAccess),
uintptr(dwShareMode),
uintptr(lpSecurityAttributes),
uintptr(dwCreationDisposition),
uintptr(dwFlagsAndAttributes),
uintptr(hTemplateFile),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction CreateFileFromAppW(
lpFileName: PWideChar; // LPCWSTR
dwDesiredAccess: DWORD; // DWORD
dwShareMode: DWORD; // DWORD
lpSecurityAttributes: Pointer; // SECURITY_ATTRIBUTES* optional
dwCreationDisposition: DWORD; // DWORD
dwFlagsAndAttributes: DWORD; // DWORD
hTemplateFile: THandle // HANDLE optional
): THandle; stdcall;
external 'api-ms-win-core-file-fromapp-l1-1-0.dll' name 'CreateFileFromAppW';result := DllCall("api-ms-win-core-file-fromapp-l1-1-0\CreateFileFromAppW"
, "WStr", lpFileName ; LPCWSTR
, "UInt", dwDesiredAccess ; DWORD
, "UInt", dwShareMode ; DWORD
, "Ptr", lpSecurityAttributes ; SECURITY_ATTRIBUTES* optional
, "UInt", dwCreationDisposition ; DWORD
, "UInt", dwFlagsAndAttributes ; DWORD
, "Ptr", hTemplateFile ; HANDLE optional
, "Ptr") ; return: HANDLE●CreateFileFromAppW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile) = DLL("api-ms-win-core-file-fromapp-l1-1-0.dll", "void* CreateFileFromAppW(char*, dword, dword, void*, dword, dword, void*)")
# 呼び出し: CreateFileFromAppW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)
# lpFileName : LPCWSTR -> "char*"
# dwDesiredAccess : DWORD -> "dword"
# dwShareMode : DWORD -> "dword"
# lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "void*"
# dwCreationDisposition : DWORD -> "dword"
# dwFlagsAndAttributes : DWORD -> "dword"
# hTemplateFile : HANDLE optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。