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

GetLocaleInfoA

関数
指定ロケールの各種情報を取得する。ANSI版。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

INT GetLocaleInfoA(
    DWORD Locale,
    DWORD LCType,
    LPSTR lpLCData,   // optional
    INT cchData
);

パラメーター

名前方向
LocaleDWORDin
LCTypeDWORDin
lpLCDataLPSTRoutoptional
cchDataINTin

戻り値の型: INT

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetLocaleInfoA = kernel32.NewProc("GetLocaleInfoA")
)

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