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

SetCalendarInfoW

関数
指定ロケールと暦のカレンダー情報を設定する。Unicode版。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetCalendarInfoW(
    DWORD Locale,
    DWORD Calendar,
    DWORD CalType,
    LPCWSTR lpCalData
);

パラメーター

名前方向
LocaleDWORDin
CalendarDWORDin
CalTypeDWORDin
lpCalDataLPCWSTRin

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetCalendarInfoW(
    DWORD Locale,
    DWORD Calendar,
    DWORD CalType,
    LPCWSTR lpCalData
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetCalendarInfoW(
    uint Locale,   // DWORD
    uint Calendar,   // DWORD
    uint CalType,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpCalData   // LPCWSTR
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetCalendarInfoW(
    Locale As UInteger,   ' DWORD
    Calendar As UInteger,   ' DWORD
    CalType As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpCalData As String   ' LPCWSTR
) As Boolean
End Function
' Locale : DWORD
' Calendar : DWORD
' CalType : DWORD
' lpCalData : LPCWSTR
Declare PtrSafe Function SetCalendarInfoW Lib "kernel32" ( _
    ByVal Locale As Long, _
    ByVal Calendar As Long, _
    ByVal CalType As Long, _
    ByVal lpCalData As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetCalendarInfoW = ctypes.windll.kernel32.SetCalendarInfoW
SetCalendarInfoW.restype = wintypes.BOOL
SetCalendarInfoW.argtypes = [
    wintypes.DWORD,  # Locale : DWORD
    wintypes.DWORD,  # Calendar : DWORD
    wintypes.DWORD,  # CalType : DWORD
    wintypes.LPCWSTR,  # lpCalData : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetCalendarInfoW = Fiddle::Function.new(
  lib['SetCalendarInfoW'],
  [
    -Fiddle::TYPE_INT,  # Locale : DWORD
    -Fiddle::TYPE_INT,  # Calendar : DWORD
    -Fiddle::TYPE_INT,  # CalType : DWORD
    Fiddle::TYPE_VOIDP,  # lpCalData : LPCWSTR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn SetCalendarInfoW(
        Locale: u32,  // DWORD
        Calendar: u32,  // DWORD
        CalType: u32,  // DWORD
        lpCalData: *const u16  // LPCWSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetCalendarInfoW(uint Locale, uint Calendar, uint CalType, [MarshalAs(UnmanagedType.LPWStr)] string lpCalData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetCalendarInfoW' -Namespace Win32 -PassThru
# $api::SetCalendarInfoW(Locale, Calendar, CalType, lpCalData)
#uselib "KERNEL32.dll"
#func global SetCalendarInfoW "SetCalendarInfoW" wptr, wptr, wptr, wptr
; SetCalendarInfoW Locale, Calendar, CalType, lpCalData   ; 戻り値は stat
; Locale : DWORD -> "wptr"
; Calendar : DWORD -> "wptr"
; CalType : DWORD -> "wptr"
; lpCalData : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetCalendarInfoW "SetCalendarInfoW" int, int, int, wstr
; res = SetCalendarInfoW(Locale, Calendar, CalType, lpCalData)
; Locale : DWORD -> "int"
; Calendar : DWORD -> "int"
; CalType : DWORD -> "int"
; lpCalData : LPCWSTR -> "wstr"
; BOOL SetCalendarInfoW(DWORD Locale, DWORD Calendar, DWORD CalType, LPCWSTR lpCalData)
#uselib "KERNEL32.dll"
#cfunc global SetCalendarInfoW "SetCalendarInfoW" int, int, int, wstr
; res = SetCalendarInfoW(Locale, Calendar, CalType, lpCalData)
; Locale : DWORD -> "int"
; Calendar : DWORD -> "int"
; CalType : DWORD -> "int"
; lpCalData : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetCalendarInfoW = kernel32.NewProc("SetCalendarInfoW")
)

// Locale (DWORD), Calendar (DWORD), CalType (DWORD), lpCalData (LPCWSTR)
r1, _, err := procSetCalendarInfoW.Call(
	uintptr(Locale),
	uintptr(Calendar),
	uintptr(CalType),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpCalData))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetCalendarInfoW(
  Locale: DWORD;   // DWORD
  Calendar: DWORD;   // DWORD
  CalType: DWORD;   // DWORD
  lpCalData: PWideChar   // LPCWSTR
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetCalendarInfoW';
result := DllCall("KERNEL32\SetCalendarInfoW"
    , "UInt", Locale   ; DWORD
    , "UInt", Calendar   ; DWORD
    , "UInt", CalType   ; DWORD
    , "WStr", lpCalData   ; LPCWSTR
    , "Int")   ; return: BOOL
●SetCalendarInfoW(Locale, Calendar, CalType, lpCalData) = DLL("KERNEL32.dll", "bool SetCalendarInfoW(dword, dword, dword, char*)")
# 呼び出し: SetCalendarInfoW(Locale, Calendar, CalType, lpCalData)
# Locale : DWORD -> "dword"
# Calendar : DWORD -> "dword"
# CalType : DWORD -> "dword"
# lpCalData : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。