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

MFCreateMediaTypeFromRepresentation

関数
形式表現データからメディア型を生成する。
DLLMFPlat.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT MFCreateMediaTypeFromRepresentation(
    GUID guidRepresentation,
    void* pvRepresentation,
    IMFMediaType** ppIMediaType
);

パラメーター

名前方向説明
guidRepresentationGUIDin

変換する形式表現を指定する GUID です。次の値が定義されています。

GUID 説明
AM_MEDIA_TYPE_REPRESENTATION DirectShow の AM_MEDIA_TYPE 構造体を変換します。
pvRepresentationvoid*in変換する形式表現を格納したバッファへのポインターです。バッファのレイアウトは guidRepresentation の値によって異なります。
ppIMediaTypeIMFMediaType**outIMFMediaType インターフェイスへのポインターを受け取ります。呼び出し元はこのインターフェイスを解放する必要があります。

戻り値の型: HRESULT

公式ドキュメント

別の形式表現から Media Foundation のメディアタイプを作成します。

戻り値

この関数は HRESULT を返します。指定できる値には次の表のものが含まれますが、これらに限定されません。

戻り値 説明
S_OK
関数が成功しました。
MF_E_UNSUPPORTED_REPRESENTATION
guidRepresentation に指定された GUID はサポートされていません。

解説(Remarks)

元の形式が DirectShow のオーディオメディアタイプであり、その形式タイプが認識されない場合、この関数は変換後のメディアタイプに次の属性を設定します。

属性 説明
MF_MT_AM_FORMAT_TYPE 形式タイプの GUID を格納します。
MF_MT_USER_DATA 形式ブロックを格納します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

