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

SHFormatDateTimeA

関数
FILETIMEを地域設定に応じた日時文字列へ整形する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

INT SHFormatDateTimeA(
    const FILETIME* pft,
    DWORD* pdwFlags,   // optional
    LPSTR pszBuf,
    DWORD cchBuf
);

パラメーター

名前方向
pftFILETIME*in
pdwFlagsDWORD*inoutoptional
pszBufLPSTRout
cchBufDWORDin

戻り値の型: INT

各言語での呼び出し定義

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

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

SHFormatDateTimeA = ctypes.windll.shlwapi.SHFormatDateTimeA
SHFormatDateTimeA.restype = ctypes.c_int
SHFormatDateTimeA.argtypes = [
    ctypes.c_void_p,  # pft : FILETIME*
    ctypes.POINTER(wintypes.DWORD),  # pdwFlags : DWORD* optional, in/out
    wintypes.LPSTR,  # pszBuf : LPSTR out
    wintypes.DWORD,  # cchBuf : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
SHFormatDateTimeA = Fiddle::Function.new(
  lib['SHFormatDateTimeA'],
  [
    Fiddle::TYPE_VOIDP,  # pft : FILETIME*
    Fiddle::TYPE_VOIDP,  # pdwFlags : DWORD* optional, in/out
    Fiddle::TYPE_VOIDP,  # pszBuf : LPSTR out
    -Fiddle::TYPE_INT,  # cchBuf : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn SHFormatDateTimeA(
        pft: *const FILETIME,  // FILETIME*
        pdwFlags: *mut u32,  // DWORD* optional, in/out
        pszBuf: *mut u8,  // LPSTR out
        cchBuf: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern int SHFormatDateTimeA(IntPtr pft, IntPtr pdwFlags, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszBuf, uint cchBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHFormatDateTimeA' -Namespace Win32 -PassThru
# $api::SHFormatDateTimeA(pft, pdwFlags, pszBuf, cchBuf)
#uselib "SHLWAPI.dll"
#func global SHFormatDateTimeA "SHFormatDateTimeA" sptr, sptr, sptr, sptr
; SHFormatDateTimeA varptr(pft), varptr(pdwFlags), varptr(pszBuf), cchBuf   ; 戻り値は stat
; pft : FILETIME* -> "sptr"
; pdwFlags : DWORD* optional, in/out -> "sptr"
; pszBuf : LPSTR out -> "sptr"
; cchBuf : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHLWAPI.dll"
#cfunc global SHFormatDateTimeA "SHFormatDateTimeA" var, var, var, int
; res = SHFormatDateTimeA(pft, pdwFlags, pszBuf, cchBuf)
; pft : FILETIME* -> "var"
; pdwFlags : DWORD* optional, in/out -> "var"
; pszBuf : LPSTR out -> "var"
; cchBuf : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT SHFormatDateTimeA(FILETIME* pft, DWORD* pdwFlags, LPSTR pszBuf, DWORD cchBuf)
#uselib "SHLWAPI.dll"
#cfunc global SHFormatDateTimeA "SHFormatDateTimeA" var, var, var, int
; res = SHFormatDateTimeA(pft, pdwFlags, pszBuf, cchBuf)
; pft : FILETIME* -> "var"
; pdwFlags : DWORD* optional, in/out -> "var"
; pszBuf : LPSTR out -> "var"
; cchBuf : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procSHFormatDateTimeA = shlwapi.NewProc("SHFormatDateTimeA")
)

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