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

ucnv_toUChars

関数
バイト列をUnicode文字列へ一括変換する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

INT ucnv_toUChars(
    UConverter* cnv,
    WORD* dest,
    INT destCapacity,
    LPCSTR src,
    INT srcLength,
    UErrorCode* pErrorCode
);

パラメーター

名前方向説明
cnvUConverter*inout外部符号化→Unicode変換に用いるコンバーターへのポインタ。
destWORD*inout変換結果のUnicode文字列を受け取る出力バッファ。
destCapacityINTindestバッファの要素容量。
srcLPCSTRin入力バイト列へのポインタ。
srcLengthINTinsrcのバイト数。-1でNUL終端を意味する。
pErrorCodeUErrorCode*inoutエラーコードを入出力するポインタ。事前にU_ZERO_ERRORで初期化する。

戻り値の型: 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 varptr(cnv), varptr(dest), destCapacity, src, srcLength, varptr(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" var, var, int, str, int, var
; res = ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
; cnv : UConverter* in/out -> "var"
; dest : WORD* in/out -> "var"
; destCapacity : INT -> "int"
; src : LPCSTR -> "str"
; srcLength : INT -> "int"
; pErrorCode : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は 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" var, var, int, str, int, var
; res = ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
; cnv : UConverter* in/out -> "var"
; dest : WORD* in/out -> "var"
; destCapacity : INT -> "int"
; src : LPCSTR -> "str"
; srcLength : INT -> "int"
; pErrorCode : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。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   // INT
function 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`,…) を使用。
const std = @import("std");

extern "icuuc" fn ucnv_toUChars(
    cnv: [*c]isize, // UConverter* in/out
    dest: [*c]u16, // WORD* in/out
    destCapacity: i32, // INT
    src: [*c]const u8, // LPCSTR
    srcLength: i32, // INT
    pErrorCode: [*c]i32 // UErrorCode* in/out
) callconv(.c) i32;
proc ucnv_toUChars(
    cnv: ptr int,  # UConverter* in/out
    dest: ptr uint16,  # WORD* in/out
    destCapacity: int32,  # INT
    src: cstring,  # LPCSTR
    srcLength: int32,  # INT
    pErrorCode: ptr int32  # UErrorCode* in/out
): int32 {.importc: "ucnv_toUChars", cdecl, dynlib: "icuuc.dll".}
pragma(lib, "icuuc");
extern(C)
int ucnv_toUChars(
    ptrdiff_t* cnv,   // UConverter* in/out
    ushort* dest,   // WORD* in/out
    int destCapacity,   // INT
    const(char)* src,   // LPCSTR
    int srcLength,   // INT
    int* pErrorCode   // UErrorCode* in/out
);
ccall((:ucnv_toUChars, "icuuc.dll"), Int32,
      (Ptr{Int}, Ptr{UInt16}, Int32, Cstring, Int32, Ptr{Int32}),
      cnv, dest, destCapacity, src, srcLength, pErrorCode)
# cnv : UConverter* in/out -> Ptr{Int}
# dest : WORD* in/out -> Ptr{UInt16}
# destCapacity : INT -> Int32
# src : LPCSTR -> Cstring
# srcLength : INT -> Int32
# pErrorCode : UErrorCode* in/out -> Ptr{Int32}
local ffi = require("ffi")
ffi.cdef[[
int32_t ucnv_toUChars(
    intptr_t* cnv,
    uint16_t* dest,
    int32_t destCapacity,
    const char* src,
    int32_t srcLength,
    int32_t* pErrorCode);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
-- cnv : UConverter* in/out
-- dest : WORD* in/out
-- destCapacity : INT
-- src : LPCSTR
-- srcLength : INT
-- pErrorCode : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const ucnv_toUChars = lib.func('__cdecl', 'ucnv_toUChars', 'int32_t', ['intptr_t *', 'uint16_t *', 'int32_t', 'str', 'int32_t', 'int32_t *']);
// ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
// cnv : UConverter* in/out -> 'intptr_t *'
// dest : WORD* in/out -> 'uint16_t *'
// destCapacity : INT -> 'int32_t'
// src : LPCSTR -> 'str'
// srcLength : INT -> 'int32_t'
// pErrorCode : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("icuuc.dll", {
  ucnv_toUChars: { parameters: ["pointer", "pointer", "i32", "buffer", "i32", "pointer"], result: "i32" },
});
// lib.symbols.ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode)
// cnv : UConverter* in/out -> "pointer"
// dest : WORD* in/out -> "pointer"
// destCapacity : INT -> "i32"
// src : LPCSTR -> "buffer"
// srcLength : INT -> "i32"
// pErrorCode : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ucnv_toUChars(
    intptr_t* cnv,
    uint16_t* dest,
    int32_t destCapacity,
    const char* src,
    int32_t srcLength,
    int32_t* pErrorCode);
C, "icuuc.dll");
// $ffi->ucnv_toUChars(cnv, dest, destCapacity, src, srcLength, pErrorCode);
// cnv : UConverter* in/out
// dest : WORD* in/out
// destCapacity : INT
// src : LPCSTR
// 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_toUChars(
        LongByReference cnv,   // UConverter* in/out
        ShortByReference dest,   // WORD* in/out
        int destCapacity,   // INT
        String src,   // LPCSTR
        int srcLength,   // INT
        IntByReference pErrorCode   // UErrorCode* in/out
    );
}
@[Link("icuuc")]
lib Libicuuc
  fun ucnv_toUChars = ucnv_toUChars(
    cnv : LibC::SSizeT*,   # UConverter* in/out
    dest : UInt16*,   # WORD* in/out
    destCapacity : Int32,   # INT
    src : UInt8*,   # LPCSTR
    srcLength : Int32,   # INT
    pErrorCode : Int32*   # UErrorCode* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ucnv_toUCharsNative = Int32 Function(Pointer<IntPtr>, Pointer<Uint16>, Int32, Pointer<Utf8>, Int32, Pointer<Int32>);
typedef ucnv_toUCharsDart = int Function(Pointer<IntPtr>, Pointer<Uint16>, int, Pointer<Utf8>, int, Pointer<Int32>);
final ucnv_toUChars = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<ucnv_toUCharsNative, ucnv_toUCharsDart>('ucnv_toUChars');
// cnv : UConverter* in/out -> Pointer<IntPtr>
// dest : WORD* in/out -> Pointer<Uint16>
// destCapacity : INT -> Int32
// src : LPCSTR -> Pointer<Utf8>
// srcLength : INT -> Int32
// pErrorCode : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function 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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ucnv_toUChars"
  c_ucnv_toUChars :: Ptr CIntPtr -> Ptr Word16 -> Int32 -> CString -> Int32 -> Ptr Int32 -> IO Int32
-- cnv : UConverter* in/out -> Ptr CIntPtr
-- dest : WORD* in/out -> Ptr Word16
-- destCapacity : INT -> Int32
-- src : LPCSTR -> CString
-- srcLength : INT -> Int32
-- pErrorCode : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ucnv_touchars =
  foreign "ucnv_toUChars"
    ((ptr intptr_t) @-> (ptr uint16_t) @-> int32_t @-> string @-> int32_t @-> (ptr int32_t) @-> returning int32_t)
(* cnv : UConverter* in/out -> (ptr intptr_t) *)
(* dest : WORD* in/out -> (ptr uint16_t) *)
(* destCapacity : INT -> int32_t *)
(* src : LPCSTR -> string *)
(* 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_toUChars" ucnv-to-uchars :convention :cdecl) :int32
  (cnv :pointer)   ; UConverter* in/out
  (dest :pointer)   ; WORD* in/out
  (dest-capacity :int32)   ; INT
  (src :string)   ; LPCSTR
  (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_toUChars = Win32::API::More->new('icuuc',
    'int ucnv_toUChars(LPVOID cnv, LPVOID dest, int destCapacity, LPCSTR src, int srcLength, LPVOID pErrorCode)');
# my $ret = $ucnv_toUChars->Call($cnv, $dest, $destCapacity, $src, $srcLength, $pErrorCode);
# cnv : UConverter* in/out -> LPVOID
# dest : WORD* in/out -> LPVOID
# destCapacity : INT -> int
# src : LPCSTR -> LPCSTR
# srcLength : INT -> int
# pErrorCode : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型