ホーム › Globalization › GetTimeFormatW
GetTimeFormatW
関数指定ロケールに従い時刻を文字列へ整形する。Unicode版。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
INT GetTimeFormatW(
DWORD Locale,
DWORD dwFlags,
const SYSTEMTIME* lpTime, // optional
LPCWSTR lpFormat, // optional
LPWSTR lpTimeStr, // optional
INT cchTime
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Locale | DWORD | in |
| dwFlags | DWORD | in |
| lpTime | SYSTEMTIME* | inoptional |
| lpFormat | LPCWSTR | inoptional |
| lpTimeStr | LPWSTR | outoptional |
| cchTime | INT | in |
戻り値の型: INT
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
INT GetTimeFormatW(
DWORD Locale,
DWORD dwFlags,
const SYSTEMTIME* lpTime, // optional
LPCWSTR lpFormat, // optional
LPWSTR lpTimeStr, // optional
INT cchTime
);[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern int GetTimeFormatW(
uint Locale, // DWORD
uint dwFlags, // DWORD
IntPtr lpTime, // SYSTEMTIME* optional
[MarshalAs(UnmanagedType.LPWStr)] string lpFormat, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpTimeStr, // LPWSTR optional, out
int cchTime // INT
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetTimeFormatW(
Locale As UInteger, ' DWORD
dwFlags As UInteger, ' DWORD
lpTime As IntPtr, ' SYSTEMTIME* optional
<MarshalAs(UnmanagedType.LPWStr)> lpFormat As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> lpTimeStr As System.Text.StringBuilder, ' LPWSTR optional, out
cchTime As Integer ' INT
) As Integer
End Function' Locale : DWORD
' dwFlags : DWORD
' lpTime : SYSTEMTIME* optional
' lpFormat : LPCWSTR optional
' lpTimeStr : LPWSTR optional, out
' cchTime : INT
Declare PtrSafe Function GetTimeFormatW Lib "kernel32" ( _
ByVal Locale As Long, _
ByVal dwFlags As Long, _
ByVal lpTime As LongPtr, _
ByVal lpFormat As LongPtr, _
ByVal lpTimeStr As LongPtr, _
ByVal cchTime 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
GetTimeFormatW = ctypes.windll.kernel32.GetTimeFormatW
GetTimeFormatW.restype = ctypes.c_int
GetTimeFormatW.argtypes = [
wintypes.DWORD, # Locale : DWORD
wintypes.DWORD, # dwFlags : DWORD
ctypes.c_void_p, # lpTime : SYSTEMTIME* optional
wintypes.LPCWSTR, # lpFormat : LPCWSTR optional
wintypes.LPWSTR, # lpTimeStr : LPWSTR optional, out
ctypes.c_int, # cchTime : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetTimeFormatW = Fiddle::Function.new(
lib['GetTimeFormatW'],
[
-Fiddle::TYPE_INT, # Locale : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # lpTime : SYSTEMTIME* optional
Fiddle::TYPE_VOIDP, # lpFormat : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lpTimeStr : LPWSTR optional, out
Fiddle::TYPE_INT, # cchTime : INT
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn GetTimeFormatW(
Locale: u32, // DWORD
dwFlags: u32, // DWORD
lpTime: *const SYSTEMTIME, // SYSTEMTIME* optional
lpFormat: *const u16, // LPCWSTR optional
lpTimeStr: *mut u16, // LPWSTR optional, out
cchTime: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetTimeFormatW(uint Locale, uint dwFlags, IntPtr lpTime, [MarshalAs(UnmanagedType.LPWStr)] string lpFormat, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpTimeStr, int cchTime);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetTimeFormatW' -Namespace Win32 -PassThru
# $api::GetTimeFormatW(Locale, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime)#uselib "KERNEL32.dll"
#func global GetTimeFormatW "GetTimeFormatW" wptr, wptr, wptr, wptr, wptr, wptr
; GetTimeFormatW Locale, dwFlags, varptr(lpTime), lpFormat, varptr(lpTimeStr), cchTime ; 戻り値は stat
; Locale : DWORD -> "wptr"
; dwFlags : DWORD -> "wptr"
; lpTime : SYSTEMTIME* optional -> "wptr"
; lpFormat : LPCWSTR optional -> "wptr"
; lpTimeStr : LPWSTR optional, out -> "wptr"
; cchTime : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetTimeFormatW "GetTimeFormatW" int, int, var, wstr, var, int ; res = GetTimeFormatW(Locale, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime) ; Locale : DWORD -> "int" ; dwFlags : DWORD -> "int" ; lpTime : SYSTEMTIME* optional -> "var" ; lpFormat : LPCWSTR optional -> "wstr" ; lpTimeStr : LPWSTR optional, out -> "var" ; cchTime : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetTimeFormatW "GetTimeFormatW" int, int, sptr, wstr, sptr, int ; res = GetTimeFormatW(Locale, dwFlags, varptr(lpTime), lpFormat, varptr(lpTimeStr), cchTime) ; Locale : DWORD -> "int" ; dwFlags : DWORD -> "int" ; lpTime : SYSTEMTIME* optional -> "sptr" ; lpFormat : LPCWSTR optional -> "wstr" ; lpTimeStr : LPWSTR optional, out -> "sptr" ; cchTime : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT GetTimeFormatW(DWORD Locale, DWORD dwFlags, SYSTEMTIME* lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchTime) #uselib "KERNEL32.dll" #cfunc global GetTimeFormatW "GetTimeFormatW" int, int, var, wstr, var, int ; res = GetTimeFormatW(Locale, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime) ; Locale : DWORD -> "int" ; dwFlags : DWORD -> "int" ; lpTime : SYSTEMTIME* optional -> "var" ; lpFormat : LPCWSTR optional -> "wstr" ; lpTimeStr : LPWSTR optional, out -> "var" ; cchTime : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT GetTimeFormatW(DWORD Locale, DWORD dwFlags, SYSTEMTIME* lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchTime) #uselib "KERNEL32.dll" #cfunc global GetTimeFormatW "GetTimeFormatW" int, int, intptr, wstr, intptr, int ; res = GetTimeFormatW(Locale, dwFlags, varptr(lpTime), lpFormat, varptr(lpTimeStr), cchTime) ; Locale : DWORD -> "int" ; dwFlags : DWORD -> "int" ; lpTime : SYSTEMTIME* optional -> "intptr" ; lpFormat : LPCWSTR optional -> "wstr" ; lpTimeStr : LPWSTR optional, out -> "intptr" ; cchTime : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetTimeFormatW = kernel32.NewProc("GetTimeFormatW")
)
// Locale (DWORD), dwFlags (DWORD), lpTime (SYSTEMTIME* optional), lpFormat (LPCWSTR optional), lpTimeStr (LPWSTR optional, out), cchTime (INT)
r1, _, err := procGetTimeFormatW.Call(
uintptr(Locale),
uintptr(dwFlags),
uintptr(lpTime),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFormat))),
uintptr(lpTimeStr),
uintptr(cchTime),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction GetTimeFormatW(
Locale: DWORD; // DWORD
dwFlags: DWORD; // DWORD
lpTime: Pointer; // SYSTEMTIME* optional
lpFormat: PWideChar; // LPCWSTR optional
lpTimeStr: PWideChar; // LPWSTR optional, out
cchTime: Integer // INT
): Integer; stdcall;
external 'KERNEL32.dll' name 'GetTimeFormatW';result := DllCall("KERNEL32\GetTimeFormatW"
, "UInt", Locale ; DWORD
, "UInt", dwFlags ; DWORD
, "Ptr", lpTime ; SYSTEMTIME* optional
, "WStr", lpFormat ; LPCWSTR optional
, "Ptr", lpTimeStr ; LPWSTR optional, out
, "Int", cchTime ; INT
, "Int") ; return: INT●GetTimeFormatW(Locale, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime) = DLL("KERNEL32.dll", "int GetTimeFormatW(dword, dword, void*, char*, char*, int)")
# 呼び出し: GetTimeFormatW(Locale, dwFlags, lpTime, lpFormat, lpTimeStr, cchTime)
# Locale : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# lpTime : SYSTEMTIME* optional -> "void*"
# lpFormat : LPCWSTR optional -> "char*"
# lpTimeStr : LPWSTR optional, out -> "char*"
# cchTime : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。