Win32 API 日本語リファレンス
ホームSystem.Memory › CreateFileMapping2

CreateFileMapping2

関数
拡張パラメータを指定してファイルマッピングオブジェクトを作成する。
DLLapi-ms-win-core-memory-l1-1-7.dll呼出規約winapiSetLastErrorあり

シグネチャ

// api-ms-win-core-memory-l1-1-7.dll
#include <windows.h>

HANDLE CreateFileMapping2(
    HANDLE File,
    SECURITY_ATTRIBUTES* SecurityAttributes,   // optional
    DWORD DesiredAccess,
    PAGE_PROTECTION_FLAGS PageProtection,
    DWORD AllocationAttributes,
    ULONGLONG MaximumSize,
    LPCWSTR Name,   // optional
    MEM_EXTENDED_PARAMETER* ExtendedParameters,   // optional
    DWORD ParameterCount
);

パラメーター

名前方向
FileHANDLEin
SecurityAttributesSECURITY_ATTRIBUTES*inoptional
DesiredAccessDWORDin
PageProtectionPAGE_PROTECTION_FLAGSin
AllocationAttributesDWORDin
MaximumSizeULONGLONGin
NameLPCWSTRinoptional
ExtendedParametersMEM_EXTENDED_PARAMETER*inoutoptional
ParameterCountDWORDin

戻り値の型: HANDLE

各言語での呼び出し定義

// api-ms-win-core-memory-l1-1-7.dll
#include <windows.h>

