SHFormatDateTimeW
関数FILETIMEを地域設定に応じた日時文字列へ整形する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
INT SHFormatDateTimeW(
const FILETIME* pft,
DWORD* pdwFlags, // optional
LPWSTR pszBuf,
DWORD cchBuf
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pft | FILETIME* | in |
| pdwFlags | DWORD* | inoutoptional |
| pszBuf | LPWSTR | out |
| cchBuf | DWORD | in |
戻り値の型: INT
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
INT SHFormatDateTimeW(
const FILETIME* pft,
DWORD* pdwFlags, // optional
LPWSTR pszBuf,
DWORD cchBuf
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SHFormatDateTimeW(
IntPtr pft, // FILETIME*
IntPtr pdwFlags, // DWORD* optional, in/out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszBuf, // LPWSTR out
uint cchBuf // DWORD
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHFormatDateTimeW(
pft As IntPtr, ' FILETIME*
pdwFlags As IntPtr, ' DWORD* optional, in/out
<MarshalAs(UnmanagedType.LPWStr)> pszBuf As System.Text.StringBuilder, ' LPWSTR out
cchBuf As UInteger ' DWORD
) As Integer
End Function' pft : FILETIME*
' pdwFlags : DWORD* optional, in/out
' pszBuf : LPWSTR out
' cchBuf : DWORD
Declare PtrSafe Function SHFormatDateTimeW Lib "shlwapi" ( _
ByVal pft As LongPtr, _
ByVal pdwFlags As LongPtr, _
ByVal pszBuf As LongPtr, _
ByVal cchBuf As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHFormatDateTimeW = ctypes.windll.shlwapi.SHFormatDateTimeW
SHFormatDateTimeW.restype = ctypes.c_int
SHFormatDateTimeW.argtypes = [
ctypes.c_void_p, # pft : FILETIME*
ctypes.POINTER(wintypes.DWORD), # pdwFlags : DWORD* optional, in/out
wintypes.LPWSTR, # pszBuf : LPWSTR out
wintypes.DWORD, # cchBuf : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
SHFormatDateTimeW = Fiddle::Function.new(
lib['SHFormatDateTimeW'],
[
Fiddle::TYPE_VOIDP, # pft : FILETIME*
Fiddle::TYPE_VOIDP, # pdwFlags : DWORD* optional, in/out
Fiddle::TYPE_VOIDP, # pszBuf : LPWSTR out
-Fiddle::TYPE_INT, # cchBuf : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn SHFormatDateTimeW(
pft: *const FILETIME, // FILETIME*
pdwFlags: *mut u32, // DWORD* optional, in/out
pszBuf: *mut u16, // LPWSTR out
cchBuf: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern int SHFormatDateTimeW(IntPtr pft, IntPtr pdwFlags, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszBuf, uint cchBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHFormatDateTimeW' -Namespace Win32 -PassThru
# $api::SHFormatDateTimeW(pft, pdwFlags, pszBuf, cchBuf)#uselib "SHLWAPI.dll"
#func global SHFormatDateTimeW "SHFormatDateTimeW" wptr, wptr, wptr, wptr
; SHFormatDateTimeW varptr(pft), varptr(pdwFlags), varptr(pszBuf), cchBuf ; 戻り値は stat
; pft : FILETIME* -> "wptr"
; pdwFlags : DWORD* optional, in/out -> "wptr"
; pszBuf : LPWSTR out -> "wptr"
; cchBuf : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global SHFormatDateTimeW "SHFormatDateTimeW" var, var, var, int ; res = SHFormatDateTimeW(pft, pdwFlags, pszBuf, cchBuf) ; pft : FILETIME* -> "var" ; pdwFlags : DWORD* optional, in/out -> "var" ; pszBuf : LPWSTR out -> "var" ; cchBuf : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global SHFormatDateTimeW "SHFormatDateTimeW" sptr, sptr, sptr, int ; res = SHFormatDateTimeW(varptr(pft), varptr(pdwFlags), varptr(pszBuf), cchBuf) ; pft : FILETIME* -> "sptr" ; pdwFlags : DWORD* optional, in/out -> "sptr" ; pszBuf : LPWSTR out -> "sptr" ; cchBuf : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT SHFormatDateTimeW(FILETIME* pft, DWORD* pdwFlags, LPWSTR pszBuf, DWORD cchBuf) #uselib "SHLWAPI.dll" #cfunc global SHFormatDateTimeW "SHFormatDateTimeW" var, var, var, int ; res = SHFormatDateTimeW(pft, pdwFlags, pszBuf, cchBuf) ; pft : FILETIME* -> "var" ; pdwFlags : DWORD* optional, in/out -> "var" ; pszBuf : LPWSTR out -> "var" ; cchBuf : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT SHFormatDateTimeW(FILETIME* pft, DWORD* pdwFlags, LPWSTR pszBuf, DWORD cchBuf) #uselib "SHLWAPI.dll" #cfunc global SHFormatDateTimeW "SHFormatDateTimeW" intptr, intptr, intptr, int ; res = SHFormatDateTimeW(varptr(pft), varptr(pdwFlags), varptr(pszBuf), cchBuf) ; pft : FILETIME* -> "intptr" ; pdwFlags : DWORD* optional, in/out -> "intptr" ; pszBuf : LPWSTR out -> "intptr" ; cchBuf : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procSHFormatDateTimeW = shlwapi.NewProc("SHFormatDateTimeW")
)
// pft (FILETIME*), pdwFlags (DWORD* optional, in/out), pszBuf (LPWSTR out), cchBuf (DWORD)
r1, _, err := procSHFormatDateTimeW.Call(
uintptr(pft),
uintptr(pdwFlags),
uintptr(pszBuf),
uintptr(cchBuf),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SHFormatDateTimeW(
pft: Pointer; // FILETIME*
pdwFlags: Pointer; // DWORD* optional, in/out
pszBuf: PWideChar; // LPWSTR out
cchBuf: DWORD // DWORD
): Integer; stdcall;
external 'SHLWAPI.dll' name 'SHFormatDateTimeW';result := DllCall("SHLWAPI\SHFormatDateTimeW"
, "Ptr", pft ; FILETIME*
, "Ptr", pdwFlags ; DWORD* optional, in/out
, "Ptr", pszBuf ; LPWSTR out
, "UInt", cchBuf ; DWORD
, "Int") ; return: INT●SHFormatDateTimeW(pft, pdwFlags, pszBuf, cchBuf) = DLL("SHLWAPI.dll", "int SHFormatDateTimeW(void*, void*, char*, dword)")
# 呼び出し: SHFormatDateTimeW(pft, pdwFlags, pszBuf, cchBuf)
# pft : FILETIME* -> "void*"
# pdwFlags : DWORD* optional, in/out -> "void*"
# pszBuf : LPWSTR out -> "char*"
# cchBuf : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。