HRESULT MFCreateMediaTypeFromRepresentation(
    GUID guidRepresentation,
    void* pvRepresentation,
    IMFMediaType** ppIMediaType
);
[DllImport("MFPlat.dll", ExactSpelling = true)]
static extern int MFCreateMediaTypeFromRepresentation(
    Guid guidRepresentation,   // GUID
    IntPtr pvRepresentation,   // void*
    IntPtr ppIMediaType   // IMFMediaType** out
);
<DllImport("MFPlat.dll", ExactSpelling:=True)>
Public Shared Function MFCreateMediaTypeFromRepresentation(
    guidRepresentation As Guid,   ' GUID
    pvRepresentation As IntPtr,   ' void*
    ppIMediaType As IntPtr   ' IMFMediaType** out
) As Integer
End Function
' guidRepresentation : GUID
' pvRepresentation : void*
' ppIMediaType : IMFMediaType** out
Declare PtrSafe Function MFCreateMediaTypeFromRepresentation Lib "mfplat" ( _
    ByVal guidRepresentation As LongPtr, _
    ByVal pvRepresentation As LongPtr, _
    ByVal ppIMediaType As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MFCreateMediaTypeFromRepresentation = ctypes.windll.mfplat.MFCreateMediaTypeFromRepresentation
MFCreateMediaTypeFromRepresentation.restype = ctypes.c_int
MFCreateMediaTypeFromRepresentation.argtypes = [
    ctypes.c_void_p,  # guidRepresentation : GUID
    ctypes.POINTER(None),  # pvRepresentation : void*
    ctypes.c_void_p,  # ppIMediaType : IMFMediaType** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MFPlat.dll')
MFCreateMediaTypeFromRepresentation = Fiddle::Function.new(
  lib['MFCreateMediaTypeFromRepresentation'],
  [
    Fiddle::TYPE_VOIDP,  # guidRepresentation : GUID
    Fiddle::TYPE_VOIDP,  # pvRepresentation : void*
    Fiddle::TYPE_VOIDP,  # ppIMediaType : IMFMediaType** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "mfplat")]
extern "system" {
    fn MFCreateMediaTypeFromRepresentation(
        guidRepresentation: GUID,  // GUID
        pvRepresentation: *mut (),  // void*
        ppIMediaType: *mut *mut core::ffi::c_void  // IMFMediaType** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MFPlat.dll")]
public static extern int MFCreateMediaTypeFromRepresentation(Guid guidRepresentation, IntPtr pvRepresentation, IntPtr ppIMediaType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MFPlat_MFCreateMediaTypeFromRepresentation' -Namespace Win32 -PassThru
# $api::MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType)
#uselib "MFPlat.dll"
#func global MFCreateMediaTypeFromRepresentation "MFCreateMediaTypeFromRepresentation" sptr, sptr, sptr
; MFCreateMediaTypeFromRepresentation guidRepresentation, pvRepresentation, ppIMediaType   ; 戻り値は stat
; guidRepresentation : GUID -> "sptr"
; pvRepresentation : void* -> "sptr"
; ppIMediaType : IMFMediaType** out -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "MFPlat.dll"
#cfunc global MFCreateMediaTypeFromRepresentation "MFCreateMediaTypeFromRepresentation" int, sptr, sptr
; res = MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType)
; guidRepresentation : GUID -> "int"
; pvRepresentation : void* -> "sptr"
; ppIMediaType : IMFMediaType** out -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; HRESULT MFCreateMediaTypeFromRepresentation(GUID guidRepresentation, void* pvRepresentation, IMFMediaType** ppIMediaType)
#uselib "MFPlat.dll"
#cfunc global MFCreateMediaTypeFromRepresentation "MFCreateMediaTypeFromRepresentation" int, intptr, intptr
; res = MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType)
; guidRepresentation : GUID -> "int"
; pvRepresentation : void* -> "intptr"
; ppIMediaType : IMFMediaType** out -> "intptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mfplat = windows.NewLazySystemDLL("MFPlat.dll")
	procMFCreateMediaTypeFromRepresentation = mfplat.NewProc("MFCreateMediaTypeFromRepresentation")
)

// guidRepresentation (GUID), pvRepresentation (void*), ppIMediaType (IMFMediaType** out)
r1, _, err := procMFCreateMediaTypeFromRepresentation.Call(
	uintptr(guidRepresentation),
	uintptr(pvRepresentation),
	uintptr(ppIMediaType),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function MFCreateMediaTypeFromRepresentation(
  guidRepresentation: TGUID;   // GUID
  pvRepresentation: Pointer;   // void*
  ppIMediaType: Pointer   // IMFMediaType** out
): Integer; stdcall;
  external 'MFPlat.dll' name 'MFCreateMediaTypeFromRepresentation';
result := DllCall("MFPlat\MFCreateMediaTypeFromRepresentation"
    , "Ptr", guidRepresentation   ; GUID
    , "Ptr", pvRepresentation   ; void*
    , "Ptr", ppIMediaType   ; IMFMediaType** out
    , "Int")   ; return: HRESULT
●MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType) = DLL("MFPlat.dll", "int MFCreateMediaTypeFromRepresentation(void*, void*, void*)")
# 呼び出し: MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType)
# guidRepresentation : GUID -> "void*"
# pvRepresentation : void* -> "void*"
# ppIMediaType : IMFMediaType** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mfplat" fn MFCreateMediaTypeFromRepresentation(
    guidRepresentation: GUID, // GUID
    pvRepresentation: ?*anyopaque, // void*
    ppIMediaType: ?*anyopaque // IMFMediaType** out
) callconv(std.os.windows.WINAPI) i32;
proc MFCreateMediaTypeFromRepresentation(
    guidRepresentation: GUID,  # GUID
    pvRepresentation: pointer,  # void*
    ppIMediaType: pointer  # IMFMediaType** out
): int32 {.importc: "MFCreateMediaTypeFromRepresentation", stdcall, dynlib: "MFPlat.dll".}
pragma(lib, "mfplat");
extern(Windows)
int MFCreateMediaTypeFromRepresentation(
    GUID guidRepresentation,   // GUID
    void* pvRepresentation,   // void*
    void* ppIMediaType   // IMFMediaType** out
);
ccall((:MFCreateMediaTypeFromRepresentation, "MFPlat.dll"), stdcall, Int32,
      (GUID, Ptr{Cvoid}, Ptr{Cvoid}),
      guidRepresentation, pvRepresentation, ppIMediaType)
# guidRepresentation : GUID -> GUID
# pvRepresentation : void* -> Ptr{Cvoid}
# ppIMediaType : IMFMediaType** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t MFCreateMediaTypeFromRepresentation(
    GUID guidRepresentation,
    void* pvRepresentation,
    void* ppIMediaType);
]]
local mfplat = ffi.load("mfplat")
-- mfplat.MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType)
-- guidRepresentation : GUID
-- pvRepresentation : void*
-- ppIMediaType : IMFMediaType** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('MFPlat.dll');
const MFCreateMediaTypeFromRepresentation = lib.func('__stdcall', 'MFCreateMediaTypeFromRepresentation', 'int32_t', ['void *', 'void *', 'void *']);
// MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType)
// guidRepresentation : GUID -> 'void *'
// pvRepresentation : void* -> 'void *'
// ppIMediaType : IMFMediaType** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MFPlat.dll", {
  MFCreateMediaTypeFromRepresentation: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType)
