SHCreateStreamOnFileA
関数指定ファイルに対するIStreamオブジェクトを生成する。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
HRESULT SHCreateStreamOnFileA(
LPCSTR pszFile,
DWORD grfMode,
IStream** ppstm
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszFile | LPCSTR | in | ファイル名を指定する null 終端文字列へのポインター。 |
| grfMode | DWORD | in | ファイルアクセスモードと、ストリームを公開するオブジェクトの作成および削除の方法を指定するために使用する 1 つ以上の STGM 値。 |
| ppstm | IStream** | out | ファイルに関連付けられたストリームの IStream インターフェイスポインターを受け取ります。 |
戻り値の型: HRESULT
公式ドキュメント
SHCreateStreamOnFile は変更または使用できなくなる可能性があります。代わりに SHCreateStreamOnFileEx を使用してください。(ANSI)
戻り値
型: HRESULT
この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。
解説(Remarks)
SHCreateStreamOnFileEx はすべての STGM モードを完全にサポートし、新しいファイルを作成する場合に呼び出し元がファイル属性を指定できるようにします。
メモ
shlwapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SHCreateStreamOnFile を定義しています。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じてコンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、「Conventions for Function Prototypes」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 // HRESULTfunction 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)。const std = @import("std");
extern "shlwapi" fn SHCreateStreamOnFileA(
pszFile: [*c]const u8, // LPCSTR
grfMode: u32, // DWORD
ppstm: ?*anyopaque // IStream** out
) callconv(std.os.windows.WINAPI) i32;proc SHCreateStreamOnFileA(
pszFile: cstring, # LPCSTR
grfMode: uint32, # DWORD
ppstm: pointer # IStream** out
): int32 {.importc: "SHCreateStreamOnFileA", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
int SHCreateStreamOnFileA(
const(char)* pszFile, // LPCSTR
uint grfMode, // DWORD
void* ppstm // IStream** out
);ccall((:SHCreateStreamOnFileA, "SHLWAPI.dll"), stdcall, Int32,
(Cstring, UInt32, Ptr{Cvoid}),
pszFile, grfMode, ppstm)
# pszFile : LPCSTR -> Cstring
# grfMode : DWORD -> UInt32
# ppstm : IStream** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SHCreateStreamOnFileA(
const char* pszFile,
uint32_t grfMode,
void* ppstm);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.SHCreateStreamOnFileA(pszFile, grfMode, ppstm)
-- pszFile : LPCSTR
-- grfMode : DWORD
-- ppstm : IStream** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const SHCreateStreamOnFileA = lib.func('__stdcall', 'SHCreateStreamOnFileA', 'int32_t', ['str', 'uint32_t', 'void *']);
// SHCreateStreamOnFileA(pszFile, grfMode, ppstm)
// pszFile : LPCSTR -> 'str'
// grfMode : DWORD -> 'uint32_t'
// ppstm : IStream** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
SHCreateStreamOnFileA: { parameters: ["buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SHCreateStreamOnFileA(pszFile, grfMode, ppstm)
// pszFile : LPCSTR -> "buffer"
// grfMode : DWORD -> "u32"
// ppstm : IStream** out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SHCreateStreamOnFileA(
const char* pszFile,
uint32_t grfMode,
void* ppstm);
C, "SHLWAPI.dll");
// $ffi->SHCreateStreamOnFileA(pszFile, grfMode, ppstm);
// pszFile : LPCSTR
// grfMode : DWORD
// ppstm : IStream** 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 Shlwapi extends StdCallLibrary {
Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.ASCII_OPTIONS);
int SHCreateStreamOnFileA(
String pszFile, // LPCSTR
int grfMode, // DWORD
Pointer ppstm // IStream** out
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun SHCreateStreamOnFileA = SHCreateStreamOnFileA(
pszFile : UInt8*, # LPCSTR
grfMode : UInt32, # DWORD
ppstm : Void* # IStream** out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHCreateStreamOnFileANative = Int32 Function(Pointer<Utf8>, Uint32, Pointer<Void>);
typedef SHCreateStreamOnFileADart = int Function(Pointer<Utf8>, int, Pointer<Void>);
final SHCreateStreamOnFileA = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<SHCreateStreamOnFileANative, SHCreateStreamOnFileADart>('SHCreateStreamOnFileA');
// pszFile : LPCSTR -> Pointer<Utf8>
// grfMode : DWORD -> Uint32
// ppstm : IStream** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHCreateStreamOnFileA(
pszFile: PAnsiChar; // LPCSTR
grfMode: DWORD; // DWORD
ppstm: Pointer // IStream** out
): Integer; stdcall;
external 'SHLWAPI.dll' name 'SHCreateStreamOnFileA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHCreateStreamOnFileA"
c_SHCreateStreamOnFileA :: CString -> Word32 -> Ptr () -> IO Int32
-- pszFile : LPCSTR -> CString
-- grfMode : DWORD -> Word32
-- ppstm : IStream** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shcreatestreamonfilea =
foreign "SHCreateStreamOnFileA"
(string @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* pszFile : LPCSTR -> string *)
(* grfMode : DWORD -> uint32_t *)
(* ppstm : IStream** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("SHCreateStreamOnFileA" shcreate-stream-on-file-a :convention :stdcall) :int32
(psz-file :string) ; LPCSTR
(grf-mode :uint32) ; DWORD
(ppstm :pointer)) ; IStream** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHCreateStreamOnFileA = Win32::API::More->new('SHLWAPI',
'int SHCreateStreamOnFileA(LPCSTR pszFile, DWORD grfMode, LPVOID ppstm)');
# my $ret = $SHCreateStreamOnFileA->Call($pszFile, $grfMode, $ppstm);
# pszFile : LPCSTR -> LPCSTR
# grfMode : DWORD -> DWORD
# ppstm : IStream** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SHCreateStreamOnFileW (Unicode版) — 指定ファイルに対するIStreamオブジェクトを生成する。
類似 API
- f SHCreateStreamOnFileEx — 属性やテンプレート指定でファイルのストリームを生成する。
使用する型