Win32 API 日本語リファレンス
ホームGlobalization › GetDurationFormatEx

GetDurationFormatEx

関数
ロケール名を指定して期間を文字列へ整形する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

INT GetDurationFormatEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD dwFlags,
    const SYSTEMTIME* lpDuration,   // optional
    ULONGLONG ullDuration,
    LPCWSTR lpFormat,   // optional
    LPWSTR lpDurationStr,   // optional
    INT cchDuration
);

パラメーター

名前方向
lpLocaleNameLPCWSTRinoptional
dwFlagsDWORDin
lpDurationSYSTEMTIME*inoptional
ullDurationULONGLONGin
lpFormatLPCWSTRinoptional
lpDurationStrLPWSTRoutoptional
cchDurationINTin

戻り値の型: INT

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

INT GetDurationFormatEx(
    LPCWSTR lpLocaleName,   // optional
    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 GetDurationFormatEx(
    [MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName,   // LPCWSTR optional
    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 GetDurationFormatEx(
    <MarshalAs(UnmanagedType.LPWStr)> lpLocaleName As String,   ' LPCWSTR optional
    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
' lpLocaleName : LPCWSTR optional
' dwFlags : DWORD
' lpDuration : SYSTEMTIME* optional
' ullDuration : ULONGLONG
' lpFormat : LPCWSTR optional
' lpDurationStr : LPWSTR optional, out
' cchDuration : INT
Declare PtrSafe Function GetDurationFormatEx Lib "kernel32" ( _
    ByVal lpLocaleName As LongPtr, _
    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

GetDurationFormatEx = ctypes.windll.kernel32.GetDurationFormatEx
GetDurationFormatEx.restype = ctypes.c_int
GetDurationFormatEx.argtypes = [
    wintypes.LPCWSTR,  # lpLocaleName : LPCWSTR optional
    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')
GetDurationFormatEx = Fiddle::Function.new(
  lib['GetDurationFormatEx'],
  [
    Fiddle::TYPE_VOIDP,  # lpLocaleName : LPCWSTR optional
    -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 GetDurationFormatEx(
        lpLocaleName: *const u16,  // LPCWSTR optional
        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 GetDurationFormatEx([MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName, 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_GetDurationFormatEx' -Namespace Win32 -PassThru
# $api::GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration)
#uselib "KERNEL32.dll"
#func global GetDurationFormatEx "GetDurationFormatEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetDurationFormatEx lpLocaleName, dwFlags, varptr(lpDuration), ullDuration, lpFormat, varptr(lpDurationStr), cchDuration   ; 戻り値は stat
; lpLocaleName : LPCWSTR optional -> "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 GetDurationFormatEx "GetDurationFormatEx" wstr, int, var, int64, wstr, var, int
; res = GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration)
; lpLocaleName : LPCWSTR optional -> "wstr"
; 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 は未対応)。
出力引数:
; INT GetDurationFormatEx(LPCWSTR lpLocaleName, DWORD dwFlags, SYSTEMTIME* lpDuration, ULONGLONG ullDuration, LPCWSTR lpFormat, LPWSTR lpDurationStr, INT cchDuration)
#uselib "KERNEL32.dll"
#cfunc global GetDurationFormatEx "GetDurationFormatEx" wstr, int, var, int64, wstr, var, int
; res = GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration)
; lpLocaleName : LPCWSTR optional -> "wstr"
; dwFlags : DWORD -> "int"
; lpDuration : SYSTEMTIME* optional -> "var"
; ullDuration : ULONGLONG -> "int64"
; lpFormat : LPCWSTR optional -> "wstr"
; lpDurationStr : LPWSTR optional, out -> "var"
; cchDuration : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetDurationFormatEx = kernel32.NewProc("GetDurationFormatEx")
)

// lpLocaleName (LPCWSTR optional), dwFlags (DWORD), lpDuration (SYSTEMTIME* optional), ullDuration (ULONGLONG), lpFormat (LPCWSTR optional), lpDurationStr (LPWSTR optional, out), cchDuration (INT)
r1, _, err := procGetDurationFormatEx.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpLocaleName))),
	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   // INT
function GetDurationFormatEx(
  lpLocaleName: PWideChar;   // LPCWSTR optional
  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 'GetDurationFormatEx';
result := DllCall("KERNEL32\GetDurationFormatEx"
    , "WStr", lpLocaleName   ; LPCWSTR optional
    , "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
●GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration) = DLL("KERNEL32.dll", "int GetDurationFormatEx(char*, dword, void*, qword, char*, char*, int)")
# 呼び出し: GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration)
# lpLocaleName : LPCWSTR optional -> "char*"
# 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)。