ホーム › Globalization › ucnv_fromUChars
ucnv_fromUChars
関数Unicode文字列をバイト列へ一括変換する。
シグネチャ
// icuuc.dll
#include <windows.h>
INT ucnv_fromUChars(
UConverter* cnv,
LPSTR dest,
INT destCapacity,
const WORD* src,
INT srcLength,
UErrorCode* pErrorCode
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| cnv | UConverter* | inout | Unicode→外部符号化変換に用いるコンバーターへのポインタ。 |
| dest | LPSTR | in | 変換結果のバイト列を受け取る出力バッファ。 |
| destCapacity | INT | in | destバッファのバイト容量。 |
| src | WORD* | in | 入力Unicode文字列(UTF-16)へのポインタ。 |
| srcLength | INT | in | srcの長さ。-1でNUL終端を意味する。 |
| pErrorCode | UErrorCode* | inout | エラーコードを入出力するポインタ。事前にU_ZERO_ERRORで初期化する。 |
戻り値の型: INT
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
INT ucnv_fromUChars(
UConverter* cnv,
LPSTR dest,
INT destCapacity,
const WORD* src,
INT srcLength,
UErrorCode* pErrorCode
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int ucnv_fromUChars(
ref IntPtr cnv, // UConverter* in/out
[MarshalAs(UnmanagedType.LPStr)] string dest, // LPSTR
int destCapacity, // INT
ref ushort src, // WORD*
int srcLength, // INT
ref int pErrorCode // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ucnv_fromUChars(
ByRef cnv As IntPtr, ' UConverter* in/out
<MarshalAs(UnmanagedType.LPStr)> dest As String, ' LPSTR
destCapacity As Integer, ' INT
ByRef src As UShort, ' WORD*
srcLength As Integer, ' INT
ByRef pErrorCode As Integer ' UErrorCode* in/out
) As Integer
End Function' cnv : UConverter* in/out
' dest : LPSTR
' destCapacity : INT
' src : WORD*
' srcLength : INT
' pErrorCode : UErrorCode* in/out
Declare PtrSafe Function ucnv_fromUChars Lib "icuuc" ( _
ByRef cnv As LongPtr, _
ByVal dest As String, _
ByVal destCapacity As Long, _
ByRef src As Integer, _
ByVal srcLength As Long, _
ByRef pErrorCode As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ucnv_fromUChars = ctypes.cdll.icuuc.ucnv_fromUChars
ucnv_fromUChars.restype = ctypes.c_int
ucnv_fromUChars.argtypes = [
ctypes.c_void_p, # cnv : UConverter* in/out
wintypes.LPCSTR, # dest : LPSTR
ctypes.c_int, # destCapacity : INT
ctypes.POINTER(ctypes.c_ushort), # src : WORD*
ctypes.c_int, # srcLength : INT
ctypes.c_void_p, # pErrorCode : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
ucnv_fromUChars = Fiddle::Function.new(
lib['ucnv_fromUChars'],
[
Fiddle::TYPE_VOIDP, # cnv : UConverter* in/out
Fiddle::TYPE_VOIDP, # dest : LPSTR
Fiddle::TYPE_INT, # destCapacity : INT
Fiddle::TYPE_VOIDP, # src : WORD*
Fiddle::TYPE_INT, # srcLength : INT
Fiddle::TYPE_VOIDP, # pErrorCode : UErrorCode* in/out
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn ucnv_fromUChars(
cnv: *mut isize, // UConverter* in/out
dest: *mut u8, // LPSTR
destCapacity: i32, // INT
src: *const u16, // WORD*
srcLength: i32, // INT
pErrorCode: *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 ucnv_fromUChars(ref IntPtr cnv, [MarshalAs(UnmanagedType.LPStr)] string dest, int destCapacity, ref ushort src, int srcLength, ref int pErrorCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ucnv_fromUChars' -Namespace Win32 -PassThru
# $api::ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)#uselib "icuuc.dll"
#func global ucnv_fromUChars "ucnv_fromUChars" sptr, sptr, sptr, sptr, sptr, sptr
; ucnv_fromUChars varptr(cnv), dest, destCapacity, varptr(src), srcLength, varptr(pErrorCode) ; 戻り値は stat
; cnv : UConverter* in/out -> "sptr"
; dest : LPSTR -> "sptr"
; destCapacity : INT -> "sptr"
; src : WORD* -> "sptr"
; srcLength : INT -> "sptr"
; pErrorCode : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global ucnv_fromUChars "ucnv_fromUChars" var, str, int, var, int, var ; res = ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode) ; cnv : UConverter* in/out -> "var" ; dest : LPSTR -> "str" ; destCapacity : INT -> "int" ; src : WORD* -> "var" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global ucnv_fromUChars "ucnv_fromUChars" sptr, str, int, sptr, int, sptr ; res = ucnv_fromUChars(varptr(cnv), dest, destCapacity, varptr(src), srcLength, varptr(pErrorCode)) ; cnv : UConverter* in/out -> "sptr" ; dest : LPSTR -> "str" ; destCapacity : INT -> "int" ; src : WORD* -> "sptr" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT ucnv_fromUChars(UConverter* cnv, LPSTR dest, INT destCapacity, WORD* src, INT srcLength, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global ucnv_fromUChars "ucnv_fromUChars" var, str, int, var, int, var ; res = ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode) ; cnv : UConverter* in/out -> "var" ; dest : LPSTR -> "str" ; destCapacity : INT -> "int" ; src : WORD* -> "var" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT ucnv_fromUChars(UConverter* cnv, LPSTR dest, INT destCapacity, WORD* src, INT srcLength, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global ucnv_fromUChars "ucnv_fromUChars" intptr, str, int, intptr, int, intptr ; res = ucnv_fromUChars(varptr(cnv), dest, destCapacity, varptr(src), srcLength, varptr(pErrorCode)) ; cnv : UConverter* in/out -> "intptr" ; dest : LPSTR -> "str" ; destCapacity : INT -> "int" ; src : WORD* -> "intptr" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procucnv_fromUChars = icuuc.NewProc("ucnv_fromUChars")
)
// cnv (UConverter* in/out), dest (LPSTR), destCapacity (INT), src (WORD*), srcLength (INT), pErrorCode (UErrorCode* in/out)
r1, _, err := procucnv_fromUChars.Call(
uintptr(cnv),
uintptr(unsafe.Pointer(windows.BytePtrFromString(dest))),
uintptr(destCapacity),
uintptr(src),
uintptr(srcLength),
uintptr(pErrorCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction ucnv_fromUChars(
cnv: Pointer; // UConverter* in/out
dest: PAnsiChar; // LPSTR
destCapacity: Integer; // INT
src: Pointer; // WORD*
srcLength: Integer; // INT
pErrorCode: Pointer // UErrorCode* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'ucnv_fromUChars';result := DllCall("icuuc\ucnv_fromUChars"
, "Ptr", cnv ; UConverter* in/out
, "AStr", dest ; LPSTR
, "Int", destCapacity ; INT
, "Ptr", src ; WORD*
, "Int", srcLength ; INT
, "Ptr", pErrorCode ; UErrorCode* in/out
, "Cdecl Int") ; return: INT●ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode) = DLL("icuuc.dll", "int ucnv_fromUChars(void*, char*, int, void*, int, void*)")
# 呼び出し: ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
# cnv : UConverter* in/out -> "void*"
# dest : LPSTR -> "char*"
# destCapacity : INT -> "int"
# src : WORD* -> "void*"
# srcLength : INT -> "int"
# pErrorCode : 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 ucnv_fromUChars(
cnv: [*c]isize, // UConverter* in/out
dest: [*c]const u8, // LPSTR
destCapacity: i32, // INT
src: [*c]u16, // WORD*
srcLength: i32, // INT
pErrorCode: [*c]i32 // UErrorCode* in/out
) callconv(.c) i32;proc ucnv_fromUChars(
cnv: ptr int, # UConverter* in/out
dest: cstring, # LPSTR
destCapacity: int32, # INT
src: ptr uint16, # WORD*
srcLength: int32, # INT
pErrorCode: ptr int32 # UErrorCode* in/out
): int32 {.importc: "ucnv_fromUChars", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
int ucnv_fromUChars(
ptrdiff_t* cnv, // UConverter* in/out
const(char)* dest, // LPSTR
int destCapacity, // INT
ushort* src, // WORD*
int srcLength, // INT
int* pErrorCode // UErrorCode* in/out
);ccall((:ucnv_fromUChars, "icuuc.dll"), Int32,
(Ptr{Int}, Cstring, Int32, Ptr{UInt16}, Int32, Ptr{Int32}),
cnv, dest, destCapacity, src, srcLength, pErrorCode)
# cnv : UConverter* in/out -> Ptr{Int}
# dest : LPSTR -> Cstring
# destCapacity : INT -> Int32
# src : WORD* -> Ptr{UInt16}
# srcLength : INT -> Int32
# pErrorCode : UErrorCode* in/out -> Ptr{Int32}local ffi = require("ffi")
ffi.cdef[[
int32_t ucnv_fromUChars(
intptr_t* cnv,
const char* dest,
int32_t destCapacity,
uint16_t* src,
int32_t srcLength,
int32_t* pErrorCode);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
-- cnv : UConverter* in/out
-- dest : LPSTR
-- destCapacity : INT
-- src : WORD*
-- srcLength : INT
-- pErrorCode : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const ucnv_fromUChars = lib.func('__cdecl', 'ucnv_fromUChars', 'int32_t', ['intptr_t *', 'str', 'int32_t', 'uint16_t *', 'int32_t', 'int32_t *']);
// ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
// cnv : UConverter* in/out -> 'intptr_t *'
// dest : LPSTR -> 'str'
// destCapacity : INT -> 'int32_t'
// src : WORD* -> 'uint16_t *'
// srcLength : INT -> 'int32_t'
// pErrorCode : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
ucnv_fromUChars: { parameters: ["pointer", "buffer", "i32", "pointer", "i32", "pointer"], result: "i32" },
});
// lib.symbols.ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
// cnv : UConverter* in/out -> "pointer"
// dest : LPSTR -> "buffer"
// destCapacity : INT -> "i32"
// src : WORD* -> "pointer"
// srcLength : INT -> "i32"
// pErrorCode : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ucnv_fromUChars(
intptr_t* cnv,
const char* dest,
int32_t destCapacity,
uint16_t* src,
int32_t srcLength,
int32_t* pErrorCode);
C, "icuuc.dll");
// $ffi->ucnv_fromUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode);
// cnv : UConverter* in/out
// dest : LPSTR
// destCapacity : INT
// src : WORD*
// srcLength : INT
// pErrorCode : 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 ucnv_fromUChars(
LongByReference cnv, // UConverter* in/out
String dest, // LPSTR
int destCapacity, // INT
ShortByReference src, // WORD*
int srcLength, // INT
IntByReference pErrorCode // UErrorCode* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun ucnv_fromUChars = ucnv_fromUChars(
cnv : LibC::SSizeT*, # UConverter* in/out
dest : UInt8*, # LPSTR
destCapacity : Int32, # INT
src : UInt16*, # WORD*
srcLength : Int32, # INT
pErrorCode : Int32* # UErrorCode* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ucnv_fromUCharsNative = Int32 Function(Pointer<IntPtr>, Pointer<Utf8>, Int32, Pointer<Uint16>, Int32, Pointer<Int32>);
typedef ucnv_fromUCharsDart = int Function(Pointer<IntPtr>, Pointer<Utf8>, int, Pointer<Uint16>, int, Pointer<Int32>);
final ucnv_fromUChars = DynamicLibrary.open('icuuc.dll')
.lookupFunction<ucnv_fromUCharsNative, ucnv_fromUCharsDart>('ucnv_fromUChars');
// cnv : UConverter* in/out -> Pointer<IntPtr>
// dest : LPSTR -> Pointer<Utf8>
// destCapacity : INT -> Int32
// src : WORD* -> Pointer<Uint16>
// srcLength : INT -> Int32
// pErrorCode : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ucnv_fromUChars(
cnv: Pointer; // UConverter* in/out
dest: PAnsiChar; // LPSTR
destCapacity: Integer; // INT
src: Pointer; // WORD*
srcLength: Integer; // INT
pErrorCode: Pointer // UErrorCode* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'ucnv_fromUChars';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ucnv_fromUChars"
c_ucnv_fromUChars :: Ptr CIntPtr -> CString -> Int32 -> Ptr Word16 -> Int32 -> Ptr Int32 -> IO Int32
-- cnv : UConverter* in/out -> Ptr CIntPtr
-- dest : LPSTR -> CString
-- destCapacity : INT -> Int32
-- src : WORD* -> Ptr Word16
-- srcLength : INT -> Int32
-- pErrorCode : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ucnv_fromuchars =
foreign "ucnv_fromUChars"
((ptr intptr_t) @-> string @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> (ptr int32_t) @-> returning int32_t)
(* cnv : UConverter* in/out -> (ptr intptr_t) *)
(* dest : LPSTR -> string *)
(* destCapacity : INT -> int32_t *)
(* src : WORD* -> (ptr uint16_t) *)
(* srcLength : INT -> int32_t *)
(* pErrorCode : 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 ("ucnv_fromUChars" ucnv-from-uchars :convention :cdecl) :int32
(cnv :pointer) ; UConverter* in/out
(dest :string) ; LPSTR
(dest-capacity :int32) ; INT
(src :pointer) ; WORD*
(src-length :int32) ; INT
(p-error-code :pointer)) ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ucnv_fromUChars = Win32::API::More->new('icuuc',
'int ucnv_fromUChars(LPVOID cnv, LPCSTR dest, int destCapacity, LPVOID src, int srcLength, LPVOID pErrorCode)');
# my $ret = $ucnv_fromUChars->Call($cnv, $dest, $destCapacity, $src, $srcLength, $pErrorCode);
# cnv : UConverter* in/out -> LPVOID
# dest : LPSTR -> LPCSTR
# destCapacity : INT -> int
# src : WORD* -> LPVOID
# srcLength : INT -> int
# pErrorCode : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型