ホーム › System.Com.Marshal › CoUnmarshalHresult
CoUnmarshalHresult
関数ストリームからHRESULT値をアンマーシャリングして取り出す。
シグネチャ
// OLE32.dll
#include <windows.h>
HRESULT CoUnmarshalHresult(
IStream* pstm,
HRESULT* phresult
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pstm | IStream* | in | HRESULT値が格納されたIStreamへのポインタ。読み出し元となる。 |
| phresult | HRESULT* | out | ストリームから復元したHRESULT値を受け取る出力ポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// OLE32.dll
#include <windows.h>
HRESULT CoUnmarshalHresult(
IStream* pstm,
HRESULT* phresult
);[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int CoUnmarshalHresult(
IntPtr pstm, // IStream*
out int phresult // HRESULT* out
);<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function CoUnmarshalHresult(
pstm As IntPtr, ' IStream*
<Out> ByRef phresult As Integer ' HRESULT* out
) As Integer
End Function' pstm : IStream*
' phresult : HRESULT* out
Declare PtrSafe Function CoUnmarshalHresult Lib "ole32" ( _
ByVal pstm As LongPtr, _
ByRef phresult As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CoUnmarshalHresult = ctypes.windll.ole32.CoUnmarshalHresult
CoUnmarshalHresult.restype = ctypes.c_int
CoUnmarshalHresult.argtypes = [
ctypes.c_void_p, # pstm : IStream*
ctypes.c_void_p, # phresult : HRESULT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLE32.dll')
CoUnmarshalHresult = Fiddle::Function.new(
lib['CoUnmarshalHresult'],
[
Fiddle::TYPE_VOIDP, # pstm : IStream*
Fiddle::TYPE_VOIDP, # phresult : HRESULT* out
],
Fiddle::TYPE_INT)#[link(name = "ole32")]
extern "system" {
fn CoUnmarshalHresult(
pstm: *mut core::ffi::c_void, // IStream*
phresult: *mut i32 // HRESULT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoUnmarshalHresult(IntPtr pstm, out int phresult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoUnmarshalHresult' -Namespace Win32 -PassThru
# $api::CoUnmarshalHresult(pstm, phresult)#uselib "OLE32.dll"
#func global CoUnmarshalHresult "CoUnmarshalHresult" sptr, sptr
; CoUnmarshalHresult pstm, varptr(phresult) ; 戻り値は stat
; pstm : IStream* -> "sptr"
; phresult : HRESULT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "OLE32.dll" #cfunc global CoUnmarshalHresult "CoUnmarshalHresult" sptr, var ; res = CoUnmarshalHresult(pstm, phresult) ; pstm : IStream* -> "sptr" ; phresult : HRESULT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "OLE32.dll" #cfunc global CoUnmarshalHresult "CoUnmarshalHresult" sptr, sptr ; res = CoUnmarshalHresult(pstm, varptr(phresult)) ; pstm : IStream* -> "sptr" ; phresult : HRESULT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT CoUnmarshalHresult(IStream* pstm, HRESULT* phresult) #uselib "OLE32.dll" #cfunc global CoUnmarshalHresult "CoUnmarshalHresult" intptr, var ; res = CoUnmarshalHresult(pstm, phresult) ; pstm : IStream* -> "intptr" ; phresult : HRESULT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT CoUnmarshalHresult(IStream* pstm, HRESULT* phresult) #uselib "OLE32.dll" #cfunc global CoUnmarshalHresult "CoUnmarshalHresult" intptr, intptr ; res = CoUnmarshalHresult(pstm, varptr(phresult)) ; pstm : IStream* -> "intptr" ; phresult : HRESULT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ole32 = windows.NewLazySystemDLL("OLE32.dll")
procCoUnmarshalHresult = ole32.NewProc("CoUnmarshalHresult")
)
// pstm (IStream*), phresult (HRESULT* out)
r1, _, err := procCoUnmarshalHresult.Call(
uintptr(pstm),
uintptr(phresult),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction CoUnmarshalHresult(
pstm: Pointer; // IStream*
phresult: Pointer // HRESULT* out
): Integer; stdcall;
external 'OLE32.dll' name 'CoUnmarshalHresult';result := DllCall("OLE32\CoUnmarshalHresult"
, "Ptr", pstm ; IStream*
, "Ptr", phresult ; HRESULT* out
, "Int") ; return: HRESULT●CoUnmarshalHresult(pstm, phresult) = DLL("OLE32.dll", "int CoUnmarshalHresult(void*, void*)")
# 呼び出し: CoUnmarshalHresult(pstm, phresult)
# pstm : IStream* -> "void*"
# phresult : HRESULT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ole32" fn CoUnmarshalHresult(
pstm: ?*anyopaque, // IStream*
phresult: [*c]i32 // HRESULT* out
) callconv(std.os.windows.WINAPI) i32;proc CoUnmarshalHresult(
pstm: pointer, # IStream*
phresult: ptr int32 # HRESULT* out
): int32 {.importc: "CoUnmarshalHresult", stdcall, dynlib: "OLE32.dll".}pragma(lib, "ole32");
extern(Windows)
int CoUnmarshalHresult(
void* pstm, // IStream*
int* phresult // HRESULT* out
);ccall((:CoUnmarshalHresult, "OLE32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Int32}),
pstm, phresult)
# pstm : IStream* -> Ptr{Cvoid}
# phresult : HRESULT* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CoUnmarshalHresult(
void* pstm,
int32_t* phresult);
]]
local ole32 = ffi.load("ole32")
-- ole32.CoUnmarshalHresult(pstm, phresult)
-- pstm : IStream*
-- phresult : HRESULT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLE32.dll');
const CoUnmarshalHresult = lib.func('__stdcall', 'CoUnmarshalHresult', 'int32_t', ['void *', 'int32_t *']);
// CoUnmarshalHresult(pstm, phresult)
// pstm : IStream* -> 'void *'
// phresult : HRESULT* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLE32.dll", {
CoUnmarshalHresult: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.CoUnmarshalHresult(pstm, phresult)
// pstm : IStream* -> "pointer"
// phresult : HRESULT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CoUnmarshalHresult(
void* pstm,
int32_t* phresult);
C, "OLE32.dll");
// $ffi->CoUnmarshalHresult(pstm, phresult);
// pstm : IStream*
// phresult : HRESULT* 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 Ole32 extends StdCallLibrary {
Ole32 INSTANCE = Native.load("ole32", Ole32.class);
int CoUnmarshalHresult(
Pointer pstm, // IStream*
IntByReference phresult // HRESULT* out
);
}@[Link("ole32")]
lib LibOLE32
fun CoUnmarshalHresult = CoUnmarshalHresult(
pstm : Void*, # IStream*
phresult : Int32* # HRESULT* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CoUnmarshalHresultNative = Int32 Function(Pointer<Void>, Pointer<Int32>);
typedef CoUnmarshalHresultDart = int Function(Pointer<Void>, Pointer<Int32>);
final CoUnmarshalHresult = DynamicLibrary.open('OLE32.dll')
.lookupFunction<CoUnmarshalHresultNative, CoUnmarshalHresultDart>('CoUnmarshalHresult');
// pstm : IStream* -> Pointer<Void>
// phresult : HRESULT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CoUnmarshalHresult(
pstm: Pointer; // IStream*
phresult: Pointer // HRESULT* out
): Integer; stdcall;
external 'OLE32.dll' name 'CoUnmarshalHresult';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CoUnmarshalHresult"
c_CoUnmarshalHresult :: Ptr () -> Ptr Int32 -> IO Int32
-- pstm : IStream* -> Ptr ()
-- phresult : HRESULT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let counmarshalhresult =
foreign "CoUnmarshalHresult"
((ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* pstm : IStream* -> (ptr void) *)
(* phresult : HRESULT* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)
(cffi:defcfun ("CoUnmarshalHresult" co-unmarshal-hresult :convention :stdcall) :int32
(pstm :pointer) ; IStream*
(phresult :pointer)) ; HRESULT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CoUnmarshalHresult = Win32::API::More->new('OLE32',
'int CoUnmarshalHresult(LPVOID pstm, LPVOID phresult)');
# my $ret = $CoUnmarshalHresult->Call($pstm, $phresult);
# pstm : IStream* -> LPVOID
# phresult : HRESULT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型