Win32 API 日本語リファレンス
ホームMedia.MediaFoundation › MFHeapAlloc

MFHeapAlloc

関数
Media Foundationのヒープからメモリーを割り当てる。
DLLMFPlat.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

void* MFHeapAlloc(
    UINT_PTR nSize,
    DWORD dwFlags,
    LPSTR pszFile,   // optional
    INT line,
    EAllocationType eat
);

パラメーター

名前方向説明
nSizeUINT_PTRin確保するメモリのバイトサイズ。
dwFlagsDWORDin確保動作を制御するフラグ。
pszFileLPSTRinoptionalデバッグ用にソースファイル名を指定する文字列。通常はマクロが自動設定する。NULL可。
lineINTinデバッグ用のソース行番号。通常はマクロが自動設定する。
eatEAllocationTypeinメモリ割り当ての種別を示すEAllocationType列挙値。

戻り値の型: void*

各言語での呼び出し定義

// 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)。