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

ReadFmtUserTypeStg

関数
ストレージからクリップボード形式とユーザー型文字列を読み取る。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT ReadFmtUserTypeStg(
    IStorage* pstg,
    WORD* pcf,
    LPWSTR* lplpszUserType   // optional
);

パラメーター

名前方向説明
pstgIStorage*in読み出し対象のIStorageへのポインタ。
pcfWORD*out記録されたクリップボード形式(CLIPFORMAT)値を受け取る出力ポインタ。
lplpszUserTypeLPWSTR*outoptional記録されたユーザータイプ名(ワイド文字列)を受け取る出力ポインタ。呼出側で解放する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT ReadFmtUserTypeStg(
    IStorage* pstg,
    WORD* pcf,
    LPWSTR* lplpszUserType   // optional
);
[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int ReadFmtUserTypeStg(
    IntPtr pstg,   // IStorage*
    out ushort pcf,   // WORD* out
    IntPtr lplpszUserType   // LPWSTR* optional, out
);
<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function ReadFmtUserTypeStg(
    pstg As IntPtr,   ' IStorage*
    <Out> ByRef pcf As UShort,   ' WORD* out
    lplpszUserType As IntPtr   ' LPWSTR* optional, out
) As Integer
End Function
' pstg : IStorage*
' pcf : WORD* out
' lplpszUserType : LPWSTR* optional, out
Declare PtrSafe Function ReadFmtUserTypeStg Lib "ole32" ( _
    ByVal pstg As LongPtr, _
    ByRef pcf As Integer, _
    ByVal lplpszUserType As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ReadFmtUserTypeStg = ctypes.windll.ole32.ReadFmtUserTypeStg
ReadFmtUserTypeStg.restype = ctypes.c_int
ReadFmtUserTypeStg.argtypes = [
    ctypes.c_void_p,  # pstg : IStorage*
    ctypes.POINTER(ctypes.c_ushort),  # pcf : WORD* out
    ctypes.c_void_p,  # lplpszUserType : LPWSTR* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
ReadFmtUserTypeStg = Fiddle::Function.new(
  lib['ReadFmtUserTypeStg'],
  [
    Fiddle::TYPE_VOIDP,  # pstg : IStorage*
    Fiddle::TYPE_VOIDP,  # pcf : WORD* out
    Fiddle::TYPE_VOIDP,  # lplpszUserType : LPWSTR* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn ReadFmtUserTypeStg(
        pstg: *mut core::ffi::c_void,  // IStorage*
        pcf: *mut u16,  // WORD* out
        lplpszUserType: *mut *mut u16  // LPWSTR* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLE32.dll")]
public static extern int ReadFmtUserTypeStg(IntPtr pstg, out ushort pcf, IntPtr lplpszUserType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_ReadFmtUserTypeStg' -Namespace Win32 -PassThru
# $api::ReadFmtUserTypeStg(pstg, pcf, lplpszUserType)
#uselib "OLE32.dll"
#func global ReadFmtUserTypeStg "ReadFmtUserTypeStg" sptr, sptr, sptr
; ReadFmtUserTypeStg pstg, varptr(pcf), varptr(lplpszUserType)   ; 戻り値は stat
; pstg : IStorage* -> "sptr"
; pcf : WORD* out -> "sptr"
; lplpszUserType : LPWSTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "OLE32.dll"
#cfunc global ReadFmtUserTypeStg "ReadFmtUserTypeStg" sptr, var, var
; res = ReadFmtUserTypeStg(pstg, pcf, lplpszUserType)
; pstg : IStorage* -> "sptr"
; pcf : WORD* out -> "var"
; lplpszUserType : LPWSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT ReadFmtUserTypeStg(IStorage* pstg, WORD* pcf, LPWSTR* lplpszUserType)
#uselib "OLE32.dll"
#cfunc global ReadFmtUserTypeStg "ReadFmtUserTypeStg" intptr, var, var
; res = ReadFmtUserTypeStg(pstg, pcf, lplpszUserType)
; pstg : IStorage* -> "intptr"
; pcf : WORD* out -> "var"
; lplpszUserType : LPWSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procReadFmtUserTypeStg = ole32.NewProc("ReadFmtUserTypeStg")
)

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

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

typedef ReadFmtUserTypeStgNative = Int32 Function(Pointer<Void>, Pointer<Uint16>, Pointer<Pointer<Utf16>>);
typedef ReadFmtUserTypeStgDart = int Function(Pointer<Void>, Pointer<Uint16>, Pointer<Pointer<Utf16>>);
final ReadFmtUserTypeStg = DynamicLibrary.open('OLE32.dll')
    .lookupFunction<ReadFmtUserTypeStgNative, ReadFmtUserTypeStgDart>('ReadFmtUserTypeStg');
// pstg : IStorage* -> Pointer<Void>
// pcf : WORD* out -> Pointer<Uint16>
// lplpszUserType : LPWSTR* optional, out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ReadFmtUserTypeStg(
  pstg: Pointer;   // IStorage*
  pcf: Pointer;   // WORD* out
  lplpszUserType: PPWideChar   // LPWSTR* optional, out
): Integer; stdcall;
  external 'OLE32.dll' name 'ReadFmtUserTypeStg';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ReadFmtUserTypeStg"
  c_ReadFmtUserTypeStg :: Ptr () -> Ptr Word16 -> Ptr CWString -> IO Int32
-- pstg : IStorage* -> Ptr ()
-- pcf : WORD* out -> Ptr Word16
-- lplpszUserType : LPWSTR* optional, out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let readfmtusertypestg =
  foreign "ReadFmtUserTypeStg"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* pstg : IStorage* -> (ptr void) *)
(* pcf : WORD* out -> (ptr uint16_t) *)
(* lplpszUserType : LPWSTR* optional, out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)

(cffi:defcfun ("ReadFmtUserTypeStg" read-fmt-user-type-stg :convention :stdcall) :int32
  (pstg :pointer)   ; IStorage*
  (pcf :pointer)   ; WORD* out
  (lplpsz-user-type :pointer))   ; LPWSTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ReadFmtUserTypeStg = Win32::API::More->new('OLE32',
    'int ReadFmtUserTypeStg(LPVOID pstg, LPVOID pcf, LPVOID lplpszUserType)');
# my $ret = $ReadFmtUserTypeStg->Call($pstg, $pcf, $lplpszUserType);
# pstg : IStorage* -> LPVOID
# pcf : WORD* out -> LPVOID
# lplpszUserType : LPWSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型