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

SHCreateStreamOnFileA

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

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

HRESULT SHCreateStreamOnFileA(
    LPCSTR pszFile,
    DWORD grfMode,
    IStream** ppstm
);

パラメーター

名前方向
pszFileLPCSTRin
grfModeDWORDin
ppstmIStream**out

戻り値の型: HRESULT

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

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

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

lib = Fiddle.dlopen('SHLWAPI.dll')
SHCreateStreamOnFileA = Fiddle::Function.new(
  lib['SHCreateStreamOnFileA'],
  [
    Fiddle::TYPE_VOIDP,  # pszFile : LPCSTR
    -Fiddle::TYPE_INT,  # grfMode : DWORD
    Fiddle::TYPE_VOIDP,  # ppstm : IStream** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn SHCreateStreamOnFileA(
        pszFile: *const u8,  // LPCSTR
        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.Ansi)]
public static extern int SHCreateStreamOnFileA([MarshalAs(UnmanagedType.LPStr)] string pszFile, uint grfMode, IntPtr ppstm);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHCreateStreamOnFileA' -Namespace Win32 -PassThru
# $api::SHCreateStreamOnFileA(pszFile, grfMode, ppstm)
#uselib "SHLWAPI.dll"
#func global SHCreateStreamOnFileA "SHCreateStreamOnFileA" sptr, sptr, sptr
; SHCreateStreamOnFileA pszFile, grfMode, ppstm   ; 戻り値は stat
; pszFile : LPCSTR -> "sptr"
; grfMode : DWORD -> "sptr"
; ppstm : IStream** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global SHCreateStreamOnFileA "SHCreateStreamOnFileA" str, int, sptr
; res = SHCreateStreamOnFileA(pszFile, grfMode, ppstm)
; pszFile : LPCSTR -> "str"
; grfMode : DWORD -> "int"
; ppstm : IStream** out -> "sptr"
; HRESULT SHCreateStreamOnFileA(LPCSTR pszFile, DWORD grfMode, IStream** ppstm)
#uselib "SHLWAPI.dll"
#cfunc global SHCreateStreamOnFileA "SHCreateStreamOnFileA" str, int, intptr
; res = SHCreateStreamOnFileA(pszFile, grfMode, ppstm)
; pszFile : LPCSTR -> "str"
; grfMode : DWORD -> "int"
; ppstm : IStream** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHCreateStreamOnFileA = shlwapi.NewProc("SHCreateStreamOnFileA")
)

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