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

GetLocaleInfoEx

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

シグネチャ

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

INT GetLocaleInfoEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD LCType,
    LPWSTR lpLCData,   // optional
    INT cchData
);

パラメーター

名前方向
lpLocaleNameLPCWSTRinoptional
LCTypeDWORDin
lpLCDataLPWSTRoutoptional
cchDataINTin

戻り値の型: INT

各言語での呼び出し定義

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

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

GetLocaleInfoEx = ctypes.windll.kernel32.GetLocaleInfoEx
GetLocaleInfoEx.restype = ctypes.c_int
GetLocaleInfoEx.argtypes = [
    wintypes.LPCWSTR,  # lpLocaleName : LPCWSTR optional
    wintypes.DWORD,  # LCType : DWORD
    wintypes.LPWSTR,  # lpLCData : LPWSTR optional, out
    ctypes.c_int,  # cchData : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetLocaleInfoEx = kernel32.NewProc("GetLocaleInfoEx")
)

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