ホーム › Media.MediaFoundation › MFHeapAlloc
MFHeapAlloc
関数Media Foundationのヒープからメモリーを割り当てる。
シグネチャ
// MFPlat.dll
#include <windows.h>
void* MFHeapAlloc(
UINT_PTR nSize,
DWORD dwFlags,
LPSTR pszFile, // optional
INT line,
EAllocationType eat
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| nSize | UINT_PTR | in | 割り当てるバイト数。 |
| dwFlags | DWORD | in | 0 個以上のフラグ。有効なフラグの一覧については、Windows SDK ドキュメントの HeapAlloc を参照してください。 |
| pszFile | LPSTR | inoptional | 予約済み。NULL を設定します。 |
| line | INT | in | 予約済み。0 を設定します。 |
| eat | EAllocationType | in | 予約済み。eAllocationTypeIgnore を設定します。 |
戻り値の型: void*
公式ドキュメント
メモリブロックを割り当てます。(MFHeapAlloc)
戻り値
関数が成功した場合は、割り当てられたメモリブロックへのポインターを返します。関数が失敗した場合は、NULL を返します。
解説(Remarks)
現在のバージョンの Media Foundation では、この関数は HeapAlloc 関数を呼び出して呼び出し元プロセスのヒープを指定することと同等です。
割り当てたメモリを解放するには、MFHeapFree を呼び出します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// MFPlat.dll
#include <windows.h>
void* MFHeapAlloc(
UINT_PTR nSize,
DWORD dwFlags,
LPSTR pszFile, // optional
INT line,
EAllocationType eat
);[DllImport("MFPlat.dll", ExactSpelling = true)]
static extern IntPtr MFHeapAlloc(
UIntPtr nSize, // UINT_PTR
uint dwFlags, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string pszFile, // LPSTR optional
int line, // INT
int eat // EAllocationType
);<DllImport("MFPlat.dll", ExactSpelling:=True)>
Public Shared Function MFHeapAlloc(
nSize As UIntPtr, ' UINT_PTR
dwFlags As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> pszFile As String, ' LPSTR optional
line As Integer, ' INT
eat As Integer ' EAllocationType
) As IntPtr
End Function' nSize : UINT_PTR
' dwFlags : DWORD
' pszFile : LPSTR optional
' line : INT
' eat : EAllocationType
Declare PtrSafe Function MFHeapAlloc Lib "mfplat" ( _
ByVal nSize As LongPtr, _
ByVal dwFlags As Long, _
ByVal pszFile As String, _
ByVal line As Long, _
ByVal eat As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MFHeapAlloc = ctypes.windll.mfplat.MFHeapAlloc
MFHeapAlloc.restype = ctypes.c_void_p
MFHeapAlloc.argtypes = [
ctypes.c_size_t, # nSize : UINT_PTR
wintypes.DWORD, # dwFlags : DWORD
wintypes.LPCSTR, # pszFile : LPSTR optional
ctypes.c_int, # line : INT
ctypes.c_int, # eat : EAllocationType
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MFPlat.dll')
MFHeapAlloc = Fiddle::Function.new(
lib['MFHeapAlloc'],
[
Fiddle::TYPE_UINTPTR_T, # nSize : UINT_PTR
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # pszFile : LPSTR optional
Fiddle::TYPE_INT, # line : INT
Fiddle::TYPE_INT, # eat : EAllocationType
],
Fiddle::TYPE_VOIDP)#[link(name = "mfplat")]
extern "system" {
fn MFHeapAlloc(
nSize: usize, // UINT_PTR
dwFlags: u32, // DWORD
pszFile: *mut u8, // LPSTR optional
line: i32, // INT
eat: i32 // EAllocationType
) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MFPlat.dll")]
public static extern IntPtr MFHeapAlloc(UIntPtr nSize, uint dwFlags, [MarshalAs(UnmanagedType.LPStr)] string pszFile, int line, int eat);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MFPlat_MFHeapAlloc' -Namespace Win32 -PassThru
# $api::MFHeapAlloc(nSize, dwFlags, pszFile, line, eat)#uselib "MFPlat.dll"
#func global MFHeapAlloc "MFHeapAlloc" sptr, sptr, sptr, sptr, sptr
; MFHeapAlloc nSize, dwFlags, pszFile, line, eat ; 戻り値は stat
; nSize : UINT_PTR -> "sptr"
; dwFlags : DWORD -> "sptr"
; pszFile : LPSTR optional -> "sptr"
; line : INT -> "sptr"
; eat : EAllocationType -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "MFPlat.dll"
#cfunc global MFHeapAlloc "MFHeapAlloc" sptr, int, str, int, int
; res = MFHeapAlloc(nSize, dwFlags, pszFile, line, eat)
; nSize : UINT_PTR -> "sptr"
; dwFlags : DWORD -> "int"
; pszFile : LPSTR optional -> "str"
; line : INT -> "int"
; eat : EAllocationType -> "int"; void* MFHeapAlloc(UINT_PTR nSize, DWORD dwFlags, LPSTR pszFile, INT line, EAllocationType eat)
#uselib "MFPlat.dll"
#cfunc global MFHeapAlloc "MFHeapAlloc" intptr, int, str, int, int
; res = MFHeapAlloc(nSize, dwFlags, pszFile, line, eat)
; nSize : UINT_PTR -> "intptr"
; dwFlags : DWORD -> "int"
; pszFile : LPSTR optional -> "str"
; line : INT -> "int"
; eat : EAllocationType -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mfplat = windows.NewLazySystemDLL("MFPlat.dll")
procMFHeapAlloc = mfplat.NewProc("MFHeapAlloc")
)
// nSize (UINT_PTR), dwFlags (DWORD), pszFile (LPSTR optional), line (INT), eat (EAllocationType)
r1, _, err := procMFHeapAlloc.Call(
uintptr(nSize),
uintptr(dwFlags),
uintptr(unsafe.Pointer(windows.BytePtrFromString(pszFile))),
uintptr(line),
uintptr(eat),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function MFHeapAlloc(
nSize: NativeUInt; // UINT_PTR
dwFlags: DWORD; // DWORD
pszFile: PAnsiChar; // LPSTR optional
line: Integer; // INT
eat: Integer // EAllocationType
): Pointer; stdcall;
external 'MFPlat.dll' name 'MFHeapAlloc';result := DllCall("MFPlat\MFHeapAlloc"
, "UPtr", nSize ; UINT_PTR
, "UInt", dwFlags ; DWORD
, "AStr", pszFile ; LPSTR optional
, "Int", line ; INT
, "Int", eat ; EAllocationType
, "Ptr") ; return: void*●MFHeapAlloc(nSize, dwFlags, pszFile, line, eat) = DLL("MFPlat.dll", "void* MFHeapAlloc(int, dword, char*, int, int)")
# 呼び出し: MFHeapAlloc(nSize, dwFlags, pszFile, line, eat)
# nSize : UINT_PTR -> "int"
# dwFlags : DWORD -> "dword"
# pszFile : LPSTR optional -> "char*"
# line : INT -> "int"
# eat : EAllocationType -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mfplat" fn MFHeapAlloc(
nSize: usize, // UINT_PTR
dwFlags: u32, // DWORD
pszFile: [*c]const u8, // LPSTR optional
line: i32, // INT
eat: i32 // EAllocationType
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc MFHeapAlloc(
nSize: uint, # UINT_PTR
dwFlags: uint32, # DWORD
pszFile: cstring, # LPSTR optional
line: int32, # INT
eat: int32 # EAllocationType
): pointer {.importc: "MFHeapAlloc", stdcall, dynlib: "MFPlat.dll".}pragma(lib, "mfplat");
extern(Windows)
void* MFHeapAlloc(
size_t nSize, // UINT_PTR
uint dwFlags, // DWORD
const(char)* pszFile, // LPSTR optional
int line, // INT
int eat // EAllocationType
);ccall((:MFHeapAlloc, "MFPlat.dll"), stdcall, Ptr{Cvoid},
(Csize_t, UInt32, Cstring, Int32, Int32),
nSize, dwFlags, pszFile, line, eat)
# nSize : UINT_PTR -> Csize_t
# dwFlags : DWORD -> UInt32
# pszFile : LPSTR optional -> Cstring
# line : INT -> Int32
# eat : EAllocationType -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* MFHeapAlloc(
uintptr_t nSize,
uint32_t dwFlags,
const char* pszFile,
int32_t line,
int32_t eat);
]]
local mfplat = ffi.load("mfplat")
-- mfplat.MFHeapAlloc(nSize, dwFlags, pszFile, line, eat)
-- nSize : UINT_PTR
-- dwFlags : DWORD
-- pszFile : LPSTR optional
-- line : INT
-- eat : EAllocationType
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('MFPlat.dll');
const MFHeapAlloc = lib.func('__stdcall', 'MFHeapAlloc', 'void *', ['uintptr_t', 'uint32_t', 'str', 'int32_t', 'int32_t']);
// MFHeapAlloc(nSize, dwFlags, pszFile, line, eat)
// nSize : UINT_PTR -> 'uintptr_t'
// dwFlags : DWORD -> 'uint32_t'
// pszFile : LPSTR optional -> 'str'
// line : INT -> 'int32_t'
// eat : EAllocationType -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MFPlat.dll", {
MFHeapAlloc: { parameters: ["usize", "u32", "buffer", "i32", "i32"], result: "pointer" },
});
// lib.symbols.MFHeapAlloc(nSize, dwFlags, pszFile, line, eat)
// nSize : UINT_PTR -> "usize"
// dwFlags : DWORD -> "u32"
// pszFile : LPSTR optional -> "buffer"
// line : INT -> "i32"
// eat : EAllocationType -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* MFHeapAlloc(
size_t nSize,
uint32_t dwFlags,
const char* pszFile,
int32_t line,
int32_t eat);
C, "MFPlat.dll");
// $ffi->MFHeapAlloc(nSize, dwFlags, pszFile, line, eat);
// nSize : UINT_PTR
// dwFlags : DWORD
// pszFile : LPSTR optional
// line : INT
// eat : EAllocationType
// 構造体/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 Mfplat extends StdCallLibrary {
Mfplat INSTANCE = Native.load("mfplat", Mfplat.class);
Pointer MFHeapAlloc(
long nSize, // UINT_PTR
int dwFlags, // DWORD
String pszFile, // LPSTR optional
int line, // INT
int eat // EAllocationType
);
}@[Link("mfplat")]
lib LibMFPlat
fun MFHeapAlloc = MFHeapAlloc(
nSize : LibC::SizeT, # UINT_PTR
dwFlags : UInt32, # DWORD
pszFile : UInt8*, # LPSTR optional
line : Int32, # INT
eat : Int32 # EAllocationType
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MFHeapAllocNative = Pointer<Void> Function(UintPtr, Uint32, Pointer<Utf8>, Int32, Int32);
typedef MFHeapAllocDart = Pointer<Void> Function(int, int, Pointer<Utf8>, int, int);
final MFHeapAlloc = DynamicLibrary.open('MFPlat.dll')
.lookupFunction<MFHeapAllocNative, MFHeapAllocDart>('MFHeapAlloc');
// nSize : UINT_PTR -> UintPtr
// dwFlags : DWORD -> Uint32
// pszFile : LPSTR optional -> Pointer<Utf8>
// line : INT -> Int32
// eat : EAllocationType -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MFHeapAlloc(
nSize: NativeUInt; // UINT_PTR
dwFlags: DWORD; // DWORD
pszFile: PAnsiChar; // LPSTR optional
line: Integer; // INT
eat: Integer // EAllocationType
): Pointer; stdcall;
external 'MFPlat.dll' name 'MFHeapAlloc';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MFHeapAlloc"
c_MFHeapAlloc :: CUIntPtr -> Word32 -> CString -> Int32 -> Int32 -> IO (Ptr ())
-- nSize : UINT_PTR -> CUIntPtr
-- dwFlags : DWORD -> Word32
-- pszFile : LPSTR optional -> CString
-- line : INT -> Int32
-- eat : EAllocationType -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let mfheapalloc =
foreign "MFHeapAlloc"
(size_t @-> uint32_t @-> string @-> int32_t @-> int32_t @-> returning (ptr void))
(* nSize : UINT_PTR -> size_t *)
(* dwFlags : DWORD -> uint32_t *)
(* pszFile : LPSTR optional -> string *)
(* line : INT -> int32_t *)
(* eat : EAllocationType -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mfplat (t "MFPlat.dll"))
(cffi:use-foreign-library mfplat)
(cffi:defcfun ("MFHeapAlloc" mfheap-alloc :convention :stdcall) :pointer
(n-size :uint64) ; UINT_PTR
(dw-flags :uint32) ; DWORD
(psz-file :string) ; LPSTR optional
(line :int32) ; INT
(eat :int32)) ; EAllocationType
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MFHeapAlloc = Win32::API::More->new('MFPlat',
'LPVOID MFHeapAlloc(WPARAM nSize, DWORD dwFlags, LPCSTR pszFile, int line, int eat)');
# my $ret = $MFHeapAlloc->Call($nSize, $dwFlags, $pszFile, $line, $eat);
# nSize : UINT_PTR -> WPARAM
# dwFlags : DWORD -> DWORD
# pszFile : LPSTR optional -> LPCSTR
# line : INT -> int
# eat : EAllocationType -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型