Win32 API 日本語リファレンス
ホームGraphics.GdiPlus › GdipCreateStreamOnFile

GdipCreateStreamOnFile

関数
指定したファイル上にIStreamストリームを作成する。
DLLgdiplus.dll呼出規約winapi

シグネチャ

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

Status GdipCreateStreamOnFile(
    LPCWSTR filename,
    DWORD access,
    IStream** stream
);

パラメーター

名前方向説明
filenameLPCWSTRin対象ファイルのパスを示すワイド文字列(LPWSTR)。
accessDWORDinファイルアクセスモードを示すフラグ。読み取り/書き込みを指定する。
streamIStream**out生成したIStreamを受け取るポインタのポインタ(出力)。不要時はReleaseする。

戻り値の型: Status

各言語での呼び出し定義

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

Status GdipCreateStreamOnFile(
    LPCWSTR filename,
    DWORD access,
    IStream** stream
);
[DllImport("gdiplus.dll", ExactSpelling = true)]
static extern int GdipCreateStreamOnFile(
    [MarshalAs(UnmanagedType.LPWStr)] string filename,   // LPCWSTR
    uint access,   // DWORD
    IntPtr stream   // IStream** out
);
<DllImport("gdiplus.dll", ExactSpelling:=True)>
Public Shared Function GdipCreateStreamOnFile(
    <MarshalAs(UnmanagedType.LPWStr)> filename As String,   ' LPCWSTR
    access As UInteger,   ' DWORD
    stream As IntPtr   ' IStream** out
) As Integer
End Function
' filename : LPCWSTR
' access : DWORD
' stream : IStream** out
Declare PtrSafe Function GdipCreateStreamOnFile Lib "gdiplus" ( _
    ByVal filename As LongPtr, _
    ByVal access As Long, _
    ByVal stream As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GdipCreateStreamOnFile = ctypes.windll.gdiplus.GdipCreateStreamOnFile
GdipCreateStreamOnFile.restype = ctypes.c_int
GdipCreateStreamOnFile.argtypes = [
    wintypes.LPCWSTR,  # filename : LPCWSTR
    wintypes.DWORD,  # access : DWORD
    ctypes.c_void_p,  # stream : IStream** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
	procGdipCreateStreamOnFile = gdiplus.NewProc("GdipCreateStreamOnFile")
)

// filename (LPCWSTR), access (DWORD), stream (IStream** out)
r1, _, err := procGdipCreateStreamOnFile.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(filename))),
	uintptr(access),
	uintptr(stream),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // Status
function GdipCreateStreamOnFile(
  filename: PWideChar;   // LPCWSTR
  access: DWORD;   // DWORD
  stream: Pointer   // IStream** out
): Integer; stdcall;
  external 'gdiplus.dll' name 'GdipCreateStreamOnFile';
result := DllCall("gdiplus\GdipCreateStreamOnFile"
    , "WStr", filename   ; LPCWSTR
    , "UInt", access   ; DWORD
    , "Ptr", stream   ; IStream** out
    , "Int")   ; return: Status
●GdipCreateStreamOnFile(filename, access, stream) = DLL("gdiplus.dll", "int GdipCreateStreamOnFile(char*, dword, void*)")
# 呼び出し: GdipCreateStreamOnFile(filename, access, stream)
# filename : LPCWSTR -> "char*"
# access : DWORD -> "dword"
# stream : IStream** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "gdiplus" fn GdipCreateStreamOnFile(
    filename: [*c]const u16, // LPCWSTR
    access: u32, // DWORD
    stream: ?*anyopaque // IStream** out
) callconv(std.os.windows.WINAPI) i32;
proc GdipCreateStreamOnFile(
    filename: WideCString,  # LPCWSTR
    access: uint32,  # DWORD
    stream: pointer  # IStream** out
): int32 {.importc: "GdipCreateStreamOnFile", stdcall, dynlib: "gdiplus.dll".}
pragma(lib, "gdiplus");
extern(Windows)
int GdipCreateStreamOnFile(
    const(wchar)* filename,   // LPCWSTR
    uint access,   // DWORD
    void* stream   // IStream** out
);
ccall((:GdipCreateStreamOnFile, "gdiplus.dll"), stdcall, Int32,
      (Cwstring, UInt32, Ptr{Cvoid}),
      filename, access, stream)
