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