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

GetCalendarInfoEx

関数
ロケール名を指定してカレンダー情報を取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

INT GetCalendarInfoEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD Calendar,
    LPCWSTR lpReserved,   // optional
    DWORD CalType,
    LPWSTR lpCalData,   // optional
    INT cchData,
    DWORD* lpValue   // optional
);

パラメーター

名前方向説明
lpLocaleNameLPCWSTRinoptional

ロケール名へのポインター、または次の定義済みの値のいずれかです。

CalendarDWORDinカレンダー識別子です。
lpReservedLPCWSTRinoptional予約済みです。NULL である必要があります。
CalTypeDWORDin

取得する情報の種類です。詳細については、Calendar Type Information を参照してください。

注意 このパラメーターに CAL_IYEAROFFSETRANGE または CAL_SERASTRING を指定した場合、GetCalendarInfoEx は 1 つの文字列のみを返します。いずれの場合も、現在の元号が返されます。
CAL_NOUSEROVERRIDE の場合、この関数は SetCalendarInfo によって設定された値を無視し、現在のシステム既定ロケールに対するデータベースの設定を使用します。この種類は、CAL_NOUSEROVERRIDE | CAL_ITWODIGITYEARMAX という組み合わせでのみ意味を持ちます。CAL_ITWODIGITYEARMAX は、SetCalendarInfo によって設定できる唯一の値です。
lpCalDataLPWSTRoutoptionalこの関数が要求されたデータを文字列として取得するバッファーへのポインターです。CalTypeCAL_RETURN_NUMBER が指定されている場合、このパラメーターには NULL を取得する必要があります。
cchDataINTinlpCalData バッファーのサイズ(文字数)です。アプリケーションは、このパラメーターを 0 に設定して、カレンダーデータバッファーに必要なサイズを返すことができます。この場合、lpCalData パラメーターは使用されません。CalTypeCAL_RETURN_NUMBER が指定されている場合、cchData の値は 0 でなければなりません。
lpValueDWORD*outoptional要求されたデータを数値として受け取る変数へのポインターです。CalTypeCAL_RETURN_NUMBER が指定されている場合、lpValueNULL であってはなりません。CalTypeCAL_RETURN_NUMBER が指定されていない場合、lpValueNULL でなければなりません。

戻り値の型: INT

公式ドキュメント

名前で指定されたロケールのカレンダーに関する情報を取得します。注意 アプリケーションが Windows Vista 以降でのみ動作するように設計されている場合は、GetCalendarInfo よりもこの関数を優先して呼び出す必要があります。注意 この関数は、たとえばカスタムロケールなどによってリリース間で変化するデータを取得することがあります。アプリケーションがデータを永続化または送信する必要がある場合は、「Using Persistent Locale Data」を参照してください。

戻り値

成功した場合、lpCalData バッファーに取得された文字数を返します。関数が成功し、cchData が 0 に設定されており、CAL_RETURN_NUMBER が指定されていない場合、戻り値はロケール情報を保持するために必要なバッファーのサイズです。関数が成功し、cchData が 0 に設定されており、CAL_RETURN_NUMBER が指定されている場合、戻り値は lpValue パラメーターに書き込まれた値のサイズです。このサイズは常に 2 です。

関数が成功しなかった場合は 0 を返します。拡張エラー情報を取得するには、アプリケーションは GetLastError を呼び出すことができます。これは次のエラーコードのいずれかを返すことがあります。

解説(Remarks)

注意 この API は、2019 年 5 月の日本の元号変更に対応するために更新されています。アプリケーションが和暦をサポートしている場合は、新しい元号を正しく処理できることを検証する必要があります。詳細については、Prepare your application for the Japanese era change を参照してください。
Windows 8 以降: アプリケーションが Windows.Globalization 名前空間からの言語タグをこの関数に渡す場合、まず ResolveLocaleName を呼び出してタグを変換する必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