# filename : LPCWSTR -> Cwstring
# access : DWORD -> UInt32
# stream : IStream** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GdipCreateStreamOnFile(
    const uint16_t* filename,
    uint32_t access,
    void* stream);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipCreateStreamOnFile(filename, access, stream)
-- filename : LPCWSTR
-- access : DWORD
-- stream : IStream** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipCreateStreamOnFile = lib.func('__stdcall', 'GdipCreateStreamOnFile', 'int32_t', ['str16', 'uint32_t', 'void *']);
// GdipCreateStreamOnFile(filename, access, stream)
// filename : LPCWSTR -> 'str16'
// access : DWORD -> 'uint32_t'
// stream : IStream** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("gdiplus.dll", {
  GdipCreateStreamOnFile: { parameters: ["buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GdipCreateStreamOnFile(filename, access, stream)
// filename : LPCWSTR -> "buffer"
// access : DWORD -> "u32"
// stream : IStream** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GdipCreateStreamOnFile(
    const uint16_t* filename,
    uint32_t access,
    void* stream);
C, "gdiplus.dll");
// $ffi->GdipCreateStreamOnFile(filename, access, stream);
// filename : LPCWSTR
// access : DWORD
// stream : 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 Gdiplus extends StdCallLibrary {
    Gdiplus INSTANCE = Native.load("gdiplus", Gdiplus.class);
    int GdipCreateStreamOnFile(
        WString filename,   // LPCWSTR
        int access,   // DWORD
        Pointer stream   // IStream** out
    );
}
@[Link("gdiplus")]
lib Libgdiplus
  fun GdipCreateStreamOnFile = GdipCreateStreamOnFile(
    filename : UInt16*,   # LPCWSTR
    access : UInt32,   # DWORD
    stream : 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 GdipCreateStreamOnFileNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Void>);
typedef GdipCreateStreamOnFileDart = int Function(Pointer<Utf16>, int, Pointer<Void>);
final GdipCreateStreamOnFile = DynamicLibrary.open('gdiplus.dll')
    .lookupFunction<GdipCreateStreamOnFileNative, GdipCreateStreamOnFileDart>('GdipCreateStreamOnFile');
// filename : LPCWSTR -> Pointer<Utf16>
// access : DWORD -> Uint32
// stream : IStream** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GdipCreateStreamOnFile(
  filename: PWideChar;   // LPCWSTR
  access: DWORD;   // DWORD
  stream: Pointer   // IStream** out
): Integer; stdcall;
  external 'gdiplus.dll' name 'GdipCreateStreamOnFile';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GdipCreateStreamOnFile"
  c_GdipCreateStreamOnFile :: CWString -> Word32 -> Ptr () -> IO Int32
-- filename : LPCWSTR -> CWString
-- access : DWORD -> Word32
-- stream : IStream** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let gdipcreatestreamonfile =
  foreign "GdipCreateStreamOnFile"
    ((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* filename : LPCWSTR -> (ptr uint16_t) *)
(* access : DWORD -> uint32_t *)
(* stream : IStream** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdiplus (t "gdiplus.dll"))
(cffi:use-foreign-library gdiplus)

(cffi:defcfun ("GdipCreateStreamOnFile" gdip-create-stream-on-file :convention :stdcall) :int32
  (filename (:string :encoding :utf-16le))   ; LPCWSTR
  (access :uint32)   ; DWORD
  (stream :pointer))   ; IStream** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GdipCreateStreamOnFile = Win32::API::More->new('gdiplus',
    'int GdipCreateStreamOnFile(LPCWSTR filename, DWORD access, LPVOID stream)');
# my $ret = $GdipCreateStreamOnFile->Call($filename, $access, $stream);
# filename : LPCWSTR -> LPCWSTR
# access : DWORD -> DWORD
# stream : IStream** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型