HANDLE CreateFileMapping2(
    HANDLE File,
    SECURITY_ATTRIBUTES* SecurityAttributes,   // optional
    DWORD DesiredAccess,
    PAGE_PROTECTION_FLAGS PageProtection,
    DWORD AllocationAttributes,
    ULONGLONG MaximumSize,
    LPCWSTR Name,   // optional
    MEM_EXTENDED_PARAMETER* ExtendedParameters,   // optional
    DWORD ParameterCount
);
[DllImport("api-ms-win-core-memory-l1-1-7.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateFileMapping2(
    IntPtr File,   // HANDLE
    IntPtr SecurityAttributes,   // SECURITY_ATTRIBUTES* optional
    uint DesiredAccess,   // DWORD
    uint PageProtection,   // PAGE_PROTECTION_FLAGS
    uint AllocationAttributes,   // DWORD
    ulong MaximumSize,   // ULONGLONG
    [MarshalAs(UnmanagedType.LPWStr)] string Name,   // LPCWSTR optional
    IntPtr ExtendedParameters,   // MEM_EXTENDED_PARAMETER* optional, in/out
    uint ParameterCount   // DWORD
);
<DllImport("api-ms-win-core-memory-l1-1-7.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateFileMapping2(
    File As IntPtr,   ' HANDLE
    SecurityAttributes As IntPtr,   ' SECURITY_ATTRIBUTES* optional
    DesiredAccess As UInteger,   ' DWORD
    PageProtection As UInteger,   ' PAGE_PROTECTION_FLAGS
    AllocationAttributes As UInteger,   ' DWORD
    MaximumSize As ULong,   ' ULONGLONG
    <MarshalAs(UnmanagedType.LPWStr)> Name As String,   ' LPCWSTR optional
    ExtendedParameters As IntPtr,   ' MEM_EXTENDED_PARAMETER* optional, in/out
    ParameterCount As UInteger   ' DWORD
) As IntPtr
End Function
' File : HANDLE
' SecurityAttributes : SECURITY_ATTRIBUTES* optional
' DesiredAccess : DWORD
' PageProtection : PAGE_PROTECTION_FLAGS
' AllocationAttributes : DWORD
' MaximumSize : ULONGLONG
' Name : LPCWSTR optional
' ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
' ParameterCount : DWORD
Declare PtrSafe Function CreateFileMapping2 Lib "api-ms-win-core-memory-l1-1-7" ( _
    ByVal File As LongPtr, _
    ByVal SecurityAttributes As LongPtr, _
    ByVal DesiredAccess As Long, _
    ByVal PageProtection As Long, _
    ByVal AllocationAttributes As Long, _
    ByVal MaximumSize As LongLong, _
    ByVal Name As LongPtr, _
    ByVal ExtendedParameters As LongPtr, _
    ByVal ParameterCount As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateFileMapping2 = ctypes.windll.LoadLibrary("api-ms-win-core-memory-l1-1-7.dll").CreateFileMapping2
CreateFileMapping2.restype = ctypes.c_void_p
CreateFileMapping2.argtypes = [
    wintypes.HANDLE,  # File : HANDLE
    ctypes.c_void_p,  # SecurityAttributes : SECURITY_ATTRIBUTES* optional
    wintypes.DWORD,  # DesiredAccess : DWORD
    wintypes.DWORD,  # PageProtection : PAGE_PROTECTION_FLAGS
    wintypes.DWORD,  # AllocationAttributes : DWORD
    ctypes.c_ulonglong,  # MaximumSize : ULONGLONG
    wintypes.LPCWSTR,  # Name : LPCWSTR optional
    ctypes.c_void_p,  # ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
    wintypes.DWORD,  # ParameterCount : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-memory-l1-1-7.dll')
CreateFileMapping2 = Fiddle::Function.new(
  lib['CreateFileMapping2'],
  [
    Fiddle::TYPE_VOIDP,  # File : HANDLE
    Fiddle::TYPE_VOIDP,  # SecurityAttributes : SECURITY_ATTRIBUTES* optional
    -Fiddle::TYPE_INT,  # DesiredAccess : DWORD
    -Fiddle::TYPE_INT,  # PageProtection : PAGE_PROTECTION_FLAGS
    -Fiddle::TYPE_INT,  # AllocationAttributes : DWORD
    -Fiddle::TYPE_LONG_LONG,  # MaximumSize : ULONGLONG
    Fiddle::TYPE_VOIDP,  # Name : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out
    -Fiddle::TYPE_INT,  # ParameterCount : DWORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "api-ms-win-core-memory-l1-1-7")]
extern "system" {
    fn CreateFileMapping2(
        File: *mut core::ffi::c_void,  // HANDLE
        SecurityAttributes: *mut SECURITY_ATTRIBUTES,  // SECURITY_ATTRIBUTES* optional
        DesiredAccess: u32,  // DWORD
        PageProtection: u32,  // PAGE_PROTECTION_FLAGS
        AllocationAttributes: u32,  // DWORD
        MaximumSize: u64,  // ULONGLONG
        Name: *const u16,  // LPCWSTR optional
        ExtendedParameters: *mut MEM_EXTENDED_PARAMETER,  // MEM_EXTENDED_PARAMETER* optional, in/out
        ParameterCount: u32  // DWORD
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("api-ms-win-core-memory-l1-1-7.dll", SetLastError = true)]
public static extern IntPtr CreateFileMapping2(IntPtr File, IntPtr SecurityAttributes, uint DesiredAccess, uint PageProtection, uint AllocationAttributes, ulong MaximumSize, [MarshalAs(UnmanagedType.LPWStr)] string Name, IntPtr ExtendedParameters, uint ParameterCount);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-memory-l1-1-7_CreateFileMapping2' -Namespace Win32 -PassThru
# $api::CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount)
#uselib "api-ms-win-core-memory-l1-1-7.dll"
#func global CreateFileMapping2 "CreateFileMapping2" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CreateFileMapping2 File, varptr(SecurityAttributes), DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, varptr(ExtendedParameters), ParameterCount   ; 戻り値は stat
; File : HANDLE -> "sptr"
; SecurityAttributes : SECURITY_ATTRIBUTES* optional -> "sptr"
; DesiredAccess : DWORD -> "sptr"
; PageProtection : PAGE_PROTECTION_FLAGS -> "sptr"
; AllocationAttributes : DWORD -> "sptr"
; MaximumSize : ULONGLONG -> "sptr"
; Name : LPCWSTR optional -> "sptr"
; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "sptr"
; ParameterCount : DWORD -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-memory-l1-1-7.dll"
#cfunc global CreateFileMapping2 "CreateFileMapping2" sptr, var, int, int, int, int64, wstr, var, int
; res = CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount)
; File : HANDLE -> "sptr"
; SecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; DesiredAccess : DWORD -> "int"
; PageProtection : PAGE_PROTECTION_FLAGS -> "int"
; AllocationAttributes : DWORD -> "int"
; MaximumSize : ULONGLONG -> "int64"
; Name : LPCWSTR optional -> "wstr"
; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "var"
; ParameterCount : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; HANDLE CreateFileMapping2(HANDLE File, SECURITY_ATTRIBUTES* SecurityAttributes, DWORD DesiredAccess, PAGE_PROTECTION_FLAGS PageProtection, DWORD AllocationAttributes, ULONGLONG MaximumSize, LPCWSTR Name, MEM_EXTENDED_PARAMETER* ExtendedParameters, DWORD ParameterCount)
#uselib "api-ms-win-core-memory-l1-1-7.dll"
#cfunc global CreateFileMapping2 "CreateFileMapping2" intptr, var, int, int, int, int64, wstr, var, int
; res = CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount)
; File : HANDLE -> "intptr"
; SecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; DesiredAccess : DWORD -> "int"
; PageProtection : PAGE_PROTECTION_FLAGS -> "int"
; AllocationAttributes : DWORD -> "int"
; MaximumSize : ULONGLONG -> "int64"
; Name : LPCWSTR optional -> "wstr"
; ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "var"
; ParameterCount : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_core_memory_l1_1_7 = windows.NewLazySystemDLL("api-ms-win-core-memory-l1-1-7.dll")
	procCreateFileMapping2 = api_ms_win_core_memory_l1_1_7.NewProc("CreateFileMapping2")
)

// File (HANDLE), SecurityAttributes (SECURITY_ATTRIBUTES* optional), DesiredAccess (DWORD), PageProtection (PAGE_PROTECTION_FLAGS), AllocationAttributes (DWORD), MaximumSize (ULONGLONG), Name (LPCWSTR optional), ExtendedParameters (MEM_EXTENDED_PARAMETER* optional, in/out), ParameterCount (DWORD)
r1, _, err := procCreateFileMapping2.Call(
	uintptr(File),
	uintptr(SecurityAttributes),
	uintptr(DesiredAccess),
	uintptr(PageProtection),
	uintptr(AllocationAttributes),
	uintptr(MaximumSize),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Name))),
	uintptr(ExtendedParameters),
	uintptr(ParameterCount),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function CreateFileMapping2(
  File: THandle;   // HANDLE
  SecurityAttributes: Pointer;   // SECURITY_ATTRIBUTES* optional
  DesiredAccess: DWORD;   // DWORD
  PageProtection: DWORD;   // PAGE_PROTECTION_FLAGS
  AllocationAttributes: DWORD;   // DWORD
  MaximumSize: UInt64;   // ULONGLONG
  Name: PWideChar;   // LPCWSTR optional
  ExtendedParameters: Pointer;   // MEM_EXTENDED_PARAMETER* optional, in/out
  ParameterCount: DWORD   // DWORD
): THandle; stdcall;
  external 'api-ms-win-core-memory-l1-1-7.dll' name 'CreateFileMapping2';
result := DllCall("api-ms-win-core-memory-l1-1-7\CreateFileMapping2"
    , "Ptr", File   ; HANDLE
    , "Ptr", SecurityAttributes   ; SECURITY_ATTRIBUTES* optional
    , "UInt", DesiredAccess   ; DWORD
    , "UInt", PageProtection   ; PAGE_PROTECTION_FLAGS
    , "UInt", AllocationAttributes   ; DWORD
    , "Int64", MaximumSize   ; ULONGLONG
    , "WStr", Name   ; LPCWSTR optional
    , "Ptr", ExtendedParameters   ; MEM_EXTENDED_PARAMETER* optional, in/out
    , "UInt", ParameterCount   ; DWORD
    , "Ptr")   ; return: HANDLE
●CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount) = DLL("api-ms-win-core-memory-l1-1-7.dll", "void* CreateFileMapping2(void*, void*, dword, dword, dword, qword, char*, void*, dword)")
# 呼び出し: CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount)
# File : HANDLE -> "void*"
# SecurityAttributes : SECURITY_ATTRIBUTES* optional -> "void*"
# DesiredAccess : DWORD -> "dword"
# PageProtection : PAGE_PROTECTION_FLAGS -> "dword"
# AllocationAttributes : DWORD -> "dword"
# MaximumSize : ULONGLONG -> "qword"
# Name : LPCWSTR optional -> "char*"
# ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "void*"
# ParameterCount : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。