INT GetCalendarInfoEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD Calendar,
    LPCWSTR lpReserved,   // optional
    DWORD CalType,
    LPWSTR lpCalData,   // optional
    INT cchData,
    DWORD* lpValue   // optional
);
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern int GetCalendarInfoEx(
    [MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName,   // LPCWSTR optional
    uint Calendar,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpReserved,   // LPCWSTR optional
    uint CalType,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpCalData,   // LPWSTR optional, out
    int cchData,   // INT
    IntPtr lpValue   // DWORD* optional, out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetCalendarInfoEx(
    <MarshalAs(UnmanagedType.LPWStr)> lpLocaleName As String,   ' LPCWSTR optional
    Calendar As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpReserved As String,   ' LPCWSTR optional
    CalType As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpCalData As System.Text.StringBuilder,   ' LPWSTR optional, out
    cchData As Integer,   ' INT
    lpValue As IntPtr   ' DWORD* optional, out
) As Integer
End Function
' lpLocaleName : LPCWSTR optional
' Calendar : DWORD
' lpReserved : LPCWSTR optional
' CalType : DWORD
' lpCalData : LPWSTR optional, out
' cchData : INT
' lpValue : DWORD* optional, out
Declare PtrSafe Function GetCalendarInfoEx Lib "kernel32" ( _
    ByVal lpLocaleName As LongPtr, _
    ByVal Calendar As Long, _
    ByVal lpReserved As LongPtr, _
    ByVal CalType As Long, _
    ByVal lpCalData As LongPtr, _
    ByVal cchData As Long, _
    ByVal lpValue As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetCalendarInfoEx = ctypes.windll.kernel32.GetCalendarInfoEx
GetCalendarInfoEx.restype = ctypes.c_int
GetCalendarInfoEx.argtypes = [
    wintypes.LPCWSTR,  # lpLocaleName : LPCWSTR optional
    wintypes.DWORD,  # Calendar : DWORD
    wintypes.LPCWSTR,  # lpReserved : LPCWSTR optional
    wintypes.DWORD,  # CalType : DWORD
    wintypes.LPWSTR,  # lpCalData : LPWSTR optional, out
    ctypes.c_int,  # cchData : INT
    ctypes.POINTER(wintypes.DWORD),  # lpValue : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetCalendarInfoEx = Fiddle::Function.new(
  lib['GetCalendarInfoEx'],
  [
    Fiddle::TYPE_VOIDP,  # lpLocaleName : LPCWSTR optional
    -Fiddle::TYPE_INT,  # Calendar : DWORD
    Fiddle::TYPE_VOIDP,  # lpReserved : LPCWSTR optional
    -Fiddle::TYPE_INT,  # CalType : DWORD
    Fiddle::TYPE_VOIDP,  # lpCalData : LPWSTR optional, out
    Fiddle::TYPE_INT,  # cchData : INT
    Fiddle::TYPE_VOIDP,  # lpValue : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetCalendarInfoEx(
        lpLocaleName: *const u16,  // LPCWSTR optional
        Calendar: u32,  // DWORD
        lpReserved: *const u16,  // LPCWSTR optional
        CalType: u32,  // DWORD
        lpCalData: *mut u16,  // LPWSTR optional, out
        cchData: i32,  // INT
        lpValue: *mut u32  // DWORD* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern int GetCalendarInfoEx([MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName, uint Calendar, [MarshalAs(UnmanagedType.LPWStr)] string lpReserved, uint CalType, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpCalData, int cchData, IntPtr lpValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetCalendarInfoEx' -Namespace Win32 -PassThru
# $api::GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue)
#uselib "KERNEL32.dll"
#func global GetCalendarInfoEx "GetCalendarInfoEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetCalendarInfoEx lpLocaleName, Calendar, lpReserved, CalType, varptr(lpCalData), cchData, varptr(lpValue)   ; 戻り値は stat
; lpLocaleName : LPCWSTR optional -> "sptr"
; Calendar : DWORD -> "sptr"
; lpReserved : LPCWSTR optional -> "sptr"
; CalType : DWORD -> "sptr"
; lpCalData : LPWSTR optional, out -> "sptr"
; cchData : INT -> "sptr"
; lpValue : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetCalendarInfoEx "GetCalendarInfoEx" wstr, int, wstr, int, var, int, var
; res = GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue)
; lpLocaleName : LPCWSTR optional -> "wstr"
; Calendar : DWORD -> "int"
; lpReserved : LPCWSTR optional -> "wstr"
; CalType : DWORD -> "int"
; lpCalData : LPWSTR optional, out -> "var"
; cchData : INT -> "int"
; lpValue : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT GetCalendarInfoEx(LPCWSTR lpLocaleName, DWORD Calendar, LPCWSTR lpReserved, DWORD CalType, LPWSTR lpCalData, INT cchData, DWORD* lpValue)
#uselib "KERNEL32.dll"
#cfunc global GetCalendarInfoEx "GetCalendarInfoEx" wstr, int, wstr, int, var, int, var
; res = GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue)
; lpLocaleName : LPCWSTR optional -> "wstr"
; Calendar : DWORD -> "int"
; lpReserved : LPCWSTR optional -> "wstr"
; CalType : DWORD -> "int"
; lpCalData : LPWSTR optional, out -> "var"
; cchData : INT -> "int"
; lpValue : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetCalendarInfoEx = kernel32.NewProc("GetCalendarInfoEx")
)

// lpLocaleName (LPCWSTR optional), Calendar (DWORD), lpReserved (LPCWSTR optional), CalType (DWORD), lpCalData (LPWSTR optional, out), cchData (INT), lpValue (DWORD* optional, out)
r1, _, err := procGetCalendarInfoEx.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpLocaleName))),
	uintptr(Calendar),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpReserved))),
	uintptr(CalType),
	uintptr(lpCalData),
	uintptr(cchData),
	uintptr(lpValue),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetCalendarInfoEx(
  lpLocaleName: PWideChar;   // LPCWSTR optional
  Calendar: DWORD;   // DWORD
  lpReserved: PWideChar;   // LPCWSTR optional
  CalType: DWORD;   // DWORD
  lpCalData: PWideChar;   // LPWSTR optional, out
  cchData: Integer;   // INT
  lpValue: Pointer   // DWORD* optional, out
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetCalendarInfoEx';
result := DllCall("KERNEL32\GetCalendarInfoEx"
    , "WStr", lpLocaleName   ; LPCWSTR optional
    , "UInt", Calendar   ; DWORD
    , "WStr", lpReserved   ; LPCWSTR optional
    , "UInt", CalType   ; DWORD
    , "Ptr", lpCalData   ; LPWSTR optional, out
    , "Int", cchData   ; INT
    , "Ptr", lpValue   ; DWORD* optional, out
    , "Int")   ; return: INT
●GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue) = DLL("KERNEL32.dll", "int GetCalendarInfoEx(char*, dword, char*, dword, char*, int, void*)")
# 呼び出し: GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue)
# lpLocaleName : LPCWSTR optional -> "char*"
# Calendar : DWORD -> "dword"
# lpReserved : LPCWSTR optional -> "char*"
# CalType : DWORD -> "dword"
# lpCalData : LPWSTR optional, out -> "char*"
# cchData : INT -> "int"
# lpValue : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn GetCalendarInfoEx(
    lpLocaleName: [*c]const u16, // LPCWSTR optional
    Calendar: u32, // DWORD
    lpReserved: [*c]const u16, // LPCWSTR optional
    CalType: u32, // DWORD
    lpCalData: [*c]u16, // LPWSTR optional, out
    cchData: i32, // INT
    lpValue: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc GetCalendarInfoEx(
    lpLocaleName: WideCString,  # LPCWSTR optional
    Calendar: uint32,  # DWORD
    lpReserved: WideCString,  # LPCWSTR optional
    CalType: uint32,  # DWORD
    lpCalData: ptr uint16,  # LPWSTR optional, out
    cchData: int32,  # INT
    lpValue: ptr uint32  # DWORD* optional, out
): int32 {.importc: "GetCalendarInfoEx", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int GetCalendarInfoEx(
    const(wchar)* lpLocaleName,   // LPCWSTR optional
    uint Calendar,   // DWORD
    const(wchar)* lpReserved,   // LPCWSTR optional
    uint CalType,   // DWORD
    wchar* lpCalData,   // LPWSTR optional, out
    int cchData,   // INT
    uint* lpValue   // DWORD* optional, out
);
ccall((:GetCalendarInfoEx, "KERNEL32.dll"), stdcall, Int32,
      (Cwstring, UInt32, Cwstring, UInt32, Ptr{UInt16}, Int32, Ptr{UInt32}),
      lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue)
# lpLocaleName : LPCWSTR optional -> Cwstring
# Calendar : DWORD -> UInt32
# lpReserved : LPCWSTR optional -> Cwstring
# CalType : DWORD -> UInt32
# lpCalData : LPWSTR optional, out -> Ptr{UInt16}
# cchData : INT -> Int32
# lpValue : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetCalendarInfoEx(
    const uint16_t* lpLocaleName,
    uint32_t Calendar,
    const uint16_t* lpReserved,
    uint32_t CalType,
    uint16_t* lpCalData,
    int32_t cchData,
    uint32_t* lpValue);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue)