// guidRepresentation : GUID -> "pointer"
// pvRepresentation : void* -> "pointer"
// ppIMediaType : IMFMediaType** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t MFCreateMediaTypeFromRepresentation(
    GUID guidRepresentation,
    void* pvRepresentation,
    void* ppIMediaType);
C, "MFPlat.dll");
// $ffi->MFCreateMediaTypeFromRepresentation(guidRepresentation, pvRepresentation, ppIMediaType);
// guidRepresentation : GUID
// pvRepresentation : void*
// ppIMediaType : IMFMediaType** out
// 構造体/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);
    int MFCreateMediaTypeFromRepresentation(
        Pointer guidRepresentation,   // GUID
        Pointer pvRepresentation,   // void*
        Pointer ppIMediaType   // IMFMediaType** out
    );
}
@[Link("mfplat")]
lib LibMFPlat
  fun MFCreateMediaTypeFromRepresentation = MFCreateMediaTypeFromRepresentation(
    guidRepresentation : GUID,   # GUID
    pvRepresentation : Void*,   # void*
    ppIMediaType : Void*   # IMFMediaType** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MFCreateMediaTypeFromRepresentationNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef MFCreateMediaTypeFromRepresentationDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final MFCreateMediaTypeFromRepresentation = DynamicLibrary.open('MFPlat.dll')
    .lookupFunction<MFCreateMediaTypeFromRepresentationNative, MFCreateMediaTypeFromRepresentationDart>('MFCreateMediaTypeFromRepresentation');
// guidRepresentation : GUID -> Pointer<Void>
// pvRepresentation : void* -> Pointer<Void>
// ppIMediaType : IMFMediaType** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MFCreateMediaTypeFromRepresentation(
  guidRepresentation: TGUID;   // GUID
  pvRepresentation: Pointer;   // void*
  ppIMediaType: Pointer   // IMFMediaType** out
): Integer; stdcall;
  external 'MFPlat.dll' name 'MFCreateMediaTypeFromRepresentation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MFCreateMediaTypeFromRepresentation"
  c_MFCreateMediaTypeFromRepresentation :: Ptr () -> Ptr () -> Ptr () -> IO Int32
-- guidRepresentation : GUID -> Ptr ()
-- pvRepresentation : void* -> Ptr ()
-- ppIMediaType : IMFMediaType** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。
open Ctypes
open Foreign

let mfcreatemediatypefromrepresentation =
  foreign "MFCreateMediaTypeFromRepresentation"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* guidRepresentation : GUID -> (ptr void) *)
(* pvRepresentation : void* -> (ptr void) *)
(* ppIMediaType : IMFMediaType** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mfplat (t "MFPlat.dll"))
(cffi:use-foreign-library mfplat)

(cffi:defcfun ("MFCreateMediaTypeFromRepresentation" mfcreate-media-type-from-representation :convention :stdcall) :int32
  (guid-representation :pointer)   ; GUID
  (pv-representation :pointer)   ; void*
  (pp-imedia-type :pointer))   ; IMFMediaType** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MFCreateMediaTypeFromRepresentation = Win32::API::More->new('MFPlat',
    'int MFCreateMediaTypeFromRepresentation(LPVOID guidRepresentation, LPVOID pvRepresentation, LPVOID ppIMediaType)');
# my $ret = $MFCreateMediaTypeFromRepresentation->Call($guidRepresentation, $pvRepresentation, $ppIMediaType);
# guidRepresentation : GUID -> LPVOID
# pvRepresentation : void* -> LPVOID
# ppIMediaType : IMFMediaType** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型