ホーム › Globalization › ucnv_toUChars
ucnv_toUChars
関数バイト列をUnicode文字列へ一括変換する。
シグネチャ
// icuuc.dll
#include <windows.h>
INT ucnv_toUChars(
UConverter* cnv,
WORD* dest,
INT destCapacity,
LPCSTR src,
INT srcLength,
UErrorCode* pErrorCode
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| cnv | UConverter* | inout |
| dest | WORD* | inout |
| destCapacity | INT | in |
| src | LPCSTR | in |
| srcLength | INT | in |
| pErrorCode | UErrorCode* | inout |
戻り値の型: INT
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
INT ucnv_toUChars(
UConverter* cnv,
WORD* dest,
INT destCapacity,
LPCSTR src,
INT srcLength,
UErrorCode* pErrorCode
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int ucnv_toUChars(
ref IntPtr cnv, // UConverter* in/out
ref ushort dest, // WORD* in/out
int destCapacity, // INT
[MarshalAs(UnmanagedType.LPStr)] string src, // LPCSTR
int srcLength, // INT
ref int pErrorCode // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ucnv_toUChars(
ByRef cnv As IntPtr, ' UConverter* in/out
ByRef dest As UShort, ' WORD* in/out
destCapacity As Integer, ' INT
<MarshalAs(UnmanagedType.LPStr)> src As String, ' LPCSTR
srcLength As Integer, ' INT
ByRef pErrorCode As Integer ' UErrorCode* in/out
) As Integer
End Function' cnv : UConverter* in/out
' dest : WORD* in/out
' destCapacity : INT
' src : LPCSTR
' srcLength : INT
' pErrorCode : UErrorCode* in/out
Declare PtrSafe Function ucnv_toUChars Lib "icuuc" ( _
ByRef cnv As LongPtr, _
ByRef dest As Integer, _
ByVal destCapacity As Long, _
ByVal src As String, _
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_toUChars = ctypes.cdll.icuuc.ucnv_toUChars
ucnv_toUChars.restype = ctypes.c_int
ucnv_toUChars.argtypes = [
ctypes.c_void_p, # cnv : UConverter* in/out
ctypes.POINTER(ctypes.c_ushort), # dest : WORD* in/out
ctypes.c_int, # destCapacity : INT
wintypes.LPCSTR, # src : LPCSTR
ctypes.c_int, # srcLength : INT
ctypes.c_void_p, # pErrorCode : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
ucnv_toUChars = Fiddle::Function.new(
lib['ucnv_toUChars'],
[
Fiddle::TYPE_VOIDP, # cnv : UConverter* in/out
Fiddle::TYPE_VOIDP, # dest : WORD* in/out
Fiddle::TYPE_INT, # destCapacity : INT
Fiddle::TYPE_VOIDP, # src : LPCSTR
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_toUChars(
cnv: *mut isize, // UConverter* in/out
dest: *mut u16, // WORD* in/out
destCapacity: i32, // INT
src: *const u8, // LPCSTR
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_toUChars(ref IntPtr cnv, ref ushort dest, int destCapacity, [MarshalAs(UnmanagedType.LPStr)] string src, int srcLength, ref int pErrorCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ucnv_toUChars' -Namespace Win32 -PassThru
# $api::ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)#uselib "icuuc.dll"
#func global ucnv_toUChars "ucnv_toUChars" sptr, sptr, sptr, sptr, sptr, sptr
; ucnv_toUChars cnv, varptr(dest), destCapacity, src, srcLength, pErrorCode ; 戻り値は stat
; cnv : UConverter* in/out -> "sptr"
; dest : WORD* in/out -> "sptr"
; destCapacity : INT -> "sptr"
; src : LPCSTR -> "sptr"
; srcLength : INT -> "sptr"
; pErrorCode : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global ucnv_toUChars "ucnv_toUChars" int, var, int, str, int, int ; res = ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode) ; cnv : UConverter* in/out -> "int" ; dest : WORD* in/out -> "var" ; destCapacity : INT -> "int" ; src : LPCSTR -> "str" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global ucnv_toUChars "ucnv_toUChars" int, sptr, int, str, int, int ; res = ucnv_toUChars(cnv, varptr(dest), destCapacity, src, srcLength, pErrorCode) ; cnv : UConverter* in/out -> "int" ; dest : WORD* in/out -> "sptr" ; destCapacity : INT -> "int" ; src : LPCSTR -> "str" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT ucnv_toUChars(UConverter* cnv, WORD* dest, INT destCapacity, LPCSTR src, INT srcLength, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global ucnv_toUChars "ucnv_toUChars" int, var, int, str, int, int ; res = ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode) ; cnv : UConverter* in/out -> "int" ; dest : WORD* in/out -> "var" ; destCapacity : INT -> "int" ; src : LPCSTR -> "str" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT ucnv_toUChars(UConverter* cnv, WORD* dest, INT destCapacity, LPCSTR src, INT srcLength, UErrorCode* pErrorCode) #uselib "icuuc.dll" #cfunc global ucnv_toUChars "ucnv_toUChars" int, intptr, int, str, int, int ; res = ucnv_toUChars(cnv, varptr(dest), destCapacity, src, srcLength, pErrorCode) ; cnv : UConverter* in/out -> "int" ; dest : WORD* in/out -> "intptr" ; destCapacity : INT -> "int" ; src : LPCSTR -> "str" ; srcLength : INT -> "int" ; pErrorCode : UErrorCode* in/out -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procucnv_toUChars = icuuc.NewProc("ucnv_toUChars")
)
// cnv (UConverter* in/out), dest (WORD* in/out), destCapacity (INT), src (LPCSTR), srcLength (INT), pErrorCode (UErrorCode* in/out)
r1, _, err := procucnv_toUChars.Call(
uintptr(cnv),
uintptr(dest),
uintptr(destCapacity),
uintptr(unsafe.Pointer(windows.BytePtrFromString(src))),
uintptr(srcLength),
uintptr(pErrorCode),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction ucnv_toUChars(
cnv: Pointer; // UConverter* in/out
dest: Pointer; // WORD* in/out
destCapacity: Integer; // INT
src: PAnsiChar; // LPCSTR
srcLength: Integer; // INT
pErrorCode: Pointer // UErrorCode* in/out
): Integer; cdecl;
external 'icuuc.dll' name 'ucnv_toUChars';result := DllCall("icuuc\ucnv_toUChars"
, "Ptr", cnv ; UConverter* in/out
, "Ptr", dest ; WORD* in/out
, "Int", destCapacity ; INT
, "AStr", src ; LPCSTR
, "Int", srcLength ; INT
, "Ptr", pErrorCode ; UErrorCode* in/out
, "Cdecl Int") ; return: INT●ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode) = DLL("icuuc.dll", "int ucnv_toUChars(void*, void*, int, char*, int, void*)")
# 呼び出し: ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
# cnv : UConverter* in/out -> "void*"
# dest : WORD* in/out -> "void*"
# destCapacity : INT -> "int"
# src : LPCSTR -> "char*"
# srcLength : INT -> "int"
# pErrorCode : UErrorCode* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。