-- lpLocaleName : LPCWSTR optional
-- Calendar : DWORD
-- lpReserved : LPCWSTR optional
-- CalType : DWORD
-- lpCalData : LPWSTR optional, out
-- cchData : INT
-- lpValue : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetCalendarInfoEx = lib.func('__stdcall', 'GetCalendarInfoEx', 'int32_t', ['str16', 'uint32_t', 'str16', 'uint32_t', 'uint16_t *', 'int32_t', 'uint32_t *']);
// GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue)
// lpLocaleName : LPCWSTR optional -> 'str16'
// Calendar : DWORD -> 'uint32_t'
// lpReserved : LPCWSTR optional -> 'str16'
// CalType : DWORD -> 'uint32_t'
// lpCalData : LPWSTR optional, out -> 'uint16_t *'
// cchData : INT -> 'int32_t'
// lpValue : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  GetCalendarInfoEx: { parameters: ["buffer", "u32", "buffer", "u32", "buffer", "i32", "pointer"], result: "i32" },
});
// lib.symbols.GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue)
// lpLocaleName : LPCWSTR optional -> "buffer"
// Calendar : DWORD -> "u32"
// lpReserved : LPCWSTR optional -> "buffer"
// CalType : DWORD -> "u32"
// lpCalData : LPWSTR optional, out -> "buffer"
// cchData : INT -> "i32"
// lpValue : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetCalendarInfoEx(
    const uint16_t* lpLocaleName,
    uint32_t Calendar,
    const uint16_t* lpReserved,
    uint32_t CalType,
    uint16_t* lpCalData,
    int32_t cchData,
    uint32_t* lpValue);
