Win32 API 日本語リファレンス
ホームSystem.Time › GetTimeZoneInformationForYear

GetTimeZoneInformationForYear

関数
指定した年に対応するタイムゾーン情報を取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL GetTimeZoneInformationForYear(
    WORD wYear,
    DYNAMIC_TIME_ZONE_INFORMATION* pdtzi,   // optional
    TIME_ZONE_INFORMATION* ptzi
);

パラメーター

名前方向
wYearWORDin
pdtziDYNAMIC_TIME_ZONE_INFORMATION*inoptional
ptziTIME_ZONE_INFORMATION*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetTimeZoneInformationForYear(
    WORD wYear,
    DYNAMIC_TIME_ZONE_INFORMATION* pdtzi,   // optional
    TIME_ZONE_INFORMATION* ptzi
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetTimeZoneInformationForYear(
    ushort wYear,   // WORD
    IntPtr pdtzi,   // DYNAMIC_TIME_ZONE_INFORMATION* optional
    IntPtr ptzi   // TIME_ZONE_INFORMATION* out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetTimeZoneInformationForYear(
    wYear As UShort,   ' WORD
    pdtzi As IntPtr,   ' DYNAMIC_TIME_ZONE_INFORMATION* optional
    ptzi As IntPtr   ' TIME_ZONE_INFORMATION* out
) As Boolean
End Function
' wYear : WORD
' pdtzi : DYNAMIC_TIME_ZONE_INFORMATION* optional
' ptzi : TIME_ZONE_INFORMATION* out
Declare PtrSafe Function GetTimeZoneInformationForYear Lib "kernel32" ( _
    ByVal wYear As Integer, _
    ByVal pdtzi As LongPtr, _
    ByVal ptzi As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetTimeZoneInformationForYear = ctypes.windll.kernel32.GetTimeZoneInformationForYear
GetTimeZoneInformationForYear.restype = wintypes.BOOL
GetTimeZoneInformationForYear.argtypes = [
    ctypes.c_ushort,  # wYear : WORD
    ctypes.c_void_p,  # pdtzi : DYNAMIC_TIME_ZONE_INFORMATION* optional
    ctypes.c_void_p,  # ptzi : TIME_ZONE_INFORMATION* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetTimeZoneInformationForYear = Fiddle::Function.new(
  lib['GetTimeZoneInformationForYear'],
  [
    -Fiddle::TYPE_SHORT,  # wYear : WORD
    Fiddle::TYPE_VOIDP,  # pdtzi : DYNAMIC_TIME_ZONE_INFORMATION* optional
    Fiddle::TYPE_VOIDP,  # ptzi : TIME_ZONE_INFORMATION* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetTimeZoneInformationForYear(
        wYear: u16,  // WORD
        pdtzi: *mut DYNAMIC_TIME_ZONE_INFORMATION,  // DYNAMIC_TIME_ZONE_INFORMATION* optional
        ptzi: *mut TIME_ZONE_INFORMATION  // TIME_ZONE_INFORMATION* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool GetTimeZoneInformationForYear(ushort wYear, IntPtr pdtzi, IntPtr ptzi);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetTimeZoneInformationForYear' -Namespace Win32 -PassThru
# $api::GetTimeZoneInformationForYear(wYear, pdtzi, ptzi)
#uselib "KERNEL32.dll"
#func global GetTimeZoneInformationForYear "GetTimeZoneInformationForYear" sptr, sptr, sptr
; GetTimeZoneInformationForYear wYear, varptr(pdtzi), varptr(ptzi)   ; 戻り値は stat
; wYear : WORD -> "sptr"
; pdtzi : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "sptr"
; ptzi : TIME_ZONE_INFORMATION* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetTimeZoneInformationForYear "GetTimeZoneInformationForYear" int, var, var
; res = GetTimeZoneInformationForYear(wYear, pdtzi, ptzi)
; wYear : WORD -> "int"
; pdtzi : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "var"
; ptzi : TIME_ZONE_INFORMATION* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetTimeZoneInformationForYear(WORD wYear, DYNAMIC_TIME_ZONE_INFORMATION* pdtzi, TIME_ZONE_INFORMATION* ptzi)
#uselib "KERNEL32.dll"
#cfunc global GetTimeZoneInformationForYear "GetTimeZoneInformationForYear" int, var, var
; res = GetTimeZoneInformationForYear(wYear, pdtzi, ptzi)
; wYear : WORD -> "int"
; pdtzi : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "var"
; ptzi : TIME_ZONE_INFORMATION* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetTimeZoneInformationForYear = kernel32.NewProc("GetTimeZoneInformationForYear")
)

// wYear (WORD), pdtzi (DYNAMIC_TIME_ZONE_INFORMATION* optional), ptzi (TIME_ZONE_INFORMATION* out)
r1, _, err := procGetTimeZoneInformationForYear.Call(
	uintptr(wYear),
	uintptr(pdtzi),
	uintptr(ptzi),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetTimeZoneInformationForYear(
  wYear: Word;   // WORD
  pdtzi: Pointer;   // DYNAMIC_TIME_ZONE_INFORMATION* optional
  ptzi: Pointer   // TIME_ZONE_INFORMATION* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'GetTimeZoneInformationForYear';
result := DllCall("KERNEL32\GetTimeZoneInformationForYear"
    , "UShort", wYear   ; WORD
    , "Ptr", pdtzi   ; DYNAMIC_TIME_ZONE_INFORMATION* optional
    , "Ptr", ptzi   ; TIME_ZONE_INFORMATION* out
    , "Int")   ; return: BOOL
●GetTimeZoneInformationForYear(wYear, pdtzi, ptzi) = DLL("KERNEL32.dll", "bool GetTimeZoneInformationForYear(int, void*, void*)")
# 呼び出し: GetTimeZoneInformationForYear(wYear, pdtzi, ptzi)
# wYear : WORD -> "int"
# pdtzi : DYNAMIC_TIME_ZONE_INFORMATION* optional -> "void*"
# ptzi : TIME_ZONE_INFORMATION* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。