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

uloc_getCountry

関数
ロケールIDから国・地域コードを取り出す。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

INT uloc_getCountry(
    LPCSTR localeID,
    LPSTR country,
    INT countryCapacity,
    UErrorCode* err
);

パラメーター

名前方向
localeIDLPCSTRin
countryLPSTRin
countryCapacityINTin
errUErrorCode*inout

戻り値の型: INT

各言語での呼び出し定義

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

INT uloc_getCountry(
    LPCSTR localeID,
    LPSTR country,
    INT countryCapacity,
    UErrorCode* err
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int uloc_getCountry(
    [MarshalAs(UnmanagedType.LPStr)] string localeID,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string country,   // LPSTR
    int countryCapacity,   // INT
    ref int err   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function uloc_getCountry(
    <MarshalAs(UnmanagedType.LPStr)> localeID As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> country As String,   ' LPSTR
    countryCapacity As Integer,   ' INT
    ByRef err As Integer   ' UErrorCode* in/out
) As Integer
End Function
' localeID : LPCSTR
' country : LPSTR
' countryCapacity : INT
' err : UErrorCode* in/out
Declare PtrSafe Function uloc_getCountry Lib "icuuc" ( _
    ByVal localeID As String, _
    ByVal country As String, _
    ByVal countryCapacity As Long, _
    ByRef err As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

uloc_getCountry = ctypes.cdll.icuuc.uloc_getCountry
uloc_getCountry.restype = ctypes.c_int
uloc_getCountry.argtypes = [
    wintypes.LPCSTR,  # localeID : LPCSTR
    wintypes.LPCSTR,  # country : LPSTR
    ctypes.c_int,  # countryCapacity : INT
    ctypes.c_void_p,  # err : UErrorCode* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
uloc_getCountry = Fiddle::Function.new(
  lib['uloc_getCountry'],
  [
    Fiddle::TYPE_VOIDP,  # localeID : LPCSTR
    Fiddle::TYPE_VOIDP,  # country : LPSTR
    Fiddle::TYPE_INT,  # countryCapacity : INT
    Fiddle::TYPE_VOIDP,  # err : UErrorCode* in/out
  ],
  Fiddle::TYPE_INT, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn uloc_getCountry(
        localeID: *const u8,  // LPCSTR
        country: *mut u8,  // LPSTR
        countryCapacity: i32,  // INT
        err: *mut i32  // UErrorCode* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int uloc_getCountry([MarshalAs(UnmanagedType.LPStr)] string localeID, [MarshalAs(UnmanagedType.LPStr)] string country, int countryCapacity, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_uloc_getCountry' -Namespace Win32 -PassThru
# $api::uloc_getCountry(localeID, country, countryCapacity, err)
#uselib "icuuc.dll"
#func global uloc_getCountry "uloc_getCountry" sptr, sptr, sptr, sptr
; uloc_getCountry localeID, country, countryCapacity, err   ; 戻り値は stat
; localeID : LPCSTR -> "sptr"
; country : LPSTR -> "sptr"
; countryCapacity : INT -> "sptr"
; err : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "icuuc.dll"
#cfunc global uloc_getCountry "uloc_getCountry" str, str, int, int
; res = uloc_getCountry(localeID, country, countryCapacity, err)
; localeID : LPCSTR -> "str"
; country : LPSTR -> "str"
; countryCapacity : INT -> "int"
; err : UErrorCode* in/out -> "int"
; INT uloc_getCountry(LPCSTR localeID, LPSTR country, INT countryCapacity, UErrorCode* err)
#uselib "icuuc.dll"
#cfunc global uloc_getCountry "uloc_getCountry" str, str, int, int
; res = uloc_getCountry(localeID, country, countryCapacity, err)
; localeID : LPCSTR -> "str"
; country : LPSTR -> "str"
; countryCapacity : INT -> "int"
; err : UErrorCode* in/out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	proculoc_getCountry = icuuc.NewProc("uloc_getCountry")
)

// localeID (LPCSTR), country (LPSTR), countryCapacity (INT), err (UErrorCode* in/out)
r1, _, err := proculoc_getCountry.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(localeID))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(country))),
	uintptr(countryCapacity),
	uintptr(err),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function uloc_getCountry(
  localeID: PAnsiChar;   // LPCSTR
  country: PAnsiChar;   // LPSTR
  countryCapacity: Integer;   // INT
  err: Pointer   // UErrorCode* in/out
): Integer; cdecl;
  external 'icuuc.dll' name 'uloc_getCountry';
result := DllCall("icuuc\uloc_getCountry"
    , "AStr", localeID   ; LPCSTR
    , "AStr", country   ; LPSTR
    , "Int", countryCapacity   ; INT
    , "Ptr", err   ; UErrorCode* in/out
    , "Cdecl Int")   ; return: INT
●uloc_getCountry(localeID, country, countryCapacity, err) = DLL("icuuc.dll", "int uloc_getCountry(char*, char*, int, void*)")
# 呼び出し: uloc_getCountry(localeID, country, countryCapacity, err)
# localeID : LPCSTR -> "char*"
# country : LPSTR -> "char*"
# countryCapacity : INT -> "int"
# err : UErrorCode* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。