ホーム › 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 | 書式制御フラグ(CAL_USE_CP_ACP等のビット組合せ)。 |
| lpCalDateTime | CALDATETIME* | in | 書式化する日時を保持するCALDATETIME構造体へのポインター。 |
| lpFormat | LPCWSTR | in | 日付書式指定文字列へのポインター。NULLでロケール既定書式を使用。 |
| lpDateStr | LPWSTR | out | 書式化結果の文字列を受け取る出力バッファへのポインター。 |
| cchDate | INT | in | lpDateStrバッファの容量(文字数)。0で必要サイズを取得。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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)。const std = @import("std");
extern "kernel32" fn GetCalendarDateFormatEx(
lpszLocale: [*c]const u16, // LPCWSTR
dwFlags: u32, // DWORD
lpCalDateTime: [*c]CALDATETIME, // CALDATETIME*
lpFormat: [*c]const u16, // LPCWSTR
lpDateStr: [*c]u16, // LPWSTR out
cchDate: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc GetCalendarDateFormatEx(
lpszLocale: WideCString, # LPCWSTR
dwFlags: uint32, # DWORD
lpCalDateTime: ptr CALDATETIME, # CALDATETIME*
lpFormat: WideCString, # LPCWSTR
lpDateStr: ptr uint16, # LPWSTR out
cchDate: int32 # INT
): int32 {.importc: "GetCalendarDateFormatEx", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int GetCalendarDateFormatEx(
const(wchar)* lpszLocale, // LPCWSTR
uint dwFlags, // DWORD
CALDATETIME* lpCalDateTime, // CALDATETIME*
const(wchar)* lpFormat, // LPCWSTR
wchar* lpDateStr, // LPWSTR out
int cchDate // INT
);ccall((:GetCalendarDateFormatEx, "KERNEL32.dll"), stdcall, Int32,
(Cwstring, UInt32, Ptr{CALDATETIME}, Cwstring, Ptr{UInt16}, Int32),
lpszLocale, dwFlags, lpCalDateTime, lpFormat, lpDateStr, cchDate)
# lpszLocale : LPCWSTR -> Cwstring
# dwFlags : DWORD -> UInt32
# lpCalDateTime : CALDATETIME* -> Ptr{CALDATETIME}
# lpFormat : LPCWSTR -> Cwstring
# lpDateStr : LPWSTR out -> Ptr{UInt16}
# cchDate : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetCalendarDateFormatEx(
const uint16_t* lpszLocale,
uint32_t dwFlags,
void* lpCalDateTime,
const uint16_t* lpFormat,
uint16_t* lpDateStr,
int32_t cchDate);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetCalendarDateFormatEx(lpszLocale, dwFlags, lpCalDateTime, lpFormat, lpDateStr, cchDate)
-- lpszLocale : LPCWSTR
-- dwFlags : DWORD
-- lpCalDateTime : CALDATETIME*
-- lpFormat : LPCWSTR
-- lpDateStr : LPWSTR out
-- cchDate : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetCalendarDateFormatEx = lib.func('__stdcall', 'GetCalendarDateFormatEx', 'int32_t', ['str16', 'uint32_t', 'void *', 'str16', 'uint16_t *', 'int32_t']);
// GetCalendarDateFormatEx(lpszLocale, dwFlags, lpCalDateTime, lpFormat, lpDateStr, cchDate)
// lpszLocale : LPCWSTR -> 'str16'
// dwFlags : DWORD -> 'uint32_t'
// lpCalDateTime : CALDATETIME* -> 'void *'
// lpFormat : LPCWSTR -> 'str16'
// lpDateStr : LPWSTR out -> 'uint16_t *'
// cchDate : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetCalendarDateFormatEx: { parameters: ["buffer", "u32", "pointer", "buffer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.GetCalendarDateFormatEx(lpszLocale, dwFlags, lpCalDateTime, lpFormat, lpDateStr, cchDate)
// lpszLocale : LPCWSTR -> "buffer"
// dwFlags : DWORD -> "u32"
// lpCalDateTime : CALDATETIME* -> "pointer"
// lpFormat : LPCWSTR -> "buffer"
// lpDateStr : LPWSTR out -> "buffer"
// cchDate : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetCalendarDateFormatEx(
const uint16_t* lpszLocale,
uint32_t dwFlags,
void* lpCalDateTime,
const uint16_t* lpFormat,
uint16_t* lpDateStr,
int32_t cchDate);
C, "KERNEL32.dll");
// $ffi->GetCalendarDateFormatEx(lpszLocale, dwFlags, lpCalDateTime, lpFormat, lpDateStr, cchDate);
// lpszLocale : LPCWSTR
// dwFlags : DWORD
// lpCalDateTime : CALDATETIME*
// lpFormat : LPCWSTR
// lpDateStr : LPWSTR out
// cchDate : 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);
boolean GetCalendarDateFormatEx(
WString lpszLocale, // LPCWSTR
int dwFlags, // DWORD
Pointer lpCalDateTime, // CALDATETIME*
WString lpFormat, // LPCWSTR
char[] lpDateStr, // LPWSTR out
int cchDate // INT
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GetCalendarDateFormatEx = GetCalendarDateFormatEx(
lpszLocale : UInt16*, # LPCWSTR
dwFlags : UInt32, # DWORD
lpCalDateTime : CALDATETIME*, # CALDATETIME*
lpFormat : UInt16*, # LPCWSTR
lpDateStr : UInt16*, # LPWSTR out
cchDate : 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 GetCalendarDateFormatExNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Int32);
typedef GetCalendarDateFormatExDart = int Function(Pointer<Utf16>, int, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int);
final GetCalendarDateFormatEx = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetCalendarDateFormatExNative, GetCalendarDateFormatExDart>('GetCalendarDateFormatEx');
// lpszLocale : LPCWSTR -> Pointer<Utf16>
// dwFlags : DWORD -> Uint32
// lpCalDateTime : CALDATETIME* -> Pointer<Void>
// lpFormat : LPCWSTR -> Pointer<Utf16>
// lpDateStr : LPWSTR out -> Pointer<Utf16>
// cchDate : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetCalendarDateFormatEx"
c_GetCalendarDateFormatEx :: CWString -> Word32 -> Ptr () -> CWString -> CWString -> Int32 -> IO CInt
-- lpszLocale : LPCWSTR -> CWString
-- dwFlags : DWORD -> Word32
-- lpCalDateTime : CALDATETIME* -> Ptr ()
-- lpFormat : LPCWSTR -> CWString
-- lpDateStr : LPWSTR out -> CWString
-- cchDate : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getcalendardateformatex =
foreign "GetCalendarDateFormatEx"
((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* lpszLocale : LPCWSTR -> (ptr uint16_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* lpCalDateTime : CALDATETIME* -> (ptr void) *)
(* lpFormat : LPCWSTR -> (ptr uint16_t) *)
(* lpDateStr : LPWSTR out -> (ptr uint16_t) *)
(* cchDate : 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 ("GetCalendarDateFormatEx" get-calendar-date-format-ex :convention :stdcall) :int32
(lpsz-locale (:string :encoding :utf-16le)) ; LPCWSTR
(dw-flags :uint32) ; DWORD
(lp-cal-date-time :pointer) ; CALDATETIME*
(lp-format (:string :encoding :utf-16le)) ; LPCWSTR
(lp-date-str :pointer) ; LPWSTR out
(cch-date :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetCalendarDateFormatEx = Win32::API::More->new('KERNEL32',
'BOOL GetCalendarDateFormatEx(LPCWSTR lpszLocale, DWORD dwFlags, LPVOID lpCalDateTime, LPCWSTR lpFormat, LPWSTR lpDateStr, int cchDate)');
# my $ret = $GetCalendarDateFormatEx->Call($lpszLocale, $dwFlags, $lpCalDateTime, $lpFormat, $lpDateStr, $cchDate);
# lpszLocale : LPCWSTR -> LPCWSTR
# dwFlags : DWORD -> DWORD
# lpCalDateTime : CALDATETIME* -> LPVOID
# lpFormat : LPCWSTR -> LPCWSTR
# lpDateStr : LPWSTR out -> LPWSTR
# cchDate : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型