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

SHCreateStreamOnFileW

関数
指定ファイルに対するIStreamオブジェクトを生成する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

HRESULT SHCreateStreamOnFileW(
    LPCWSTR pszFile,
    DWORD grfMode,
    IStream** ppstm
);

パラメーター

名前方向
pszFileLPCWSTRin
grfModeDWORDin
ppstmIStream**out

戻り値の型: HRESULT

各言語での呼び出し定義

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

HRESULT SHCreateStreamOnFileW(
    LPCWSTR pszFile,
    DWORD grfMode,
    IStream** ppstm
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SHCreateStreamOnFileW(
    [MarshalAs(UnmanagedType.LPWStr)] string pszFile,   // LPCWSTR
    uint grfMode,   // DWORD
    IntPtr ppstm   // IStream** out
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHCreateStreamOnFileW(
    <MarshalAs(UnmanagedType.LPWStr)> pszFile As String,   ' LPCWSTR
    grfMode As UInteger,   ' DWORD
    ppstm As IntPtr   ' IStream** out
) As Integer
End Function
' pszFile : LPCWSTR
' grfMode : DWORD
' ppstm : IStream** out
Declare PtrSafe Function SHCreateStreamOnFileW Lib "shlwapi" ( _
    ByVal pszFile As LongPtr, _
    ByVal grfMode As Long, _
    ByVal ppstm As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHCreateStreamOnFileW = shlwapi.NewProc("SHCreateStreamOnFileW")
)

// pszFile (LPCWSTR), grfMode (DWORD), ppstm (IStream** out)
r1, _, err := procSHCreateStreamOnFileW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFile))),
	uintptr(grfMode),
	uintptr(ppstm),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHCreateStreamOnFileW(
  pszFile: PWideChar;   // LPCWSTR
  grfMode: DWORD;   // DWORD
  ppstm: Pointer   // IStream** out
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'SHCreateStreamOnFileW';
result := DllCall("SHLWAPI\SHCreateStreamOnFileW"
    , "WStr", pszFile   ; LPCWSTR
    , "UInt", grfMode   ; DWORD
    , "Ptr", ppstm   ; IStream** out
    , "Int")   ; return: HRESULT
●SHCreateStreamOnFileW(pszFile, grfMode, ppstm) = DLL("SHLWAPI.dll", "int SHCreateStreamOnFileW(char*, dword, void*)")
# 呼び出し: SHCreateStreamOnFileW(pszFile, grfMode, ppstm)
# pszFile : LPCWSTR -> "char*"
# grfMode : DWORD -> "dword"
# ppstm : IStream** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。