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