ホーム › System.Com.StructuredStorage › StgOpenStorage
StgOpenStorage
関数既存の複合ドキュメントファイルを開きルートストレージを取得する。
シグネチャ
// OLE32.dll
#include <windows.h>
HRESULT StgOpenStorage(
LPCWSTR pwcsName, // optional
IStorage* pstgPriority, // optional
STGM grfMode,
WORD** snbExclude, // optional
DWORD reserved,
IStorage** ppstgOpen
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pwcsName | LPCWSTR | inoptional | 開く複合ファイルのパス名(ワイド文字列)。pstgPriority使用時はNULL可。 |
| pstgPriority | IStorage* | inoptional | 優先モードで先に開いたIStorageへのポインタ。通常NULL。 |
| grfMode | STGM | in | アクセスモードを示すSTGMフラグ。共有モードも含む。 |
| snbExclude | WORD** | inoptional | 開く際に除外する要素名のSNB(文字列名ブロック)。通常NULL。 |
| reserved | DWORD | in | 予約パラメータ。0を指定する。 |
| ppstgOpen | IStorage** | out | 開いたルートストレージのIStorageを受け取る出力ポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// OLE32.dll
#include <windows.h>
HRESULT StgOpenStorage(
LPCWSTR pwcsName, // optional
IStorage* pstgPriority, // optional
STGM grfMode,
WORD** snbExclude, // optional
DWORD reserved,
IStorage** ppstgOpen
);[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int StgOpenStorage(
[MarshalAs(UnmanagedType.LPWStr)] string pwcsName, // LPCWSTR optional
IntPtr pstgPriority, // IStorage* optional
uint grfMode, // STGM
IntPtr snbExclude, // WORD** optional
uint reserved, // DWORD
IntPtr ppstgOpen // IStorage** out
);<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function StgOpenStorage(
<MarshalAs(UnmanagedType.LPWStr)> pwcsName As String, ' LPCWSTR optional
pstgPriority As IntPtr, ' IStorage* optional
grfMode As UInteger, ' STGM
snbExclude As IntPtr, ' WORD** optional
reserved As UInteger, ' DWORD
ppstgOpen As IntPtr ' IStorage** out
) As Integer
End Function' pwcsName : LPCWSTR optional
' pstgPriority : IStorage* optional
' grfMode : STGM
' snbExclude : WORD** optional
' reserved : DWORD
' ppstgOpen : IStorage** out
Declare PtrSafe Function StgOpenStorage Lib "ole32" ( _
ByVal pwcsName As LongPtr, _
ByVal pstgPriority As LongPtr, _
ByVal grfMode As Long, _
ByVal snbExclude As LongPtr, _
ByVal reserved As Long, _
ByVal ppstgOpen As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
StgOpenStorage = ctypes.windll.ole32.StgOpenStorage
StgOpenStorage.restype = ctypes.c_int
StgOpenStorage.argtypes = [
wintypes.LPCWSTR, # pwcsName : LPCWSTR optional
ctypes.c_void_p, # pstgPriority : IStorage* optional
wintypes.DWORD, # grfMode : STGM
ctypes.c_void_p, # snbExclude : WORD** optional
wintypes.DWORD, # reserved : DWORD
ctypes.c_void_p, # ppstgOpen : IStorage** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLE32.dll')
StgOpenStorage = Fiddle::Function.new(
lib['StgOpenStorage'],
[
Fiddle::TYPE_VOIDP, # pwcsName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pstgPriority : IStorage* optional
-Fiddle::TYPE_INT, # grfMode : STGM
Fiddle::TYPE_VOIDP, # snbExclude : WORD** optional
-Fiddle::TYPE_INT, # reserved : DWORD
Fiddle::TYPE_VOIDP, # ppstgOpen : IStorage** out
],
Fiddle::TYPE_INT)#[link(name = "ole32")]
extern "system" {
fn StgOpenStorage(
pwcsName: *const u16, // LPCWSTR optional
pstgPriority: *mut core::ffi::c_void, // IStorage* optional
grfMode: u32, // STGM
snbExclude: *mut *mut u16, // WORD** optional
reserved: u32, // DWORD
ppstgOpen: *mut *mut core::ffi::c_void // IStorage** out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLE32.dll")]
public static extern int StgOpenStorage([MarshalAs(UnmanagedType.LPWStr)] string pwcsName, IntPtr pstgPriority, uint grfMode, IntPtr snbExclude, uint reserved, IntPtr ppstgOpen);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_StgOpenStorage' -Namespace Win32 -PassThru
# $api::StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen)#uselib "OLE32.dll"
#func global StgOpenStorage "StgOpenStorage" sptr, sptr, sptr, sptr, sptr, sptr
; StgOpenStorage pwcsName, pstgPriority, grfMode, varptr(snbExclude), reserved, ppstgOpen ; 戻り値は stat
; pwcsName : LPCWSTR optional -> "sptr"
; pstgPriority : IStorage* optional -> "sptr"
; grfMode : STGM -> "sptr"
; snbExclude : WORD** optional -> "sptr"
; reserved : DWORD -> "sptr"
; ppstgOpen : IStorage** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "OLE32.dll" #cfunc global StgOpenStorage "StgOpenStorage" wstr, sptr, int, var, int, sptr ; res = StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen) ; pwcsName : LPCWSTR optional -> "wstr" ; pstgPriority : IStorage* optional -> "sptr" ; grfMode : STGM -> "int" ; snbExclude : WORD** optional -> "var" ; reserved : DWORD -> "int" ; ppstgOpen : IStorage** out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "OLE32.dll" #cfunc global StgOpenStorage "StgOpenStorage" wstr, sptr, int, sptr, int, sptr ; res = StgOpenStorage(pwcsName, pstgPriority, grfMode, varptr(snbExclude), reserved, ppstgOpen) ; pwcsName : LPCWSTR optional -> "wstr" ; pstgPriority : IStorage* optional -> "sptr" ; grfMode : STGM -> "int" ; snbExclude : WORD** optional -> "sptr" ; reserved : DWORD -> "int" ; ppstgOpen : IStorage** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT StgOpenStorage(LPCWSTR pwcsName, IStorage* pstgPriority, STGM grfMode, WORD** snbExclude, DWORD reserved, IStorage** ppstgOpen) #uselib "OLE32.dll" #cfunc global StgOpenStorage "StgOpenStorage" wstr, intptr, int, var, int, intptr ; res = StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen) ; pwcsName : LPCWSTR optional -> "wstr" ; pstgPriority : IStorage* optional -> "intptr" ; grfMode : STGM -> "int" ; snbExclude : WORD** optional -> "var" ; reserved : DWORD -> "int" ; ppstgOpen : IStorage** out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT StgOpenStorage(LPCWSTR pwcsName, IStorage* pstgPriority, STGM grfMode, WORD** snbExclude, DWORD reserved, IStorage** ppstgOpen) #uselib "OLE32.dll" #cfunc global StgOpenStorage "StgOpenStorage" wstr, intptr, int, intptr, int, intptr ; res = StgOpenStorage(pwcsName, pstgPriority, grfMode, varptr(snbExclude), reserved, ppstgOpen) ; pwcsName : LPCWSTR optional -> "wstr" ; pstgPriority : IStorage* optional -> "intptr" ; grfMode : STGM -> "int" ; snbExclude : WORD** optional -> "intptr" ; reserved : DWORD -> "int" ; ppstgOpen : IStorage** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ole32 = windows.NewLazySystemDLL("OLE32.dll")
procStgOpenStorage = ole32.NewProc("StgOpenStorage")
)
// pwcsName (LPCWSTR optional), pstgPriority (IStorage* optional), grfMode (STGM), snbExclude (WORD** optional), reserved (DWORD), ppstgOpen (IStorage** out)
r1, _, err := procStgOpenStorage.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwcsName))),
uintptr(pstgPriority),
uintptr(grfMode),
uintptr(snbExclude),
uintptr(reserved),
uintptr(ppstgOpen),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction StgOpenStorage(
pwcsName: PWideChar; // LPCWSTR optional
pstgPriority: Pointer; // IStorage* optional
grfMode: DWORD; // STGM
snbExclude: Pointer; // WORD** optional
reserved: DWORD; // DWORD
ppstgOpen: Pointer // IStorage** out
): Integer; stdcall;
external 'OLE32.dll' name 'StgOpenStorage';result := DllCall("OLE32\StgOpenStorage"
, "WStr", pwcsName ; LPCWSTR optional
, "Ptr", pstgPriority ; IStorage* optional
, "UInt", grfMode ; STGM
, "Ptr", snbExclude ; WORD** optional
, "UInt", reserved ; DWORD
, "Ptr", ppstgOpen ; IStorage** out
, "Int") ; return: HRESULT●StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen) = DLL("OLE32.dll", "int StgOpenStorage(char*, void*, dword, void*, dword, void*)")
# 呼び出し: StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen)
# pwcsName : LPCWSTR optional -> "char*"
# pstgPriority : IStorage* optional -> "void*"
# grfMode : STGM -> "dword"
# snbExclude : WORD** optional -> "void*"
# reserved : DWORD -> "dword"
# ppstgOpen : IStorage** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ole32" fn StgOpenStorage(
pwcsName: [*c]const u16, // LPCWSTR optional
pstgPriority: ?*anyopaque, // IStorage* optional
grfMode: u32, // STGM
snbExclude: [*c][*c]u16, // WORD** optional
reserved: u32, // DWORD
ppstgOpen: ?*anyopaque // IStorage** out
) callconv(std.os.windows.WINAPI) i32;proc StgOpenStorage(
pwcsName: WideCString, # LPCWSTR optional
pstgPriority: pointer, # IStorage* optional
grfMode: uint32, # STGM
snbExclude: ptr uint16, # WORD** optional
reserved: uint32, # DWORD
ppstgOpen: pointer # IStorage** out
): int32 {.importc: "StgOpenStorage", stdcall, dynlib: "OLE32.dll".}pragma(lib, "ole32");
extern(Windows)
int StgOpenStorage(
const(wchar)* pwcsName, // LPCWSTR optional
void* pstgPriority, // IStorage* optional
uint grfMode, // STGM
ushort** snbExclude, // WORD** optional
uint reserved, // DWORD
void* ppstgOpen // IStorage** out
);ccall((:StgOpenStorage, "OLE32.dll"), stdcall, Int32,
(Cwstring, Ptr{Cvoid}, UInt32, Ptr{UInt16}, UInt32, Ptr{Cvoid}),
pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen)
# pwcsName : LPCWSTR optional -> Cwstring
# pstgPriority : IStorage* optional -> Ptr{Cvoid}
# grfMode : STGM -> UInt32
# snbExclude : WORD** optional -> Ptr{UInt16}
# reserved : DWORD -> UInt32
# ppstgOpen : IStorage** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t StgOpenStorage(
const uint16_t* pwcsName,
void* pstgPriority,
uint32_t grfMode,
uint16_t** snbExclude,
uint32_t reserved,
void* ppstgOpen);
]]
local ole32 = ffi.load("ole32")
-- ole32.StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen)
-- pwcsName : LPCWSTR optional
-- pstgPriority : IStorage* optional
-- grfMode : STGM
-- snbExclude : WORD** optional
-- reserved : DWORD
-- ppstgOpen : IStorage** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLE32.dll');
const StgOpenStorage = lib.func('__stdcall', 'StgOpenStorage', 'int32_t', ['str16', 'void *', 'uint32_t', 'uint16_t *', 'uint32_t', 'void *']);
// StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen)
// pwcsName : LPCWSTR optional -> 'str16'
// pstgPriority : IStorage* optional -> 'void *'
// grfMode : STGM -> 'uint32_t'
// snbExclude : WORD** optional -> 'uint16_t *'
// reserved : DWORD -> 'uint32_t'
// ppstgOpen : IStorage** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLE32.dll", {
StgOpenStorage: { parameters: ["buffer", "pointer", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen)
// pwcsName : LPCWSTR optional -> "buffer"
// pstgPriority : IStorage* optional -> "pointer"
// grfMode : STGM -> "u32"
// snbExclude : WORD** optional -> "pointer"
// reserved : DWORD -> "u32"
// ppstgOpen : IStorage** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t StgOpenStorage(
const uint16_t* pwcsName,
void* pstgPriority,
uint32_t grfMode,
uint16_t** snbExclude,
uint32_t reserved,
void* ppstgOpen);
C, "OLE32.dll");
// $ffi->StgOpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstgOpen);
// pwcsName : LPCWSTR optional
// pstgPriority : IStorage* optional
// grfMode : STGM
// snbExclude : WORD** optional
// reserved : DWORD
// ppstgOpen : IStorage** 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 StgOpenStorage(
WString pwcsName, // LPCWSTR optional
Pointer pstgPriority, // IStorage* optional
int grfMode, // STGM
Pointer snbExclude, // WORD** optional
int reserved, // DWORD
Pointer ppstgOpen // IStorage** out
);
}@[Link("ole32")]
lib LibOLE32
fun StgOpenStorage = StgOpenStorage(
pwcsName : UInt16*, # LPCWSTR optional
pstgPriority : Void*, # IStorage* optional
grfMode : UInt32, # STGM
snbExclude : UInt16**, # WORD** optional
reserved : UInt32, # DWORD
ppstgOpen : Void* # IStorage** out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef StgOpenStorageNative = Int32 Function(Pointer<Utf16>, Pointer<Void>, Uint32, Pointer<Uint16>, Uint32, Pointer<Void>);
typedef StgOpenStorageDart = int Function(Pointer<Utf16>, Pointer<Void>, int, Pointer<Uint16>, int, Pointer<Void>);
final StgOpenStorage = DynamicLibrary.open('OLE32.dll')
.lookupFunction<StgOpenStorageNative, StgOpenStorageDart>('StgOpenStorage');
// pwcsName : LPCWSTR optional -> Pointer<Utf16>
// pstgPriority : IStorage* optional -> Pointer<Void>
// grfMode : STGM -> Uint32
// snbExclude : WORD** optional -> Pointer<Uint16>
// reserved : DWORD -> Uint32
// ppstgOpen : IStorage** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function StgOpenStorage(
pwcsName: PWideChar; // LPCWSTR optional
pstgPriority: Pointer; // IStorage* optional
grfMode: DWORD; // STGM
snbExclude: Pointer; // WORD** optional
reserved: DWORD; // DWORD
ppstgOpen: Pointer // IStorage** out
): Integer; stdcall;
external 'OLE32.dll' name 'StgOpenStorage';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "StgOpenStorage"
c_StgOpenStorage :: CWString -> Ptr () -> Word32 -> Ptr Word16 -> Word32 -> Ptr () -> IO Int32
-- pwcsName : LPCWSTR optional -> CWString
-- pstgPriority : IStorage* optional -> Ptr ()
-- grfMode : STGM -> Word32
-- snbExclude : WORD** optional -> Ptr Word16
-- reserved : DWORD -> Word32
-- ppstgOpen : IStorage** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let stgopenstorage =
foreign "StgOpenStorage"
((ptr uint16_t) @-> (ptr void) @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* pwcsName : LPCWSTR optional -> (ptr uint16_t) *)
(* pstgPriority : IStorage* optional -> (ptr void) *)
(* grfMode : STGM -> uint32_t *)
(* snbExclude : WORD** optional -> (ptr uint16_t) *)
(* reserved : DWORD -> uint32_t *)
(* ppstgOpen : IStorage** 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 ("StgOpenStorage" stg-open-storage :convention :stdcall) :int32
(pwcs-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(pstg-priority :pointer) ; IStorage* optional
(grf-mode :uint32) ; STGM
(snb-exclude :pointer) ; WORD** optional
(reserved :uint32) ; DWORD
(ppstg-open :pointer)) ; IStorage** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $StgOpenStorage = Win32::API::More->new('OLE32',
'int StgOpenStorage(LPCWSTR pwcsName, LPVOID pstgPriority, DWORD grfMode, LPVOID snbExclude, DWORD reserved, LPVOID ppstgOpen)');
# my $ret = $StgOpenStorage->Call($pwcsName, $pstgPriority, $grfMode, $snbExclude, $reserved, $ppstgOpen);
# pwcsName : LPCWSTR optional -> LPCWSTR
# pstgPriority : IStorage* optional -> LPVOID
# grfMode : STGM -> DWORD
# snbExclude : WORD** optional -> LPVOID
# reserved : DWORD -> DWORD
# ppstgOpen : IStorage** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f StgOpenStorageEx — 指定形式と属性で既存のストレージオブジェクトを開く。
使用する型