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

CreateILockBytesOnHGlobal

関数
グローバルメモリ上にILockBytesオブジェクトを生成する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT CreateILockBytesOnHGlobal(
    HGLOBAL hGlobal,   // optional
    BOOL fDeleteOnRelease,
    ILockBytes** pplkbyt
);

パラメーター

名前方向説明
hGlobalHGLOBALinoptionalILockBytesの基となるグローバルメモリハンドル。NULLなら新規確保する。
fDeleteOnReleaseBOOLin解放時にHGLOBALを自動解放するか。TRUEで解放する。
pplkbytILockBytes**out生成したILockBytesを受け取る出力ポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

CreateILockBytesOnHGlobal = ctypes.windll.ole32.CreateILockBytesOnHGlobal
CreateILockBytesOnHGlobal.restype = ctypes.c_int
CreateILockBytesOnHGlobal.argtypes = [
    wintypes.HANDLE,  # hGlobal : HGLOBAL optional
    wintypes.BOOL,  # fDeleteOnRelease : BOOL
    ctypes.c_void_p,  # pplkbyt : ILockBytes** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procCreateILockBytesOnHGlobal = ole32.NewProc("CreateILockBytesOnHGlobal")
)

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

extern "ole32" fn CreateILockBytesOnHGlobal(
    hGlobal: ?*anyopaque, // HGLOBAL optional
    fDeleteOnRelease: i32, // BOOL
    pplkbyt: ?*anyopaque // ILockBytes** out
) callconv(std.os.windows.WINAPI) i32;
proc CreateILockBytesOnHGlobal(
    hGlobal: pointer,  # HGLOBAL optional
    fDeleteOnRelease: int32,  # BOOL
    pplkbyt: pointer  # ILockBytes** out
): int32 {.importc: "CreateILockBytesOnHGlobal", stdcall, dynlib: "OLE32.dll".}
pragma(lib, "ole32");
extern(Windows)
int CreateILockBytesOnHGlobal(
    void* hGlobal,   // HGLOBAL optional
    int fDeleteOnRelease,   // BOOL
    void* pplkbyt   // ILockBytes** out
);
ccall((:CreateILockBytesOnHGlobal, "OLE32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}),
      hGlobal, fDeleteOnRelease, pplkbyt)
# hGlobal : HGLOBAL optional -> Ptr{Cvoid}
# fDeleteOnRelease : BOOL -> Int32
# pplkbyt : ILockBytes** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CreateILockBytesOnHGlobal(
    void* hGlobal,
    int32_t fDeleteOnRelease,
    void* pplkbyt);
]]
local ole32 = ffi.load("ole32")
-- ole32.CreateILockBytesOnHGlobal(hGlobal, fDeleteOnRelease, pplkbyt)
-- hGlobal : HGLOBAL optional
-- fDeleteOnRelease : BOOL
-- pplkbyt : ILockBytes** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('OLE32.dll');
const CreateILockBytesOnHGlobal = lib.func('__stdcall', 'CreateILockBytesOnHGlobal', 'int32_t', ['void *', 'int32_t', 'void *']);
// CreateILockBytesOnHGlobal(hGlobal, fDeleteOnRelease, pplkbyt)
// hGlobal : HGLOBAL optional -> 'void *'
// fDeleteOnRelease : BOOL -> 'int32_t'
// pplkbyt : ILockBytes** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("OLE32.dll", {
  CreateILockBytesOnHGlobal: { parameters: ["pointer", "i32", "pointer"], result: "i32" },
});
// lib.symbols.CreateILockBytesOnHGlobal(hGlobal, fDeleteOnRelease, pplkbyt)
// hGlobal : HGLOBAL optional -> "pointer"
// fDeleteOnRelease : BOOL -> "i32"
// pplkbyt : ILockBytes** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CreateILockBytesOnHGlobal(
    void* hGlobal,
    int32_t fDeleteOnRelease,
    void* pplkbyt);
C, "OLE32.dll");
// $ffi->CreateILockBytesOnHGlobal(hGlobal, fDeleteOnRelease, pplkbyt);
// hGlobal : HGLOBAL optional
// fDeleteOnRelease : BOOL
// pplkbyt : ILockBytes** 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 CreateILockBytesOnHGlobal(
        Pointer hGlobal,   // HGLOBAL optional
        boolean fDeleteOnRelease,   // BOOL
        Pointer pplkbyt   // ILockBytes** out
    );
}
@[Link("ole32")]
lib LibOLE32
  fun CreateILockBytesOnHGlobal = CreateILockBytesOnHGlobal(
    hGlobal : Void*,   # HGLOBAL optional
    fDeleteOnRelease : Int32,   # BOOL
    pplkbyt : Void*   # ILockBytes** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CreateILockBytesOnHGlobalNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>);
typedef CreateILockBytesOnHGlobalDart = int Function(Pointer<Void>, int, Pointer<Void>);
final CreateILockBytesOnHGlobal = DynamicLibrary.open('OLE32.dll')
    .lookupFunction<CreateILockBytesOnHGlobalNative, CreateILockBytesOnHGlobalDart>('CreateILockBytesOnHGlobal');
// hGlobal : HGLOBAL optional -> Pointer<Void>
// fDeleteOnRelease : BOOL -> Int32
// pplkbyt : ILockBytes** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateILockBytesOnHGlobal(
  hGlobal: THandle;   // HGLOBAL optional
  fDeleteOnRelease: BOOL;   // BOOL
  pplkbyt: Pointer   // ILockBytes** out
): Integer; stdcall;
  external 'OLE32.dll' name 'CreateILockBytesOnHGlobal';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateILockBytesOnHGlobal"
  c_CreateILockBytesOnHGlobal :: Ptr () -> CInt -> Ptr () -> IO Int32
-- hGlobal : HGLOBAL optional -> Ptr ()
-- fDeleteOnRelease : BOOL -> CInt
-- pplkbyt : ILockBytes** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createilockbytesonhglobal =
  foreign "CreateILockBytesOnHGlobal"
    ((ptr void) @-> int32_t @-> (ptr void) @-> returning int32_t)
(* hGlobal : HGLOBAL optional -> (ptr void) *)
(* fDeleteOnRelease : BOOL -> int32_t *)
(* pplkbyt : ILockBytes** 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 ("CreateILockBytesOnHGlobal" create-ilock-bytes-on-hglobal :convention :stdcall) :int32
  (h-global :pointer)   ; HGLOBAL optional
  (f-delete-on-release :int32)   ; BOOL
  (pplkbyt :pointer))   ; ILockBytes** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateILockBytesOnHGlobal = Win32::API::More->new('OLE32',
    'int CreateILockBytesOnHGlobal(HANDLE hGlobal, BOOL fDeleteOnRelease, LPVOID pplkbyt)');
# my $ret = $CreateILockBytesOnHGlobal->Call($hGlobal, $fDeleteOnRelease, $pplkbyt);
# hGlobal : HGLOBAL optional -> HANDLE
# fDeleteOnRelease : BOOL -> BOOL
# pplkbyt : ILockBytes** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型