Win32 API 日本語リファレンス
ホームUI.Shell › SHCreateStreamOnFileEx

SHCreateStreamOnFileEx

関数
属性やテンプレート指定でファイルのストリームを生成する。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT SHCreateStreamOnFileEx(
    LPCWSTR pszFile,
    DWORD grfMode,
    DWORD dwAttributes,
    BOOL fCreate,
    IStream* pstmTemplate,   // optional
    IStream** ppstm
);

パラメーター

名前方向
pszFileLPCWSTRin
grfModeDWORDin
dwAttributesDWORDin
fCreateBOOLin
pstmTemplateIStream*inoptional
ppstmIStream**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SHCreateStreamOnFileEx(
    LPCWSTR pszFile,
    DWORD grfMode,
    DWORD dwAttributes,
    BOOL fCreate,
    IStream* pstmTemplate,   // optional
    IStream** ppstm
);
[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern int SHCreateStreamOnFileEx(
    [MarshalAs(UnmanagedType.LPWStr)] string pszFile,   // LPCWSTR
    uint grfMode,   // DWORD
    uint dwAttributes,   // DWORD
    bool fCreate,   // BOOL
    IntPtr pstmTemplate,   // IStream* optional
    IntPtr ppstm   // IStream** out
);
<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function SHCreateStreamOnFileEx(
    <MarshalAs(UnmanagedType.LPWStr)> pszFile As String,   ' LPCWSTR
    grfMode As UInteger,   ' DWORD
    dwAttributes As UInteger,   ' DWORD
    fCreate As Boolean,   ' BOOL
    pstmTemplate As IntPtr,   ' IStream* optional
    ppstm As IntPtr   ' IStream** out
) As Integer
End Function
' pszFile : LPCWSTR
' grfMode : DWORD
' dwAttributes : DWORD
' fCreate : BOOL
' pstmTemplate : IStream* optional
' ppstm : IStream** out
Declare PtrSafe Function SHCreateStreamOnFileEx Lib "shlwapi" ( _
    ByVal pszFile As LongPtr, _
    ByVal grfMode As Long, _
    ByVal dwAttributes As Long, _
    ByVal fCreate As Long, _
    ByVal pstmTemplate As LongPtr, _
    ByVal ppstm As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHCreateStreamOnFileEx = ctypes.windll.shlwapi.SHCreateStreamOnFileEx
SHCreateStreamOnFileEx.restype = ctypes.c_int
SHCreateStreamOnFileEx.argtypes = [
    wintypes.LPCWSTR,  # pszFile : LPCWSTR
    wintypes.DWORD,  # grfMode : DWORD
    wintypes.DWORD,  # dwAttributes : DWORD
    wintypes.BOOL,  # fCreate : BOOL
    ctypes.c_void_p,  # pstmTemplate : IStream* optional
    ctypes.c_void_p,  # ppstm : IStream** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
SHCreateStreamOnFileEx = Fiddle::Function.new(
  lib['SHCreateStreamOnFileEx'],
  [
    Fiddle::TYPE_VOIDP,  # pszFile : LPCWSTR
    -Fiddle::TYPE_INT,  # grfMode : DWORD
    -Fiddle::TYPE_INT,  # dwAttributes : DWORD
    Fiddle::TYPE_INT,  # fCreate : BOOL
    Fiddle::TYPE_VOIDP,  # pstmTemplate : IStream* optional
    Fiddle::TYPE_VOIDP,  # ppstm : IStream** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn SHCreateStreamOnFileEx(
        pszFile: *const u16,  // LPCWSTR
        grfMode: u32,  // DWORD
        dwAttributes: u32,  // DWORD
        fCreate: i32,  // BOOL
        pstmTemplate: *mut core::ffi::c_void,  // IStream* optional
        ppstm: *mut *mut core::ffi::c_void  // IStream** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll")]
public static extern int SHCreateStreamOnFileEx([MarshalAs(UnmanagedType.LPWStr)] string pszFile, uint grfMode, uint dwAttributes, bool fCreate, IntPtr pstmTemplate, IntPtr ppstm);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHCreateStreamOnFileEx' -Namespace Win32 -PassThru
# $api::SHCreateStreamOnFileEx(pszFile, grfMode, dwAttributes, fCreate, pstmTemplate, ppstm)
#uselib "SHLWAPI.dll"
#func global SHCreateStreamOnFileEx "SHCreateStreamOnFileEx" sptr, sptr, sptr, sptr, sptr, sptr
; SHCreateStreamOnFileEx pszFile, grfMode, dwAttributes, fCreate, pstmTemplate, ppstm   ; 戻り値は stat
; pszFile : LPCWSTR -> "sptr"
; grfMode : DWORD -> "sptr"
; dwAttributes : DWORD -> "sptr"
; fCreate : BOOL -> "sptr"
; pstmTemplate : IStream* optional -> "sptr"
; ppstm : IStream** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global SHCreateStreamOnFileEx "SHCreateStreamOnFileEx" wstr, int, int, int, sptr, sptr
; res = SHCreateStreamOnFileEx(pszFile, grfMode, dwAttributes, fCreate, pstmTemplate, ppstm)
; pszFile : LPCWSTR -> "wstr"
; grfMode : DWORD -> "int"
; dwAttributes : DWORD -> "int"
; fCreate : BOOL -> "int"
; pstmTemplate : IStream* optional -> "sptr"
; ppstm : IStream** out -> "sptr"
; HRESULT SHCreateStreamOnFileEx(LPCWSTR pszFile, DWORD grfMode, DWORD dwAttributes, BOOL fCreate, IStream* pstmTemplate, IStream** ppstm)
#uselib "SHLWAPI.dll"
#cfunc global SHCreateStreamOnFileEx "SHCreateStreamOnFileEx" wstr, int, int, int, intptr, intptr
; res = SHCreateStreamOnFileEx(pszFile, grfMode, dwAttributes, fCreate, pstmTemplate, ppstm)
; pszFile : LPCWSTR -> "wstr"
; grfMode : DWORD -> "int"
; dwAttributes : DWORD -> "int"
; fCreate : BOOL -> "int"
; pstmTemplate : IStream* optional -> "intptr"
; ppstm : IStream** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHCreateStreamOnFileEx = shlwapi.NewProc("SHCreateStreamOnFileEx")
)

// pszFile (LPCWSTR), grfMode (DWORD), dwAttributes (DWORD), fCreate (BOOL), pstmTemplate (IStream* optional), ppstm (IStream** out)
r1, _, err := procSHCreateStreamOnFileEx.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFile))),
	uintptr(grfMode),
	uintptr(dwAttributes),
	uintptr(fCreate),
	uintptr(pstmTemplate),
	uintptr(ppstm),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHCreateStreamOnFileEx(
  pszFile: PWideChar;   // LPCWSTR
  grfMode: DWORD;   // DWORD
  dwAttributes: DWORD;   // DWORD
  fCreate: BOOL;   // BOOL
  pstmTemplate: Pointer;   // IStream* optional
  ppstm: Pointer   // IStream** out
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'SHCreateStreamOnFileEx';
result := DllCall("SHLWAPI\SHCreateStreamOnFileEx"
    , "WStr", pszFile   ; LPCWSTR
    , "UInt", grfMode   ; DWORD
    , "UInt", dwAttributes   ; DWORD
    , "Int", fCreate   ; BOOL
    , "Ptr", pstmTemplate   ; IStream* optional
    , "Ptr", ppstm   ; IStream** out
    , "Int")   ; return: HRESULT
●SHCreateStreamOnFileEx(pszFile, grfMode, dwAttributes, fCreate, pstmTemplate, ppstm) = DLL("SHLWAPI.dll", "int SHCreateStreamOnFileEx(char*, dword, dword, bool, void*, void*)")
# 呼び出し: SHCreateStreamOnFileEx(pszFile, grfMode, dwAttributes, fCreate, pstmTemplate, ppstm)
# pszFile : LPCWSTR -> "char*"
# grfMode : DWORD -> "dword"
# dwAttributes : DWORD -> "dword"
# fCreate : BOOL -> "bool"
# pstmTemplate : IStream* optional -> "void*"
# ppstm : IStream** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。