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

CreateFile3

関数
拡張パラメータを指定してファイルを作成または開く。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

// KERNEL32.dll
#include <windows.h>

HANDLE CreateFile3(
    LPCWSTR lpFileName,
    DWORD dwDesiredAccess,
    DWORD dwShareMode,
    DWORD dwCreationDisposition,
    CREATEFILE3_EXTENDED_PARAMETERS* pCreateExParams   // optional
);

パラメーター

名前方向
lpFileNameLPCWSTRin
dwDesiredAccessDWORDin
dwShareModeDWORDin
dwCreationDispositionDWORDin
pCreateExParamsCREATEFILE3_EXTENDED_PARAMETERS*inoptional

戻り値の型: HANDLE

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

HANDLE CreateFile3(
    LPCWSTR lpFileName,
    DWORD dwDesiredAccess,
    DWORD dwShareMode,
    DWORD dwCreationDisposition,
    CREATEFILE3_EXTENDED_PARAMETERS* pCreateExParams   // optional
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern IntPtr CreateFile3(
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName,   // LPCWSTR
    uint dwDesiredAccess,   // DWORD
    uint dwShareMode,   // DWORD
    uint dwCreationDisposition,   // DWORD
    IntPtr pCreateExParams   // CREATEFILE3_EXTENDED_PARAMETERS* optional
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function CreateFile3(
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String,   ' LPCWSTR
    dwDesiredAccess As UInteger,   ' DWORD
    dwShareMode As UInteger,   ' DWORD
    dwCreationDisposition As UInteger,   ' DWORD
    pCreateExParams As IntPtr   ' CREATEFILE3_EXTENDED_PARAMETERS* optional
) As IntPtr
End Function
' lpFileName : LPCWSTR
' dwDesiredAccess : DWORD
' dwShareMode : DWORD
' dwCreationDisposition : DWORD
' pCreateExParams : CREATEFILE3_EXTENDED_PARAMETERS* optional
Declare PtrSafe Function CreateFile3 Lib "kernel32" ( _
    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

CreateFile3 = ctypes.windll.kernel32.CreateFile3
CreateFile3.restype = ctypes.c_void_p
CreateFile3.argtypes = [
    wintypes.LPCWSTR,  # lpFileName : LPCWSTR
    wintypes.DWORD,  # dwDesiredAccess : DWORD
    wintypes.DWORD,  # dwShareMode : DWORD
    wintypes.DWORD,  # dwCreationDisposition : DWORD
    ctypes.c_void_p,  # pCreateExParams : CREATEFILE3_EXTENDED_PARAMETERS* optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCreateFile3 = kernel32.NewProc("CreateFile3")
)

// lpFileName (LPCWSTR), dwDesiredAccess (DWORD), dwShareMode (DWORD), dwCreationDisposition (DWORD), pCreateExParams (CREATEFILE3_EXTENDED_PARAMETERS* optional)
r1, _, err := procCreateFile3.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 CreateFile3(
  lpFileName: PWideChar;   // LPCWSTR
  dwDesiredAccess: DWORD;   // DWORD
  dwShareMode: DWORD;   // DWORD
  dwCreationDisposition: DWORD;   // DWORD
  pCreateExParams: Pointer   // CREATEFILE3_EXTENDED_PARAMETERS* optional
): THandle; stdcall;
  external 'KERNEL32.dll' name 'CreateFile3';
result := DllCall("KERNEL32\CreateFile3"
    , "WStr", lpFileName   ; LPCWSTR
    , "UInt", dwDesiredAccess   ; DWORD
    , "UInt", dwShareMode   ; DWORD
    , "UInt", dwCreationDisposition   ; DWORD
    , "Ptr", pCreateExParams   ; CREATEFILE3_EXTENDED_PARAMETERS* optional
    , "Ptr")   ; return: HANDLE
●CreateFile3(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, pCreateExParams) = DLL("KERNEL32.dll", "void* CreateFile3(char*, dword, dword, dword, void*)")
# 呼び出し: CreateFile3(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, pCreateExParams)
# lpFileName : LPCWSTR -> "char*"
# dwDesiredAccess : DWORD -> "dword"
# dwShareMode : DWORD -> "dword"
# dwCreationDisposition : DWORD -> "dword"
# pCreateExParams : CREATEFILE3_EXTENDED_PARAMETERS* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。