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

SetLocaleInfoA

関数
ユーザーロケールの項目を設定する。ANSI版。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetLocaleInfoA(
    DWORD Locale,
    DWORD LCType,
    LPCSTR lpLCData
);

パラメーター

名前方向
LocaleDWORDin
LCTypeDWORDin
lpLCDataLPCSTRin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetLocaleInfoA(
    DWORD Locale,
    DWORD LCType,
    LPCSTR lpLCData
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetLocaleInfoA(
    uint Locale,   // DWORD
    uint LCType,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string lpLCData   // LPCSTR
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetLocaleInfoA(
    Locale As UInteger,   ' DWORD
    LCType As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> lpLCData As String   ' LPCSTR
) As Boolean
End Function
' Locale : DWORD
' LCType : DWORD
' lpLCData : LPCSTR
Declare PtrSafe Function SetLocaleInfoA Lib "kernel32" ( _
    ByVal Locale As Long, _
    ByVal LCType As Long, _
    ByVal lpLCData As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetLocaleInfoA = ctypes.windll.kernel32.SetLocaleInfoA
SetLocaleInfoA.restype = wintypes.BOOL
SetLocaleInfoA.argtypes = [
    wintypes.DWORD,  # Locale : DWORD
    wintypes.DWORD,  # LCType : DWORD
    wintypes.LPCSTR,  # lpLCData : LPCSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetLocaleInfoA = Fiddle::Function.new(
  lib['SetLocaleInfoA'],
  [
    -Fiddle::TYPE_INT,  # Locale : DWORD
    -Fiddle::TYPE_INT,  # LCType : DWORD
    Fiddle::TYPE_VOIDP,  # lpLCData : LPCSTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetLocaleInfoA(
        Locale: u32,  // DWORD
        LCType: u32,  // DWORD
        lpLCData: *const u8  // LPCSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetLocaleInfoA(uint Locale, uint LCType, [MarshalAs(UnmanagedType.LPStr)] string lpLCData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetLocaleInfoA' -Namespace Win32 -PassThru
# $api::SetLocaleInfoA(Locale, LCType, lpLCData)
#uselib "KERNEL32.dll"
#func global SetLocaleInfoA "SetLocaleInfoA" sptr, sptr, sptr
; SetLocaleInfoA Locale, LCType, lpLCData   ; 戻り値は stat
; Locale : DWORD -> "sptr"
; LCType : DWORD -> "sptr"
; lpLCData : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetLocaleInfoA "SetLocaleInfoA" int, int, str
; res = SetLocaleInfoA(Locale, LCType, lpLCData)
; Locale : DWORD -> "int"
; LCType : DWORD -> "int"
; lpLCData : LPCSTR -> "str"
; BOOL SetLocaleInfoA(DWORD Locale, DWORD LCType, LPCSTR lpLCData)
#uselib "KERNEL32.dll"
#cfunc global SetLocaleInfoA "SetLocaleInfoA" int, int, str
; res = SetLocaleInfoA(Locale, LCType, lpLCData)
; Locale : DWORD -> "int"
; LCType : DWORD -> "int"
; lpLCData : LPCSTR -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetLocaleInfoA = kernel32.NewProc("SetLocaleInfoA")
)

// Locale (DWORD), LCType (DWORD), lpLCData (LPCSTR)
r1, _, err := procSetLocaleInfoA.Call(
	uintptr(Locale),
	uintptr(LCType),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpLCData))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetLocaleInfoA(
  Locale: DWORD;   // DWORD
  LCType: DWORD;   // DWORD
  lpLCData: PAnsiChar   // LPCSTR
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetLocaleInfoA';
result := DllCall("KERNEL32\SetLocaleInfoA"
    , "UInt", Locale   ; DWORD
    , "UInt", LCType   ; DWORD
    , "AStr", lpLCData   ; LPCSTR
    , "Int")   ; return: BOOL
●SetLocaleInfoA(Locale, LCType, lpLCData) = DLL("KERNEL32.dll", "bool SetLocaleInfoA(dword, dword, char*)")
# 呼び出し: SetLocaleInfoA(Locale, LCType, lpLCData)
# Locale : DWORD -> "dword"
# LCType : DWORD -> "dword"
# lpLCData : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。