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

CoMarshalHresult

関数
HRESULT値をストリームへマーシャリングして書き込む。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT CoMarshalHresult(
    IStream* pstm,
    HRESULT hresult
);

パラメーター

名前方向
pstmIStream*in
hresultHRESULTin

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

CoMarshalHresult = ctypes.windll.ole32.CoMarshalHresult
CoMarshalHresult.restype = ctypes.c_int
CoMarshalHresult.argtypes = [
    ctypes.c_void_p,  # pstm : IStream*
    ctypes.c_int,  # hresult : HRESULT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
CoMarshalHresult = Fiddle::Function.new(
  lib['CoMarshalHresult'],
  [
    Fiddle::TYPE_VOIDP,  # pstm : IStream*
    Fiddle::TYPE_INT,  # hresult : HRESULT
  ],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn CoMarshalHresult(
        pstm: *mut core::ffi::c_void,  // IStream*
        hresult: i32  // HRESULT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoMarshalHresult(IntPtr pstm, int hresult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoMarshalHresult' -Namespace Win32 -PassThru
# $api::CoMarshalHresult(pstm, hresult)
#uselib "OLE32.dll"
#func global CoMarshalHresult "CoMarshalHresult" sptr, sptr
; CoMarshalHresult pstm, hresult   ; 戻り値は stat
; pstm : IStream* -> "sptr"
; hresult : HRESULT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "OLE32.dll"
#cfunc global CoMarshalHresult "CoMarshalHresult" sptr, int
; res = CoMarshalHresult(pstm, hresult)
; pstm : IStream* -> "sptr"
; hresult : HRESULT -> "int"
; HRESULT CoMarshalHresult(IStream* pstm, HRESULT hresult)
#uselib "OLE32.dll"
#cfunc global CoMarshalHresult "CoMarshalHresult" intptr, int
; res = CoMarshalHresult(pstm, hresult)
; pstm : IStream* -> "intptr"
; hresult : HRESULT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procCoMarshalHresult = ole32.NewProc("CoMarshalHresult")
)

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