IStream_Write
関数ストリームへ指定バイト数を確実に書き込む。
シグネチャ
// SHLWAPI.dll
#include <windows.h>
HRESULT IStream_Write(
IStream* pstm,
const void* pv,
DWORD cb
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pstm | IStream* | in | 対象のストリームを指定する IStream ポインターです。 |
| pv | void* | in | 対象のストリームに送信するデータを保持するバッファへのポインターです。このバッファのサイズは、少なくとも cb バイト以上である必要があります。 |
| cb | DWORD | in | 対象のストリームに書き込むデータのバイト数です。 |
戻り値の型: HRESULT
公式ドキュメント
未知の形式のデータをバッファから指定したストリームに書き込みます。
戻り値
型: HRESULT
指定したバイト数をストリームに正常に書き込んだ場合は S_OK を返し、それ以外の場合はエラー値を返します。特に、対象のストリームに書き込まれたバイト数が cb バイト未満であった場合は、一部のデータが正常に書き込まれていたとしても、この関数は E_FAIL を返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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
#include <windows.h>
HRESULT IStream_Write(
IStream* pstm,
const void* pv,
DWORD cb
);[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern int IStream_Write(
IntPtr pstm, // IStream*
IntPtr pv, // void*
uint cb // DWORD
);<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function IStream_Write(
pstm As IntPtr, ' IStream*
pv As IntPtr, ' void*
cb As UInteger ' DWORD
) As Integer
End Function' pstm : IStream*
' pv : void*
' cb : DWORD
Declare PtrSafe Function IStream_Write Lib "shlwapi" ( _
ByVal pstm As LongPtr, _
ByVal pv As LongPtr, _
ByVal cb As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
IStream_Write = ctypes.windll.shlwapi.IStream_Write
IStream_Write.restype = ctypes.c_int
IStream_Write.argtypes = [
ctypes.c_void_p, # pstm : IStream*
ctypes.POINTER(None), # pv : void*
wintypes.DWORD, # cb : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
IStream_Write = Fiddle::Function.new(
lib['IStream_Write'],
[
Fiddle::TYPE_VOIDP, # pstm : IStream*
Fiddle::TYPE_VOIDP, # pv : void*
-Fiddle::TYPE_INT, # cb : DWORD
],
Fiddle::TYPE_INT)#[link(name = "shlwapi")]
extern "system" {
fn IStream_Write(
pstm: *mut core::ffi::c_void, // IStream*
pv: *const (), // void*
cb: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll")]
public static extern int IStream_Write(IntPtr pstm, IntPtr pv, uint cb);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_IStream_Write' -Namespace Win32 -PassThru
# $api::IStream_Write(pstm, pv, cb)#uselib "SHLWAPI.dll"
#func global IStream_Write "IStream_Write" sptr, sptr, sptr
; IStream_Write pstm, pv, cb ; 戻り値は stat
; pstm : IStream* -> "sptr"
; pv : void* -> "sptr"
; cb : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHLWAPI.dll"
#cfunc global IStream_Write "IStream_Write" sptr, sptr, int
; res = IStream_Write(pstm, pv, cb)
; pstm : IStream* -> "sptr"
; pv : void* -> "sptr"
; cb : DWORD -> "int"; HRESULT IStream_Write(IStream* pstm, void* pv, DWORD cb)
#uselib "SHLWAPI.dll"
#cfunc global IStream_Write "IStream_Write" intptr, intptr, int
; res = IStream_Write(pstm, pv, cb)
; pstm : IStream* -> "intptr"
; pv : void* -> "intptr"
; cb : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procIStream_Write = shlwapi.NewProc("IStream_Write")
)
// pstm (IStream*), pv (void*), cb (DWORD)
r1, _, err := procIStream_Write.Call(
uintptr(pstm),
uintptr(pv),
uintptr(cb),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction IStream_Write(
pstm: Pointer; // IStream*
pv: Pointer; // void*
cb: DWORD // DWORD
): Integer; stdcall;
external 'SHLWAPI.dll' name 'IStream_Write';result := DllCall("SHLWAPI\IStream_Write"
, "Ptr", pstm ; IStream*
, "Ptr", pv ; void*
, "UInt", cb ; DWORD
, "Int") ; return: HRESULT●IStream_Write(pstm, pv, cb) = DLL("SHLWAPI.dll", "int IStream_Write(void*, void*, dword)")
# 呼び出し: IStream_Write(pstm, pv, cb)
# pstm : IStream* -> "void*"
# pv : void* -> "void*"
# cb : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn IStream_Write(
pstm: ?*anyopaque, // IStream*
pv: ?*anyopaque, // void*
cb: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc IStream_Write(
pstm: pointer, # IStream*
pv: pointer, # void*
cb: uint32 # DWORD
): int32 {.importc: "IStream_Write", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
int IStream_Write(
void* pstm, // IStream*
void* pv, // void*
uint cb // DWORD
);ccall((:IStream_Write, "SHLWAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, UInt32),
pstm, pv, cb)
# pstm : IStream* -> Ptr{Cvoid}
# pv : void* -> Ptr{Cvoid}
# cb : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t IStream_Write(
void* pstm,
void* pv,
uint32_t cb);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.IStream_Write(pstm, pv, cb)
-- pstm : IStream*
-- pv : void*
-- cb : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const IStream_Write = lib.func('__stdcall', 'IStream_Write', 'int32_t', ['void *', 'void *', 'uint32_t']);
// IStream_Write(pstm, pv, cb)
// pstm : IStream* -> 'void *'
// pv : void* -> 'void *'
// cb : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
IStream_Write: { parameters: ["pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.IStream_Write(pstm, pv, cb)
// pstm : IStream* -> "pointer"
// pv : void* -> "pointer"
// cb : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t IStream_Write(
void* pstm,
void* pv,
uint32_t cb);
C, "SHLWAPI.dll");
// $ffi->IStream_Write(pstm, pv, cb);
// pstm : IStream*
// pv : void*
// cb : DWORD
// 構造体/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);
int IStream_Write(
Pointer pstm, // IStream*
Pointer pv, // void*
int cb // DWORD
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun IStream_Write = IStream_Write(
pstm : Void*, # IStream*
pv : Void*, # void*
cb : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef IStream_WriteNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32);
typedef IStream_WriteDart = int Function(Pointer<Void>, Pointer<Void>, int);
final IStream_Write = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<IStream_WriteNative, IStream_WriteDart>('IStream_Write');
// pstm : IStream* -> Pointer<Void>
// pv : void* -> Pointer<Void>
// cb : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function IStream_Write(
pstm: Pointer; // IStream*
pv: Pointer; // void*
cb: DWORD // DWORD
): Integer; stdcall;
external 'SHLWAPI.dll' name 'IStream_Write';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "IStream_Write"
c_IStream_Write :: Ptr () -> Ptr () -> Word32 -> IO Int32
-- pstm : IStream* -> Ptr ()
-- pv : void* -> Ptr ()
-- cb : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let istream_write =
foreign "IStream_Write"
((ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* pstm : IStream* -> (ptr void) *)
(* pv : void* -> (ptr void) *)
(* cb : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("IStream_Write" istream-write :convention :stdcall) :int32
(pstm :pointer) ; IStream*
(pv :pointer) ; void*
(cb :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $IStream_Write = Win32::API::More->new('SHLWAPI',
'int IStream_Write(LPVOID pstm, LPVOID pv, DWORD cb)');
# my $ret = $IStream_Write->Call($pstm, $pv, $cb);
# pstm : IStream* -> LPVOID
# pv : void* -> LPVOID
# cb : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型