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