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

GetHGlobalFromStream

関数
ストリームの基になるグローバルメモリハンドルを取得する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT GetHGlobalFromStream(
    IStream* pstm,
    HGLOBAL* phglobal
);

パラメーター

名前方向
pstmIStream*in
phglobalHGLOBAL*out

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

GetHGlobalFromStream = ctypes.windll.ole32.GetHGlobalFromStream
GetHGlobalFromStream.restype = ctypes.c_int
GetHGlobalFromStream.argtypes = [
    ctypes.c_void_p,  # pstm : IStream*
    ctypes.c_void_p,  # phglobal : HGLOBAL* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procGetHGlobalFromStream = ole32.NewProc("GetHGlobalFromStream")
)

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