C, "KERNEL32.dll");
// $ffi->GetCalendarInfoEx(lpLocaleName, Calendar, lpReserved, CalType, lpCalData, cchData, lpValue);
// lpLocaleName : LPCWSTR optional
// Calendar : DWORD
// lpReserved : LPCWSTR optional
// CalType : DWORD
// lpCalData : LPWSTR optional, out
// cchData : INT
// lpValue : DWORD* optional, out
// 構造体/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 GetCalendarInfoEx(
        WString lpLocaleName,   // LPCWSTR optional
        int Calendar,   // DWORD
        WString lpReserved,   // LPCWSTR optional
        int CalType,   // DWORD
        char[] lpCalData,   // LPWSTR optional, out
        int cchData,   // INT
        IntByReference lpValue   // DWORD* optional, out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun GetCalendarInfoEx = GetCalendarInfoEx(
    lpLocaleName : UInt16*,   # LPCWSTR optional
    Calendar : UInt32,   # DWORD
    lpReserved : UInt16*,   # LPCWSTR optional
    CalType : UInt32,   # DWORD
    lpCalData : UInt16*,   # LPWSTR optional, out
    cchData : Int32,   # INT
    lpValue : UInt32*   # DWORD* optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetCalendarInfoExNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>, Uint32, Pointer<Utf16>, Int32, Pointer<Uint32>);
