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

StrFormatKBSizeA

関数
バイト数をキロバイト単位の文字列に整形する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

LPSTR StrFormatKBSizeA(
    LONGLONG qdw,
    LPSTR pszBuf,
    DWORD cchBuf
);

パラメーター

名前方向
qdwLONGLONGin
pszBufLPSTRout
cchBufDWORDin

戻り値の型: LPSTR

各言語での呼び出し定義

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

LPSTR StrFormatKBSizeA(
    LONGLONG qdw,
    LPSTR pszBuf,
    DWORD cchBuf
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr StrFormatKBSizeA(
    long qdw,   // LONGLONG
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszBuf,   // LPSTR out
    uint cchBuf   // DWORD
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function StrFormatKBSizeA(
    qdw As Long,   ' LONGLONG
    <MarshalAs(UnmanagedType.LPStr)> pszBuf As System.Text.StringBuilder,   ' LPSTR out
    cchBuf As UInteger   ' DWORD
) As IntPtr
End Function
' qdw : LONGLONG
' pszBuf : LPSTR out
' cchBuf : DWORD
Declare PtrSafe Function StrFormatKBSizeA Lib "shlwapi" ( _
    ByVal qdw As LongLong, _
    ByVal pszBuf As String, _
    ByVal cchBuf As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

StrFormatKBSizeA = ctypes.windll.shlwapi.StrFormatKBSizeA
StrFormatKBSizeA.restype = wintypes.LPSTR
StrFormatKBSizeA.argtypes = [
    ctypes.c_longlong,  # qdw : LONGLONG
    wintypes.LPSTR,  # pszBuf : LPSTR out
    wintypes.DWORD,  # cchBuf : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
StrFormatKBSizeA = Fiddle::Function.new(
  lib['StrFormatKBSizeA'],
  [
    Fiddle::TYPE_LONG_LONG,  # qdw : LONGLONG
    Fiddle::TYPE_VOIDP,  # pszBuf : LPSTR out
    -Fiddle::TYPE_INT,  # cchBuf : DWORD
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "shlwapi")]
extern "system" {
    fn StrFormatKBSizeA(
        qdw: i64,  // LONGLONG
        pszBuf: *mut u8,  // LPSTR out
        cchBuf: u32  // DWORD
    ) -> *mut u8;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr StrFormatKBSizeA(long qdw, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszBuf, uint cchBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrFormatKBSizeA' -Namespace Win32 -PassThru
# $api::StrFormatKBSizeA(qdw, pszBuf, cchBuf)
#uselib "SHLWAPI.dll"
#func global StrFormatKBSizeA "StrFormatKBSizeA" sptr, sptr, sptr
; StrFormatKBSizeA qdw, varptr(pszBuf), cchBuf   ; 戻り値は stat
; qdw : LONGLONG -> "sptr"
; pszBuf : LPSTR out -> "sptr"
; cchBuf : DWORD -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHLWAPI.dll"
#cfunc global StrFormatKBSizeA "StrFormatKBSizeA" int64, var, int
; res = StrFormatKBSizeA(qdw, pszBuf, cchBuf)
; qdw : LONGLONG -> "int64"
; pszBuf : LPSTR out -> "var"
; cchBuf : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; LPSTR StrFormatKBSizeA(LONGLONG qdw, LPSTR pszBuf, DWORD cchBuf)
#uselib "SHLWAPI.dll"
#cfunc global StrFormatKBSizeA "StrFormatKBSizeA" int64, var, int
; res = StrFormatKBSizeA(qdw, pszBuf, cchBuf)
; qdw : LONGLONG -> "int64"
; pszBuf : LPSTR out -> "var"
; cchBuf : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrFormatKBSizeA = shlwapi.NewProc("StrFormatKBSizeA")
)

// qdw (LONGLONG), pszBuf (LPSTR out), cchBuf (DWORD)
r1, _, err := procStrFormatKBSizeA.Call(
	uintptr(qdw),
	uintptr(pszBuf),
	uintptr(cchBuf),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPSTR
function StrFormatKBSizeA(
  qdw: Int64;   // LONGLONG
  pszBuf: PAnsiChar;   // LPSTR out
  cchBuf: DWORD   // DWORD
): PAnsiChar; stdcall;
  external 'SHLWAPI.dll' name 'StrFormatKBSizeA';
result := DllCall("SHLWAPI\StrFormatKBSizeA"
    , "Int64", qdw   ; LONGLONG
    , "Ptr", pszBuf   ; LPSTR out
    , "UInt", cchBuf   ; DWORD
    , "Ptr")   ; return: LPSTR
●StrFormatKBSizeA(qdw, pszBuf, cchBuf) = DLL("SHLWAPI.dll", "char* StrFormatKBSizeA(int64, char*, dword)")
# 呼び出し: StrFormatKBSizeA(qdw, pszBuf, cchBuf)
# qdw : LONGLONG -> "int64"
# pszBuf : LPSTR out -> "char*"
# cchBuf : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。