CreateFileMapping2
関数シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| File | HANDLE | in | ファイルマッピングオブジェクトを作成する元となるファイルへのハンドルです。 ファイルは、flProtect パラメーターで指定する保護フラグと互換性のあるアクセス権で開く必要があります。必須ではありませんが、マッピングするファイルは排他アクセスで開くことを推奨します。詳細については、File security and access rights を参照してください。 hFile が INVALID_HANDLE_VALUE の場合、呼び出し側プロセスは dwMaximumSizeHigh および dwMaximumSizeLow パラメーターでファイルマッピングオブジェクトのサイズも指定する必要があります。この場合、CreateFileMapping は、ファイルシステム上のファイルではなくシステムのページングファイルによってバックされる、指定したサイズのファイルマッピングオブジェクトを作成します。 | ||||||||||||||||
| SecurityAttributes | SECURITY_ATTRIBUTES* | inoptional | 返されるハンドルを子プロセスが継承できるかどうかを決定する SECURITY_ATTRIBUTES 構造体へのポインターです。SECURITY_ATTRIBUTES 構造体の lpSecurityDescriptor メンバーは、新しいファイルマッピングオブジェクトのセキュリティ記述子を指定します。 lpAttributes が NULL の場合、ハンドルは継承できず、ファイルマッピングオブジェクトには既定のセキュリティ記述子が設定されます。ファイルマッピングオブジェクトの既定のセキュリティ記述子に含まれるアクセス制御リスト (ACL) は、作成者のプライマリトークンまたは偽装トークンに由来します。詳細については、File Mapping Security and Access Rights を参照してください。 | ||||||||||||||||
| DesiredAccess | DWORD | in | 返されるファイルマッピングハンドルに対して要求するアクセスマスクです。アクセス権の一覧については、File-mapping security and access rights を参照してください。 | ||||||||||||||||
| PageProtection | PAGE_PROTECTION_FLAGS | in | ファイルマッピングオブジェクトのページ保護を指定します。オブジェクトのすべてのマップされたビューは、この保護と互換性がある必要があります。 このパラメーターには、次のいずれかの値を指定できます。
| ||||||||||||||||
| AllocationAttributes | DWORD | in | ファイルマッピングオブジェクトに対して、次の属性を 1 つ以上指定できます。PageProtection パラメーターも参照してください。
| ||||||||||||||||
| MaximumSize | ULONGLONG | in | ファイルマッピングオブジェクトの最大サイズです。 このパラメーターが 0 (ゼロ) の場合、ファイルマッピングオブジェクトの最大サイズは、hFile が識別するファイルの現在のサイズと等しくなります。 長さが 0 (ゼロ) のファイルをマップしようとすると、エラーコード ERROR_FILE_INVALID で失敗します。長さが 0 (ゼロ) のファイルをテストし、そのようなファイルは拒否してください。 | ||||||||||||||||
| Name | LPCWSTR | inoptional | ファイルマッピングオブジェクトの名前です。 このパラメーターが既存のマッピングオブジェクトの名前と一致する場合、関数は flProtect で指定する保護でそのオブジェクトへのアクセスを要求します。 このパラメーターが NULL の場合、ファイルマッピングオブジェクトは名前なしで作成されます。 lpName が既存のイベント、セマフォ、ミューテックス、待機可能タイマー、またはジョブオブジェクトの名前と一致する場合、関数は失敗し、GetLastError 関数は ERROR_INVALID_HANDLE を返します。これは、これらのオブジェクトが同じ名前空間を共有するために発生します。 名前には、グローバル名前空間またはセッション名前空間にオブジェクトを明示的に作成するために、「Global\」または「Local\」のプレフィックスを付けることができます。名前の残りの部分には、円記号 (\) を除く任意の文字を含めることができます。セッション 0 以外のセッションからグローバル名前空間にファイルマッピングオブジェクトを作成するには、SeCreateGlobalPrivilege 特権が必要です。詳細については、Kernel Object Namespaces を参照してください。 高速ユーザー切り替えは、ターミナルサービスセッションを使用して実装されています。最初にログオンするユーザーはセッション 0 (ゼロ) を使用し、次にログオンするユーザーはセッション 1 (1) を使用する、というように続きます。アプリケーションが複数のユーザーをサポートできるように、カーネルオブジェクト名はターミナルサービスについて示されたガイドラインに従う必要があります。 | ||||||||||||||||
| ExtendedParameters | MEM_EXTENDED_PARAMETER* | inoutoptional | MEM_EXTENDED_PARAMETER 型の 1 つ以上の拡張パラメーターへの省略可能なポインターです。これらの拡張パラメーター値はそれぞれ、MemExtendedParameterAddressRequirements または MemExtendedParameterNumaNode のいずれかの Type フィールドを持つことができます。MemExtendedParameterNumaNode 拡張パラメーターが指定されていない場合、動作は VirtualAlloc/MapViewOfFile 関数と同じになります (つまり、物理ページに優先的に使用される NUMA ノードは、最初にメモリにアクセスするスレッドの理想プロセッサに基づいて決定されます)。 | ||||||||||||||||
| ParameterCount | DWORD | in | In ULONG ParameterCount ExtendedParameters が指す拡張パラメーターの数です。 |
戻り値の型: HANDLE
公式ドキュメント
指定したファイルに対する、名前付きまたは名前なしのファイルマッピングオブジェクトを作成または開きます。拡張パラメーターとして、物理メモリに優先的に使用する NUMA ノードを指定できます。ExtendedParameters パラメーターを参照してください。
戻り値
関数が成功した場合、戻り値は新しく作成されたファイルマッピングオブジェクトへのハンドルです。
関数呼び出しの前にオブジェクトが存在していた場合、関数は既存のオブジェクトへのハンドル (指定したサイズではなく、現在のサイズを持つもの) を返し、GetLastError は ERROR_ALREADY_EXISTS を返します。
関数が失敗した場合、戻り値は NULL です。拡張エラー情報を取得するには、GetLastError を呼び出します。
解説(Remarks)
CreateFileMapping の 解説 を参照してください。
例
例については、Creating named shared memory または Creating a file mapping using large pages を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 は未対応)。#uselib "api-ms-win-core-memory-l1-1-7.dll" #cfunc global CreateFileMapping2 "CreateFileMapping2" sptr, sptr, int, int, int, int64, wstr, sptr, int ; res = CreateFileMapping2(File, varptr(SecurityAttributes), DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, varptr(ExtendedParameters), ParameterCount) ; File : HANDLE -> "sptr" ; SecurityAttributes : SECURITY_ATTRIBUTES* optional -> "sptr" ; 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 -> "sptr" ; ParameterCount : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, int, int, int, int64, wstr, intptr, int ; res = CreateFileMapping2(File, varptr(SecurityAttributes), DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, varptr(ExtendedParameters), ParameterCount) ; File : HANDLE -> "intptr" ; SecurityAttributes : SECURITY_ATTRIBUTES* optional -> "intptr" ; 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 -> "intptr" ; ParameterCount : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // HANDLEfunction 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)。const std = @import("std");
extern "api-ms-win-core-memory-l1-1-7" fn CreateFileMapping2(
File: ?*anyopaque, // HANDLE
SecurityAttributes: [*c]SECURITY_ATTRIBUTES, // SECURITY_ATTRIBUTES* optional
DesiredAccess: u32, // DWORD
PageProtection: u32, // PAGE_PROTECTION_FLAGS
AllocationAttributes: u32, // DWORD
MaximumSize: u64, // ULONGLONG
Name: [*c]const u16, // LPCWSTR optional
ExtendedParameters: [*c]MEM_EXTENDED_PARAMETER, // MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc CreateFileMapping2(
File: pointer, # HANDLE
SecurityAttributes: ptr SECURITY_ATTRIBUTES, # SECURITY_ATTRIBUTES* optional
DesiredAccess: uint32, # DWORD
PageProtection: uint32, # PAGE_PROTECTION_FLAGS
AllocationAttributes: uint32, # DWORD
MaximumSize: uint64, # ULONGLONG
Name: WideCString, # LPCWSTR optional
ExtendedParameters: ptr MEM_EXTENDED_PARAMETER, # MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount: uint32 # DWORD
): pointer {.importc: "CreateFileMapping2", stdcall, dynlib: "api-ms-win-core-memory-l1-1-7.dll".}pragma(lib, "api-ms-win-core-memory-l1-1-7");
extern(Windows)
void* CreateFileMapping2(
void* File, // HANDLE
SECURITY_ATTRIBUTES* SecurityAttributes, // SECURITY_ATTRIBUTES* optional
uint DesiredAccess, // DWORD
uint PageProtection, // PAGE_PROTECTION_FLAGS
uint AllocationAttributes, // DWORD
ulong MaximumSize, // ULONGLONG
const(wchar)* Name, // LPCWSTR optional
MEM_EXTENDED_PARAMETER* ExtendedParameters, // MEM_EXTENDED_PARAMETER* optional, in/out
uint ParameterCount // DWORD
);ccall((:CreateFileMapping2, "api-ms-win-core-memory-l1-1-7.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid}, Ptr{SECURITY_ATTRIBUTES}, UInt32, UInt32, UInt32, UInt64, Cwstring, Ptr{MEM_EXTENDED_PARAMETER}, UInt32),
File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount)
# File : HANDLE -> Ptr{Cvoid}
# SecurityAttributes : SECURITY_ATTRIBUTES* optional -> Ptr{SECURITY_ATTRIBUTES}
# DesiredAccess : DWORD -> UInt32
# PageProtection : PAGE_PROTECTION_FLAGS -> UInt32
# AllocationAttributes : DWORD -> UInt32
# MaximumSize : ULONGLONG -> UInt64
# Name : LPCWSTR optional -> Cwstring
# ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> Ptr{MEM_EXTENDED_PARAMETER}
# ParameterCount : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* CreateFileMapping2(
void* File,
void* SecurityAttributes,
uint32_t DesiredAccess,
uint32_t PageProtection,
uint32_t AllocationAttributes,
uint64_t MaximumSize,
const uint16_t* Name,
void* ExtendedParameters,
uint32_t ParameterCount);
]]
local api-ms-win-core-memory-l1-1-7 = ffi.load("api-ms-win-core-memory-l1-1-7")
-- api-ms-win-core-memory-l1-1-7.CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-memory-l1-1-7.dll');
const CreateFileMapping2 = lib.func('__stdcall', 'CreateFileMapping2', 'void *', ['void *', 'void *', 'uint32_t', 'uint32_t', 'uint32_t', 'uint64_t', 'str16', 'void *', 'uint32_t']);
// CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount)
// File : HANDLE -> 'void *'
// SecurityAttributes : SECURITY_ATTRIBUTES* optional -> 'void *'
// DesiredAccess : DWORD -> 'uint32_t'
// PageProtection : PAGE_PROTECTION_FLAGS -> 'uint32_t'
// AllocationAttributes : DWORD -> 'uint32_t'
// MaximumSize : ULONGLONG -> 'uint64_t'
// Name : LPCWSTR optional -> 'str16'
// ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> 'void *'
// ParameterCount : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-memory-l1-1-7.dll", {
CreateFileMapping2: { parameters: ["pointer", "pointer", "u32", "u32", "u32", "u64", "buffer", "pointer", "u32"], result: "pointer" },
});
// lib.symbols.CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount)
// File : HANDLE -> "pointer"
// SecurityAttributes : SECURITY_ATTRIBUTES* optional -> "pointer"
// DesiredAccess : DWORD -> "u32"
// PageProtection : PAGE_PROTECTION_FLAGS -> "u32"
// AllocationAttributes : DWORD -> "u32"
// MaximumSize : ULONGLONG -> "u64"
// Name : LPCWSTR optional -> "buffer"
// ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> "pointer"
// ParameterCount : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* CreateFileMapping2(
void* File,
void* SecurityAttributes,
uint32_t DesiredAccess,
uint32_t PageProtection,
uint32_t AllocationAttributes,
uint64_t MaximumSize,
const uint16_t* Name,
void* ExtendedParameters,
uint32_t ParameterCount);
C, "api-ms-win-core-memory-l1-1-7.dll");
// $ffi->CreateFileMapping2(File, SecurityAttributes, DesiredAccess, PageProtection, AllocationAttributes, MaximumSize, Name, ExtendedParameters, ParameterCount);
// 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
// 構造体/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-memory-l1-1-7 extends StdCallLibrary {
Api-ms-win-core-memory-l1-1-7 INSTANCE = Native.load("api-ms-win-core-memory-l1-1-7", Api-ms-win-core-memory-l1-1-7.class);
Pointer CreateFileMapping2(
Pointer File, // HANDLE
Pointer SecurityAttributes, // SECURITY_ATTRIBUTES* optional
int DesiredAccess, // DWORD
int PageProtection, // PAGE_PROTECTION_FLAGS
int AllocationAttributes, // DWORD
long MaximumSize, // ULONGLONG
WString Name, // LPCWSTR optional
Pointer ExtendedParameters, // MEM_EXTENDED_PARAMETER* optional, in/out
int ParameterCount // DWORD
);
}@[Link("api-ms-win-core-memory-l1-1-7")]
lib Libapi-ms-win-core-memory-l1-1-7
fun CreateFileMapping2 = CreateFileMapping2(
File : Void*, # HANDLE
SecurityAttributes : SECURITY_ATTRIBUTES*, # SECURITY_ATTRIBUTES* optional
DesiredAccess : UInt32, # DWORD
PageProtection : UInt32, # PAGE_PROTECTION_FLAGS
AllocationAttributes : UInt32, # DWORD
MaximumSize : UInt64, # ULONGLONG
Name : UInt16*, # LPCWSTR optional
ExtendedParameters : MEM_EXTENDED_PARAMETER*, # MEM_EXTENDED_PARAMETER* optional, in/out
ParameterCount : UInt32 # DWORD
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CreateFileMapping2Native = Pointer<Void> Function(Pointer<Void>, Pointer<Void>, Uint32, Uint32, Uint32, Uint64, Pointer<Utf16>, Pointer<Void>, Uint32);
typedef CreateFileMapping2Dart = Pointer<Void> Function(Pointer<Void>, Pointer<Void>, int, int, int, int, Pointer<Utf16>, Pointer<Void>, int);
final CreateFileMapping2 = DynamicLibrary.open('api-ms-win-core-memory-l1-1-7.dll')
.lookupFunction<CreateFileMapping2Native, CreateFileMapping2Dart>('CreateFileMapping2');
// File : HANDLE -> Pointer<Void>
// SecurityAttributes : SECURITY_ATTRIBUTES* optional -> Pointer<Void>
// DesiredAccess : DWORD -> Uint32
// PageProtection : PAGE_PROTECTION_FLAGS -> Uint32
// AllocationAttributes : DWORD -> Uint32
// MaximumSize : ULONGLONG -> Uint64
// Name : LPCWSTR optional -> Pointer<Utf16>
// ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> Pointer<Void>
// ParameterCount : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CreateFileMapping2"
c_CreateFileMapping2 :: Ptr () -> Ptr () -> Word32 -> Word32 -> Word32 -> Word64 -> CWString -> Ptr () -> Word32 -> IO (Ptr ())
-- File : HANDLE -> Ptr ()
-- SecurityAttributes : SECURITY_ATTRIBUTES* optional -> Ptr ()
-- DesiredAccess : DWORD -> Word32
-- PageProtection : PAGE_PROTECTION_FLAGS -> Word32
-- AllocationAttributes : DWORD -> Word32
-- MaximumSize : ULONGLONG -> Word64
-- Name : LPCWSTR optional -> CWString
-- ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> Ptr ()
-- ParameterCount : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let createfilemapping2 =
foreign "CreateFileMapping2"
((ptr void) @-> (ptr void) @-> uint32_t @-> uint32_t @-> uint32_t @-> uint64_t @-> (ptr uint16_t) @-> (ptr void) @-> uint32_t @-> returning (ptr void))
(* File : HANDLE -> (ptr void) *)
(* SecurityAttributes : SECURITY_ATTRIBUTES* optional -> (ptr void) *)
(* DesiredAccess : DWORD -> uint32_t *)
(* PageProtection : PAGE_PROTECTION_FLAGS -> uint32_t *)
(* AllocationAttributes : DWORD -> uint32_t *)
(* MaximumSize : ULONGLONG -> uint64_t *)
(* Name : LPCWSTR optional -> (ptr uint16_t) *)
(* ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> (ptr void) *)
(* ParameterCount : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-memory-l1-1-7 (t "api-ms-win-core-memory-l1-1-7.dll"))
(cffi:use-foreign-library api-ms-win-core-memory-l1-1-7)
(cffi:defcfun ("CreateFileMapping2" create-file-mapping2 :convention :stdcall) :pointer
(file :pointer) ; HANDLE
(security-attributes :pointer) ; SECURITY_ATTRIBUTES* optional
(desired-access :uint32) ; DWORD
(page-protection :uint32) ; PAGE_PROTECTION_FLAGS
(allocation-attributes :uint32) ; DWORD
(maximum-size :uint64) ; ULONGLONG
(name (:string :encoding :utf-16le)) ; LPCWSTR optional
(extended-parameters :pointer) ; MEM_EXTENDED_PARAMETER* optional, in/out
(parameter-count :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CreateFileMapping2 = Win32::API::More->new('api-ms-win-core-memory-l1-1-7',
'HANDLE CreateFileMapping2(HANDLE File, LPVOID SecurityAttributes, DWORD DesiredAccess, DWORD PageProtection, DWORD AllocationAttributes, UINT64 MaximumSize, LPCWSTR Name, LPVOID ExtendedParameters, DWORD ParameterCount)');
# my $ret = $CreateFileMapping2->Call($File, $SecurityAttributes, $DesiredAccess, $PageProtection, $AllocationAttributes, $MaximumSize, $Name, $ExtendedParameters, $ParameterCount);
# File : HANDLE -> HANDLE
# SecurityAttributes : SECURITY_ATTRIBUTES* optional -> LPVOID
# DesiredAccess : DWORD -> DWORD
# PageProtection : PAGE_PROTECTION_FLAGS -> DWORD
# AllocationAttributes : DWORD -> DWORD
# MaximumSize : ULONGLONG -> UINT64
# Name : LPCWSTR optional -> LPCWSTR
# ExtendedParameters : MEM_EXTENDED_PARAMETER* optional, in/out -> LPVOID
# ParameterCount : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f CreateFileMappingW — ファイルマッピングオブジェクトを作成または開く(Unicode版)。
- f CloseHandle — オープンされたオブジェクトハンドルを閉じる。
- f CreateFileMappingNumaW — NUMAノードを指定してファイルマッピングオブジェクトを作成する(Unicode版)。
- f DuplicateHandle — オブジェクトハンドルの複製を作成する。
- f MapViewOfFile — ファイルマッピングのビューを呼び出し元プロセスのアドレス空間にマップする。
- f MapViewOfFileEx — ベースアドレスを指定してファイルマッピングのビューをマップする。
- f OpenFileMappingW — 名前付きファイルマッピングオブジェクトを開く(Unicode版)。
- f ReadFile — ファイルやデバイスからデータを読み込む。
- f UnmapViewOfFile — マップされたファイルビューをプロセスのアドレス空間から解除する。
- f VirtualAlloc — プロセスの仮想アドレス空間にメモリを確保する。
- f WriteFile — ファイルやデバイスにデータを書き込む。