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

uloc_toLanguageTag

関数
ICUロケールIDをBCP47言語タグに変換する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

INT uloc_toLanguageTag(
    LPCSTR localeID,
    LPSTR langtag,
    INT langtagCapacity,
    CHAR strict,
    UErrorCode* err
);

パラメーター

名前方向
localeIDLPCSTRin
langtagLPSTRin
langtagCapacityINTin
strictCHARin
errUErrorCode*inout

戻り値の型: INT

各言語での呼び出し定義

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

INT uloc_toLanguageTag(
    LPCSTR localeID,
    LPSTR langtag,
    INT langtagCapacity,
    CHAR strict,
    UErrorCode* err
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int uloc_toLanguageTag(
    [MarshalAs(UnmanagedType.LPStr)] string localeID,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string langtag,   // LPSTR
    int langtagCapacity,   // INT
    sbyte strict,   // CHAR
    ref int err   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function uloc_toLanguageTag(
    <MarshalAs(UnmanagedType.LPStr)> localeID As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> langtag As String,   ' LPSTR
    langtagCapacity As Integer,   ' INT
    strict As SByte,   ' CHAR
    ByRef err As Integer   ' UErrorCode* in/out
) As Integer
End Function
' localeID : LPCSTR
' langtag : LPSTR
' langtagCapacity : INT
' strict : CHAR
' err : UErrorCode* in/out
Declare PtrSafe Function uloc_toLanguageTag Lib "icuuc" ( _
    ByVal localeID As String, _
    ByVal langtag As String, _
    ByVal langtagCapacity As Long, _
    ByVal strict As Byte, _
    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_toLanguageTag = ctypes.cdll.icuuc.uloc_toLanguageTag
uloc_toLanguageTag.restype = ctypes.c_int
uloc_toLanguageTag.argtypes = [
    wintypes.LPCSTR,  # localeID : LPCSTR
    wintypes.LPCSTR,  # langtag : LPSTR
    ctypes.c_int,  # langtagCapacity : INT
    ctypes.c_byte,  # strict : CHAR
    ctypes.c_void_p,  # err : UErrorCode* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
uloc_toLanguageTag = Fiddle::Function.new(
  lib['uloc_toLanguageTag'],
  [
    Fiddle::TYPE_VOIDP,  # localeID : LPCSTR
    Fiddle::TYPE_VOIDP,  # langtag : LPSTR
    Fiddle::TYPE_INT,  # langtagCapacity : INT
    Fiddle::TYPE_CHAR,  # strict : CHAR
    Fiddle::TYPE_VOIDP,  # err : UErrorCode* in/out
  ],
  Fiddle::TYPE_INT, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn uloc_toLanguageTag(
        localeID: *const u8,  // LPCSTR
        langtag: *mut u8,  // LPSTR
        langtagCapacity: i32,  // INT
        strict: i8,  // CHAR
        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_toLanguageTag([MarshalAs(UnmanagedType.LPStr)] string localeID, [MarshalAs(UnmanagedType.LPStr)] string langtag, int langtagCapacity, sbyte strict, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_uloc_toLanguageTag' -Namespace Win32 -PassThru
# $api::uloc_toLanguageTag(localeID, langtag, langtagCapacity, strict, err)
#uselib "icuuc.dll"
#func global uloc_toLanguageTag "uloc_toLanguageTag" sptr, sptr, sptr, sptr, sptr
; uloc_toLanguageTag localeID, langtag, langtagCapacity, strict, err   ; 戻り値は stat
; localeID : LPCSTR -> "sptr"
; langtag : LPSTR -> "sptr"
; langtagCapacity : INT -> "sptr"
; strict : CHAR -> "sptr"
; err : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "icuuc.dll"
#cfunc global uloc_toLanguageTag "uloc_toLanguageTag" str, str, int, int, int
; res = uloc_toLanguageTag(localeID, langtag, langtagCapacity, strict, err)
; localeID : LPCSTR -> "str"
; langtag : LPSTR -> "str"
; langtagCapacity : INT -> "int"
; strict : CHAR -> "int"
; err : UErrorCode* in/out -> "int"
; INT uloc_toLanguageTag(LPCSTR localeID, LPSTR langtag, INT langtagCapacity, CHAR strict, UErrorCode* err)
#uselib "icuuc.dll"
#cfunc global uloc_toLanguageTag "uloc_toLanguageTag" str, str, int, int, int
; res = uloc_toLanguageTag(localeID, langtag, langtagCapacity, strict, err)
; localeID : LPCSTR -> "str"
; langtag : LPSTR -> "str"
; langtagCapacity : INT -> "int"
; strict : CHAR -> "int"
; err : UErrorCode* in/out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	proculoc_toLanguageTag = icuuc.NewProc("uloc_toLanguageTag")
)

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