typedef GetCalendarInfoExDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, int, Pointer<Utf16>, int, Pointer<Uint32>);
final GetCalendarInfoEx = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetCalendarInfoExNative, GetCalendarInfoExDart>('GetCalendarInfoEx');
// lpLocaleName : LPCWSTR optional -> Pointer<Utf16>
// Calendar : DWORD -> Uint32
// lpReserved : LPCWSTR optional -> Pointer<Utf16>
// CalType : DWORD -> Uint32
// lpCalData : LPWSTR optional, out -> Pointer<Utf16>
// cchData : INT -> Int32
// lpValue : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetCalendarInfoEx(
  lpLocaleName: PWideChar;   // LPCWSTR optional
  Calendar: DWORD;   // DWORD
  lpReserved: PWideChar;   // LPCWSTR optional
  CalType: DWORD;   // DWORD
  lpCalData: PWideChar;   // LPWSTR optional, out
  cchData: Integer;   // INT
  lpValue: Pointer   // DWORD* optional, out
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetCalendarInfoEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetCalendarInfoEx"
  c_GetCalendarInfoEx :: CWString -> Word32 -> CWString -> Word32 -> CWString -> Int32 -> Ptr Word32 -> IO Int32
-- lpLocaleName : LPCWSTR optional -> CWString
-- Calendar : DWORD -> Word32
-- lpReserved : LPCWSTR optional -> CWString
-- CalType : DWORD -> Word32
-- lpCalData : LPWSTR optional, out -> CWString
-- cchData : INT -> Int32
-- lpValue : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getcalendarinfoex =
  foreign "GetCalendarInfoEx"
    ((ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> int32_t @-> (ptr uint32_t) @-> returning int32_t)
(* lpLocaleName : LPCWSTR optional -> (ptr uint16_t) *)
(* Calendar : DWORD -> uint32_t *)
(* lpReserved : LPCWSTR optional -> (ptr uint16_t) *)
(* CalType : DWORD -> uint32_t *)
(* lpCalData : LPWSTR optional, out -> (ptr uint16_t) *)
(* cchData : INT -> int32_t *)
(* lpValue : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("GetCalendarInfoEx" get-calendar-info-ex :convention :stdcall) :int32
  (lp-locale-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (calendar :uint32)   ; DWORD
  (lp-reserved (:string :encoding :utf-16le))   ; LPCWSTR optional
  (cal-type :uint32)   ; DWORD
  (lp-cal-data :pointer)   ; LPWSTR optional, out
  (cch-data :int32)   ; INT
  (lp-value :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetCalendarInfoEx = Win32::API::More->new('KERNEL32',
    'int GetCalendarInfoEx(LPCWSTR lpLocaleName, DWORD Calendar, LPCWSTR lpReserved, DWORD CalType, LPWSTR lpCalData, int cchData, LPVOID lpValue)');
# my $ret = $GetCalendarInfoEx->Call($lpLocaleName, $Calendar, $lpReserved, $CalType, $lpCalData, $cchData, $lpValue);
# lpLocaleName : LPCWSTR optional -> LPCWSTR
# Calendar : DWORD -> DWORD
# lpReserved : LPCWSTR optional -> LPCWSTR
# CalType : DWORD -> DWORD
# lpCalData : LPWSTR optional, out -> LPWSTR
# cchData : INT -> int
# lpValue : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
公式の関連項目