ホーム › Globalization › uscript_getCode
uscript_getCode
関数スクリプト名や略称・ロケールからスクリプトコードを取得する。
シグネチャ
// icuuc.dll
#include <windows.h>
INT uscript_getCode(
LPCSTR nameOrAbbrOrLocale,
UScriptCode* fillIn,
INT capacity,
UErrorCode* err
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| nameOrAbbrOrLocale | LPCSTR | in | スクリプトの名前・略称、またはロケールID文字列。これに対応するスクリプトコードを取得する。 |
| fillIn | UScriptCode* | inout | 取得したUScriptCode値を格納する出力配列。NULL可(容量取得時など)。 |
| capacity | INT | in | fillIn配列の要素数(容量)。0なら所要数のみを返す。 |
| err | UErrorCode* | inout | ICUエラーコードを受け渡すポインタ。呼び出し前にU_ZERO_ERRORへ初期化する必要がある。 |
戻り値の型: INT
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
INT uscript_getCode(
LPCSTR nameOrAbbrOrLocale,
UScriptCode* fillIn,
INT capacity,
UErrorCode* err
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int uscript_getCode(
[MarshalAs(UnmanagedType.LPStr)] string nameOrAbbrOrLocale, // LPCSTR
ref int fillIn, // UScriptCode* in/out
int capacity, // INT
ref int err // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function uscript_getCode(
<MarshalAs(UnmanagedType.LPStr)> nameOrAbbrOrLocale As String, ' LPCSTR
ByRef fillIn As Integer, ' UScriptCode* in/out
capacity As Integer, ' INT
ByRef err As Integer ' UErrorCode* in/out
) As Integer
End Function' nameOrAbbrOrLocale : LPCSTR
' fillIn : UScriptCode* in/out
' capacity : INT
' err : UErrorCode* in/out
Declare PtrSafe Function uscript_getCode Lib "icuuc" ( _
ByVal nameOrAbbrOrLocale As String, _
ByRef fillIn As Long, _
ByVal capacity 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
uscript_getCode = ctypes.cdll.icuuc.uscript_getCode
uscript_getCode.restype = ctypes.c_int
uscript_getCode.argtypes = [
wintypes.LPCSTR, # nameOrAbbrOrLocale : LPCSTR
ctypes.c_void_p, # fillIn : UScriptCode* in/out
ctypes.c_int, # capacity : INT
ctypes.c_void_p, # err : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
uscript_getCode = Fiddle::Function.new(
lib['uscript_getCode'],
[
Fiddle::TYPE_VOIDP, # nameOrAbbrOrLocale : LPCSTR
Fiddle::TYPE_VOIDP, # fillIn : UScriptCode* in/out
Fiddle::TYPE_INT, # capacity : INT
Fiddle::TYPE_VOIDP, # err : UErrorCode* in/out
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn uscript_getCode(
nameOrAbbrOrLocale: *const u8, // LPCSTR
fillIn: *mut i32, // UScriptCode* in/out
capacity: 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 uscript_getCode([MarshalAs(UnmanagedType.LPStr)] string nameOrAbbrOrLocale, ref int fillIn, int capacity, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_uscript_getCode' -Namespace Win32 -PassThru
# $api::uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err)#uselib "icuuc.dll"
#func global uscript_getCode "uscript_getCode" sptr, sptr, sptr, sptr
; uscript_getCode nameOrAbbrOrLocale, varptr(fillIn), capacity, varptr(err) ; 戻り値は stat
; nameOrAbbrOrLocale : LPCSTR -> "sptr"
; fillIn : UScriptCode* in/out -> "sptr"
; capacity : INT -> "sptr"
; err : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global uscript_getCode "uscript_getCode" str, var, int, var ; res = uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err) ; nameOrAbbrOrLocale : LPCSTR -> "str" ; fillIn : UScriptCode* in/out -> "var" ; capacity : INT -> "int" ; err : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global uscript_getCode "uscript_getCode" str, sptr, int, sptr ; res = uscript_getCode(nameOrAbbrOrLocale, varptr(fillIn), capacity, varptr(err)) ; nameOrAbbrOrLocale : LPCSTR -> "str" ; fillIn : UScriptCode* in/out -> "sptr" ; capacity : INT -> "int" ; err : UErrorCode* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT uscript_getCode(LPCSTR nameOrAbbrOrLocale, UScriptCode* fillIn, INT capacity, UErrorCode* err) #uselib "icuuc.dll" #cfunc global uscript_getCode "uscript_getCode" str, var, int, var ; res = uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err) ; nameOrAbbrOrLocale : LPCSTR -> "str" ; fillIn : UScriptCode* in/out -> "var" ; capacity : INT -> "int" ; err : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT uscript_getCode(LPCSTR nameOrAbbrOrLocale, UScriptCode* fillIn, INT capacity, UErrorCode* err) #uselib "icuuc.dll" #cfunc global uscript_getCode "uscript_getCode" str, intptr, int, intptr ; res = uscript_getCode(nameOrAbbrOrLocale, varptr(fillIn), capacity, varptr(err)) ; nameOrAbbrOrLocale : LPCSTR -> "str" ; fillIn : UScriptCode* in/out -> "intptr" ; capacity : INT -> "int" ; err : UErrorCode* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procuscript_getCode = icuuc.NewProc("uscript_getCode")
)
// nameOrAbbrOrLocale (LPCSTR), fillIn (UScriptCode* in/out), capacity (INT), err (UErrorCode* in/out)
r1, _, err := procuscript_getCode.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(nameOrAbbrOrLocale))),
uintptr(fillIn),
uintptr(capacity),
uintptr(err),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction uscript_getCode(
nameOrAbbrOrLocale: PAnsiChar; // LPCSTR
fillIn: Pointer; // UScriptCode* in/out
capacity: Integer; // INT
err: Pointer // UErrorCode* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'uscript_getCode';result := DllCall("icuuc\uscript_getCode"
, "AStr", nameOrAbbrOrLocale ; LPCSTR
, "Ptr", fillIn ; UScriptCode* in/out
, "Int", capacity ; INT
, "Ptr", err ; UErrorCode* in/out
, "Cdecl Int") ; return: INT●uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err) = DLL("icuuc.dll", "int uscript_getCode(char*, void*, int, void*)")
# 呼び出し: uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err)
# nameOrAbbrOrLocale : LPCSTR -> "char*"
# fillIn : UScriptCode* in/out -> "void*"
# capacity : INT -> "int"
# err : UErrorCode* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "icuuc" fn uscript_getCode(
nameOrAbbrOrLocale: [*c]const u8, // LPCSTR
fillIn: [*c]i32, // UScriptCode* in/out
capacity: i32, // INT
err: [*c]i32 // UErrorCode* in/out
) callconv(.c) i32;proc uscript_getCode(
nameOrAbbrOrLocale: cstring, # LPCSTR
fillIn: ptr int32, # UScriptCode* in/out
capacity: int32, # INT
err: ptr int32 # UErrorCode* in/out
): int32 {.importc: "uscript_getCode", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
int uscript_getCode(
const(char)* nameOrAbbrOrLocale, // LPCSTR
int* fillIn, // UScriptCode* in/out
int capacity, // INT
int* err // UErrorCode* in/out
);ccall((:uscript_getCode, "icuuc.dll"), Int32,
(Cstring, Ptr{Int32}, Int32, Ptr{Int32}),
nameOrAbbrOrLocale, fillIn, capacity, err)
# nameOrAbbrOrLocale : LPCSTR -> Cstring
# fillIn : UScriptCode* in/out -> Ptr{Int32}
# capacity : INT -> Int32
# err : UErrorCode* in/out -> Ptr{Int32}local ffi = require("ffi")
ffi.cdef[[
int32_t uscript_getCode(
const char* nameOrAbbrOrLocale,
int32_t* fillIn,
int32_t capacity,
int32_t* err);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err)
-- nameOrAbbrOrLocale : LPCSTR
-- fillIn : UScriptCode* in/out
-- capacity : INT
-- err : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const uscript_getCode = lib.func('__cdecl', 'uscript_getCode', 'int32_t', ['str', 'int32_t *', 'int32_t', 'int32_t *']);
// uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err)
// nameOrAbbrOrLocale : LPCSTR -> 'str'
// fillIn : UScriptCode* in/out -> 'int32_t *'
// capacity : INT -> 'int32_t'
// err : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
uscript_getCode: { parameters: ["buffer", "pointer", "i32", "pointer"], result: "i32" },
});
// lib.symbols.uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err)
// nameOrAbbrOrLocale : LPCSTR -> "buffer"
// fillIn : UScriptCode* in/out -> "pointer"
// capacity : INT -> "i32"
// err : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t uscript_getCode(
const char* nameOrAbbrOrLocale,
int32_t* fillIn,
int32_t capacity,
int32_t* err);
C, "icuuc.dll");
// $ffi->uscript_getCode(nameOrAbbrOrLocale, fillIn, capacity, err);
// nameOrAbbrOrLocale : LPCSTR
// fillIn : UScriptCode* in/out
// capacity : INT
// err : UErrorCode* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Icuuc extends Library {
Icuuc INSTANCE = Native.load("icuuc", Icuuc.class);
int uscript_getCode(
String nameOrAbbrOrLocale, // LPCSTR
IntByReference fillIn, // UScriptCode* in/out
int capacity, // INT
IntByReference err // UErrorCode* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun uscript_getCode = uscript_getCode(
nameOrAbbrOrLocale : UInt8*, # LPCSTR
fillIn : Int32*, # UScriptCode* in/out
capacity : Int32, # INT
err : Int32* # UErrorCode* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef uscript_getCodeNative = Int32 Function(Pointer<Utf8>, Pointer<Int32>, Int32, Pointer<Int32>);
typedef uscript_getCodeDart = int Function(Pointer<Utf8>, Pointer<Int32>, int, Pointer<Int32>);
final uscript_getCode = DynamicLibrary.open('icuuc.dll')
.lookupFunction<uscript_getCodeNative, uscript_getCodeDart>('uscript_getCode');
// nameOrAbbrOrLocale : LPCSTR -> Pointer<Utf8>
// fillIn : UScriptCode* in/out -> Pointer<Int32>
// capacity : INT -> Int32
// err : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function uscript_getCode(
nameOrAbbrOrLocale: PAnsiChar; // LPCSTR
fillIn: Pointer; // UScriptCode* in/out
capacity: Integer; // INT
err: Pointer // UErrorCode* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'uscript_getCode';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "uscript_getCode"
c_uscript_getCode :: CString -> Ptr Int32 -> Int32 -> Ptr Int32 -> IO Int32
-- nameOrAbbrOrLocale : LPCSTR -> CString
-- fillIn : UScriptCode* in/out -> Ptr Int32
-- capacity : INT -> Int32
-- err : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let uscript_getcode =
foreign "uscript_getCode"
(string @-> (ptr int32_t) @-> int32_t @-> (ptr int32_t) @-> returning int32_t)
(* nameOrAbbrOrLocale : LPCSTR -> string *)
(* fillIn : UScriptCode* in/out -> (ptr int32_t) *)
(* capacity : INT -> int32_t *)
(* err : UErrorCode* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)
(cffi:defcfun ("uscript_getCode" uscript-get-code :convention :cdecl) :int32
(name-or-abbr-or-locale :string) ; LPCSTR
(fill-in :pointer) ; UScriptCode* in/out
(capacity :int32) ; INT
(err :pointer)) ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $uscript_getCode = Win32::API::More->new('icuuc',
'int uscript_getCode(LPCSTR nameOrAbbrOrLocale, LPVOID fillIn, int capacity, LPVOID err)');
# my $ret = $uscript_getCode->Call($nameOrAbbrOrLocale, $fillIn, $capacity, $err);
# nameOrAbbrOrLocale : LPCSTR -> LPCSTR
# fillIn : UScriptCode* in/out -> LPVOID
# capacity : INT -> int
# err : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。