GetDurationFormatEx
関数シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpLocaleName | LPCWSTR | inoptional | ロケール名へのポインター、または次の定義済みの値のいずれかを指定します。 |
| dwFlags | DWORD | in | 関数のオプションを指定するフラグです。lpFormat が NULL に設定されていない場合、このパラメーターは 0 に設定する必要があります。lpFormat が NULL に設定されている場合、アプリケーションは LOCALE_NOUSEROVERRIDE を指定して、指定したロケールのシステム既定の継続時間書式を使用して文字列を書式設定できます。 注意 LOCALE_NOUSEROVERRIDE はユーザー設定を無効にするため、その使用は強く推奨されません。
|
| lpDuration | SYSTEMTIME* | inoptional | 書式設定する時間の長さの情報を格納した SYSTEMTIME 構造体へのポインターです。関数にこのパラメーターを無視させて ullDuration を使用させる場合、アプリケーションはこのパラメーターを NULL に設定します。 |
| ullDuration | ULONGLONG | in | 継続時間に含まれる 100 ナノ秒単位の個数を表す 64 ビットの符号なし整数です。lpDuration と ullDuration の両方が設定されている場合は、lpDuration パラメーターが優先されます。lpDuration が NULL に設定され、ullDuration が 0 に設定されている場合、継続時間は 0 になります。 |
| lpFormat | LPCWSTR | inoptional | 以下に示す文字を含む書式文字列へのポインターです。指定したロケールの継続時間書式に従って関数に文字列を書式設定させる場合、アプリケーションはこのパラメーターを NULL に設定できます。lpFormat が NULL に設定されていない場合、関数は書式指定文字列で指定されていない情報についてのみロケールを使用します。 |
| lpDurationStr | LPWSTR | outoptional | 関数が継続時間文字列を取得するバッファーへのポインターです。 あるいは、cchDuration が 0 に設定されている場合、このパラメーターには NULL が取得されます。この場合、関数は継続時間文字列バッファーに必要なサイズを返します。 |
| cchDuration | INT | in | lpDurationStr が指すバッファーのサイズ (文字数単位) です。 あるいは、アプリケーションはこのパラメーターを 0 に設定できます。この場合、関数は lpDurationStr に NULL を取得し、継続時間文字列バッファーに必要なサイズを返します。 |
戻り値の型: INT
公式ドキュメント
名前で指定したロケールに対して、時間の長さ(継続時間)を時刻文字列として書式設定します。
戻り値
成功した場合、lpDurationStr が指すバッファーに取得された文字数を返します。lpDurationStr が NULL に設定され、cchDuration が 0 に設定されている場合、関数は終端の null 文字を含めた継続時間文字列バッファーに必要なサイズを返します。たとえば、バッファーに 10 文字が書き込まれる場合、関数は終端の null 文字を含めて 11 を返します。
成功しなかった場合、関数は 0 を返します。拡張エラー情報を取得するには、アプリケーションは GetLastError を呼び出すことができます。これは次のいずれかのエラーコードを返す可能性があります。
- ERROR_INSUFFICIENT_BUFFER。指定されたバッファーサイズが十分でなかったか、誤って NULL に設定されていました。
- ERROR_INVALID_PARAMETER。いずれかのパラメーター値が無効でした。
解説(Remarks)
この関数は、ファイル時刻を表示するマルチメディアアプリケーションや、競技イベントの終了時刻を表示するアプリケーションで使用できます。
この関数は、SYSTEMTIME 構造体の最初の 3 つのメンバー、wYear、wMonth、wDayOfWeek を無視します。
この関数は、カスタムロケールからデータを取得できます。データはコンピューター間やアプリケーションの実行間で同一であることは保証されません。アプリケーションがデータを永続化または送信する必要がある場合は、永続的なロケールデータの使用を参照してください。
継続時間書式文字列には次の特性があります。
-
書式設定文字は小文字です。
注意 ただし、GetTimeFormatEx との整合性を保つため、(H) は例外とされます。
- 時、分、秒の 2 桁書式文字列は、値が 10 未満の場合に先頭に 0 を付加します。
- 最初の出力フィールドは、いかなる範囲チェック (時<24、分<60、秒<60、ミリ秒<1000) も受けません。日も範囲チェックの対象外です。
- この関数は、すべての書式文字列がフィールドサイズの大きい順 (たとえば、時、分、秒、ミリ秒) になっていると想定します。
- 最初に表示されるフィールドは、書式文字列で定義されたとおりに正規化されます。たとえば、アプリケーションが 310 秒を指定し、書式文字列が m:ss の場合、出力は 5:10 になります。ただし、書式文字列が分と秒を指定し、アプリケーションが時を指定した場合、分フィールドはそれに応じて調整されます。
- 小数部が最初のフィールドでない場合、書式文字列内の "f" 文字の数は表示する小数の桁数を示します (上限は 9)。小数部が最初のフィールドの場合、"f" 文字の数は 1 秒未満の有効桁数を示します。
- 丸めは、五捨六入や四捨五入のような規則ではなく、切り捨てによって行われます。
- 文字をエスケープするには単一引用符を使用します。
例
以下は、指定した時間の長さに対する継続時間書式とそれに対応する出力の例です。
SYSTEMTIME = 14 日、2 時間、45 分、12 秒、247 ミリ秒
| 書式 | 出力 |
|---|---|
| d:hh:mm:ss | 14:02:45:12 |
| hh:mm:ss:ff | 338:45:12:24 |
| hh:mm:ss:fff | 338:45:12:247 |
| h' h 'mm' m 'ss' s' | 338 h 45 m 12 s |
SYSTEMTIME = 345 秒
| 書式 | 出力 |
|---|---|
| hh:mm:ss | 00:05:45 |
| h:mm:ss | 0:05:45 |
| mm:ss | 05:45 |
| m:ss | 5:45 |
| mm' m 'ss' s' | 05 m 45 s |
| ss | 345 |
| ss' seconds' | 345 seconds |
uulDuration = 51234567 (5.1234567 秒)
| 書式 | 出力 |
|---|---|
| s.fff | 5.123 |
| s.ffffff | 5.123456 |
| s.fffffffff | 5.123456700 (末尾に 0 を付加) |
| fff 'ms' | 5123 ms |
| ffffff 'microseconds' | 5123456 microseconds |
| fffffffff 'ns' | 5123456700 ns |
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 は未対応)。#uselib "KERNEL32.dll" #cfunc global GetDurationFormatEx "GetDurationFormatEx" wstr, int, sptr, int64, wstr, sptr, int ; res = GetDurationFormatEx(lpLocaleName, dwFlags, varptr(lpDuration), ullDuration, lpFormat, varptr(lpDurationStr), cchDuration) ; lpLocaleName : LPCWSTR optional -> "wstr" ; 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 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 方式にも切替可。; 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, intptr, int64, wstr, intptr, int ; res = GetDurationFormatEx(lpLocaleName, dwFlags, varptr(lpDuration), ullDuration, lpFormat, varptr(lpDurationStr), cchDuration) ; lpLocaleName : LPCWSTR optional -> "wstr" ; 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")
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 // INTfunction 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)。const std = @import("std");
extern "kernel32" fn GetDurationFormatEx(
lpLocaleName: [*c]const u16, // LPCWSTR optional
dwFlags: u32, // DWORD
lpDuration: [*c]SYSTEMTIME, // SYSTEMTIME* optional
ullDuration: u64, // ULONGLONG
lpFormat: [*c]const u16, // LPCWSTR optional
lpDurationStr: [*c]u16, // LPWSTR optional, out
cchDuration: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc GetDurationFormatEx(
lpLocaleName: WideCString, # LPCWSTR optional
dwFlags: uint32, # DWORD
lpDuration: ptr SYSTEMTIME, # SYSTEMTIME* optional
ullDuration: uint64, # ULONGLONG
lpFormat: WideCString, # LPCWSTR optional
lpDurationStr: ptr uint16, # LPWSTR optional, out
cchDuration: int32 # INT
): int32 {.importc: "GetDurationFormatEx", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int GetDurationFormatEx(
const(wchar)* lpLocaleName, // LPCWSTR optional
uint dwFlags, // DWORD
SYSTEMTIME* lpDuration, // SYSTEMTIME* optional
ulong ullDuration, // ULONGLONG
const(wchar)* lpFormat, // LPCWSTR optional
wchar* lpDurationStr, // LPWSTR optional, out
int cchDuration // INT
);ccall((:GetDurationFormatEx, "KERNEL32.dll"), stdcall, Int32,
(Cwstring, UInt32, Ptr{SYSTEMTIME}, UInt64, Cwstring, Ptr{UInt16}, Int32),
lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration)
# lpLocaleName : LPCWSTR optional -> Cwstring
# dwFlags : DWORD -> UInt32
# lpDuration : SYSTEMTIME* optional -> Ptr{SYSTEMTIME}
# ullDuration : ULONGLONG -> UInt64
# lpFormat : LPCWSTR optional -> Cwstring
# lpDurationStr : LPWSTR optional, out -> Ptr{UInt16}
# cchDuration : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetDurationFormatEx(
const uint16_t* lpLocaleName,
uint32_t dwFlags,
void* lpDuration,
uint64_t ullDuration,
const uint16_t* lpFormat,
uint16_t* lpDurationStr,
int32_t cchDuration);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration)
-- lpLocaleName : LPCWSTR optional
-- dwFlags : DWORD
-- lpDuration : SYSTEMTIME* optional
-- ullDuration : ULONGLONG
-- lpFormat : LPCWSTR optional
-- lpDurationStr : LPWSTR optional, out
-- cchDuration : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetDurationFormatEx = lib.func('__stdcall', 'GetDurationFormatEx', 'int32_t', ['str16', 'uint32_t', 'void *', 'uint64_t', 'str16', 'uint16_t *', 'int32_t']);
// GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration)
// lpLocaleName : LPCWSTR optional -> 'str16'
// dwFlags : DWORD -> 'uint32_t'
// lpDuration : SYSTEMTIME* optional -> 'void *'
// ullDuration : ULONGLONG -> 'uint64_t'
// lpFormat : LPCWSTR optional -> 'str16'
// lpDurationStr : LPWSTR optional, out -> 'uint16_t *'
// cchDuration : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetDurationFormatEx: { parameters: ["buffer", "u32", "pointer", "u64", "buffer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration)
// lpLocaleName : LPCWSTR optional -> "buffer"
// dwFlags : DWORD -> "u32"
// lpDuration : SYSTEMTIME* optional -> "pointer"
// ullDuration : ULONGLONG -> "u64"
// lpFormat : LPCWSTR optional -> "buffer"
// lpDurationStr : LPWSTR optional, out -> "buffer"
// cchDuration : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetDurationFormatEx(
const uint16_t* lpLocaleName,
uint32_t dwFlags,
void* lpDuration,
uint64_t ullDuration,
const uint16_t* lpFormat,
uint16_t* lpDurationStr,
int32_t cchDuration);
C, "KERNEL32.dll");
// $ffi->GetDurationFormatEx(lpLocaleName, dwFlags, lpDuration, ullDuration, lpFormat, lpDurationStr, cchDuration);
// lpLocaleName : LPCWSTR optional
// dwFlags : DWORD
// lpDuration : SYSTEMTIME* optional
// ullDuration : ULONGLONG
// lpFormat : LPCWSTR optional
// lpDurationStr : LPWSTR optional, out
// cchDuration : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
int GetDurationFormatEx(
WString lpLocaleName, // LPCWSTR optional
int dwFlags, // DWORD
Pointer lpDuration, // SYSTEMTIME* optional
long ullDuration, // ULONGLONG
WString lpFormat, // LPCWSTR optional
char[] lpDurationStr, // LPWSTR optional, out
int cchDuration // INT
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GetDurationFormatEx = GetDurationFormatEx(
lpLocaleName : UInt16*, # LPCWSTR optional
dwFlags : UInt32, # DWORD
lpDuration : SYSTEMTIME*, # SYSTEMTIME* optional
ullDuration : UInt64, # ULONGLONG
lpFormat : UInt16*, # LPCWSTR optional
lpDurationStr : UInt16*, # LPWSTR optional, out
cchDuration : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetDurationFormatExNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Void>, Uint64, Pointer<Utf16>, Pointer<Utf16>, Int32);
typedef GetDurationFormatExDart = int Function(Pointer<Utf16>, int, Pointer<Void>, int, Pointer<Utf16>, Pointer<Utf16>, int);
final GetDurationFormatEx = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetDurationFormatExNative, GetDurationFormatExDart>('GetDurationFormatEx');
// lpLocaleName : LPCWSTR optional -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// lpDuration : SYSTEMTIME* optional -> Pointer<Void>
// ullDuration : ULONGLONG -> Uint64
// lpFormat : LPCWSTR optional -> Pointer<Utf16>
// lpDurationStr : LPWSTR optional, out -> Pointer<Utf16>
// cchDuration : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetDurationFormatEx"
c_GetDurationFormatEx :: CWString -> Word32 -> Ptr () -> Word64 -> CWString -> CWString -> Int32 -> IO Int32
-- lpLocaleName : LPCWSTR optional -> CWString
-- dwFlags : DWORD -> Word32
-- lpDuration : SYSTEMTIME* optional -> Ptr ()
-- ullDuration : ULONGLONG -> Word64
-- lpFormat : LPCWSTR optional -> CWString
-- lpDurationStr : LPWSTR optional, out -> CWString
-- cchDuration : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getdurationformatex =
foreign "GetDurationFormatEx"
((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> uint64_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* lpLocaleName : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* lpDuration : SYSTEMTIME* optional -> (ptr void) *)
(* ullDuration : ULONGLONG -> uint64_t *)
(* lpFormat : LPCWSTR optional -> (ptr uint16_t) *)
(* lpDurationStr : LPWSTR optional, out -> (ptr uint16_t) *)
(* cchDuration : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetDurationFormatEx" get-duration-format-ex :convention :stdcall) :int32
(lp-locale-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-flags :uint32) ; DWORD
(lp-duration :pointer) ; SYSTEMTIME* optional
(ull-duration :uint64) ; ULONGLONG
(lp-format (:string :encoding :utf-16le)) ; LPCWSTR optional
(lp-duration-str :pointer) ; LPWSTR optional, out
(cch-duration :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetDurationFormatEx = Win32::API::More->new('KERNEL32',
'int GetDurationFormatEx(LPCWSTR lpLocaleName, DWORD dwFlags, LPVOID lpDuration, UINT64 ullDuration, LPCWSTR lpFormat, LPWSTR lpDurationStr, int cchDuration)');
# my $ret = $GetDurationFormatEx->Call($lpLocaleName, $dwFlags, $lpDuration, $ullDuration, $lpFormat, $lpDurationStr, $cchDuration);
# lpLocaleName : LPCWSTR optional -> LPCWSTR
# dwFlags : DWORD -> DWORD
# lpDuration : SYSTEMTIME* optional -> LPVOID
# ullDuration : ULONGLONG -> UINT64
# lpFormat : LPCWSTR optional -> LPCWSTR
# lpDurationStr : LPWSTR optional, out -> LPWSTR
# cchDuration : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetDurationFormat — 指定ロケールに従い期間を文字列へ整形する。
- f GetDateFormatEx — ロケール名と暦を指定して日付を文字列へ整形する。
- f GetLocaleInfoEx — ロケール名を指定してロケール情報を取得する。
- f GetTimeFormatEx — ロケール名を指定して時刻を文字列へ整形する。