Win32 API 日本語リファレンス
ホームSystem.Com.Marshal › CoUnmarshalInterface

CoUnmarshalInterface

関数
ストリームからインターフェイスポインタをアンマーシャリングして復元する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT CoUnmarshalInterface(
    IStream* pStm,
    const GUID* riid,
    void** ppv
);

パラメーター

名前方向
pStmIStream*in
riidGUID*in
ppvvoid**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT CoUnmarshalInterface(
    IStream* pStm,
    const GUID* riid,
    void** ppv
);
[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int CoUnmarshalInterface(
    IntPtr pStm,   // IStream*
    ref Guid riid,   // GUID*
    IntPtr ppv   // void** out
);
<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function CoUnmarshalInterface(
    pStm As IntPtr,   ' IStream*
    ByRef riid As Guid,   ' GUID*
    ppv As IntPtr   ' void** out
) As Integer
End Function
' pStm : IStream*
' riid : GUID*
' ppv : void** out
Declare PtrSafe Function CoUnmarshalInterface Lib "ole32" ( _
    ByVal pStm As LongPtr, _
    ByVal riid As LongPtr, _
    ByVal ppv As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CoUnmarshalInterface = ctypes.windll.ole32.CoUnmarshalInterface
CoUnmarshalInterface.restype = ctypes.c_int
CoUnmarshalInterface.argtypes = [
    ctypes.c_void_p,  # pStm : IStream*
    ctypes.c_void_p,  # riid : GUID*
    ctypes.c_void_p,  # ppv : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
CoUnmarshalInterface = Fiddle::Function.new(
  lib['CoUnmarshalInterface'],
  [
    Fiddle::TYPE_VOIDP,  # pStm : IStream*
    Fiddle::TYPE_VOIDP,  # riid : GUID*
    Fiddle::TYPE_VOIDP,  # ppv : void** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn CoUnmarshalInterface(
        pStm: *mut core::ffi::c_void,  // IStream*
        riid: *const GUID,  // GUID*
        ppv: *mut *mut ()  // void** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoUnmarshalInterface(IntPtr pStm, ref Guid riid, IntPtr ppv);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoUnmarshalInterface' -Namespace Win32 -PassThru
# $api::CoUnmarshalInterface(pStm, riid, ppv)
#uselib "OLE32.dll"
#func global CoUnmarshalInterface "CoUnmarshalInterface" sptr, sptr, sptr
; CoUnmarshalInterface pStm, varptr(riid), ppv   ; 戻り値は stat
; pStm : IStream* -> "sptr"
; riid : GUID* -> "sptr"
; ppv : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "OLE32.dll"
#cfunc global CoUnmarshalInterface "CoUnmarshalInterface" sptr, var, sptr
; res = CoUnmarshalInterface(pStm, riid, ppv)
; pStm : IStream* -> "sptr"
; riid : GUID* -> "var"
; ppv : void** out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT CoUnmarshalInterface(IStream* pStm, GUID* riid, void** ppv)
#uselib "OLE32.dll"
#cfunc global CoUnmarshalInterface "CoUnmarshalInterface" intptr, var, intptr
; res = CoUnmarshalInterface(pStm, riid, ppv)
; pStm : IStream* -> "intptr"
; riid : GUID* -> "var"
; ppv : void** out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procCoUnmarshalInterface = ole32.NewProc("CoUnmarshalInterface")
)

// pStm (IStream*), riid (GUID*), ppv (void** out)
r1, _, err := procCoUnmarshalInterface.Call(
	uintptr(pStm),
	uintptr(riid),
	uintptr(ppv),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CoUnmarshalInterface(
  pStm: Pointer;   // IStream*
  riid: PGUID;   // GUID*
  ppv: Pointer   // void** out
): Integer; stdcall;
  external 'OLE32.dll' name 'CoUnmarshalInterface';
result := DllCall("OLE32\CoUnmarshalInterface"
    , "Ptr", pStm   ; IStream*
    , "Ptr", riid   ; GUID*
    , "Ptr", ppv   ; void** out
    , "Int")   ; return: HRESULT
●CoUnmarshalInterface(pStm, riid, ppv) = DLL("OLE32.dll", "int CoUnmarshalInterface(void*, void*, void*)")
# 呼び出し: CoUnmarshalInterface(pStm, riid, ppv)
# pStm : IStream* -> "void*"
# riid : GUID* -> "void*"
# ppv : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。