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

ucnv_fromUnicode

関数
Unicodeからバイト列へストリーム変換する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

void ucnv_fromUnicode(
    UConverter* converter,
    CHAR** target,
    LPCSTR targetLimit,
    const WORD** source,
    const WORD* sourceLimit,
    INT* offsets,
    CHAR flush,
    UErrorCode* err
);

パラメーター

名前方向説明
converterUConverter*inoutUnicode→外部符号化変換に用いるコンバーターへのポインタ。
targetCHAR**inout出力バッファ位置を指すポインタのポインタ。書き込みに応じて進む。
targetLimitLPCSTRin出力バッファの終端(書き込み不可)を示すポインタ。
sourceWORD**in入力Unicode文字列位置を指すポインタのポインタ。読み取りに応じて進む。
sourceLimitWORD*in入力文字列の終端を示すポインタ。
offsetsINT*inout出力各バイトに対応する入力オフセットを受け取る配列。NULL可。
flushCHARin残存入力を確定するか(TRUE)、継続呼び出しか(FALSE)を示すブール値。
errUErrorCode*inoutエラーコードを入出力するポインタ。事前にU_ZERO_ERRORで初期化する。

戻り値の型: void

各言語での呼び出し定義

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

void ucnv_fromUnicode(
    UConverter* converter,
    CHAR** target,
    LPCSTR targetLimit,
    const WORD** source,
    const WORD* sourceLimit,
    INT* offsets,
    CHAR flush,
    UErrorCode* err
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void ucnv_fromUnicode(
    ref IntPtr converter,   // UConverter* in/out
    IntPtr target,   // CHAR** in/out
    [MarshalAs(UnmanagedType.LPStr)] string targetLimit,   // LPCSTR
    IntPtr source,   // WORD**
    ref ushort sourceLimit,   // WORD*
    ref int offsets,   // INT* in/out
    sbyte flush,   // CHAR
    ref int err   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub ucnv_fromUnicode(
    ByRef converter As IntPtr,   ' UConverter* in/out
    target As IntPtr,   ' CHAR** in/out
    <MarshalAs(UnmanagedType.LPStr)> targetLimit As String,   ' LPCSTR
    source As IntPtr,   ' WORD**
    ByRef sourceLimit As UShort,   ' WORD*
    ByRef offsets As Integer,   ' INT* in/out
    flush As SByte,   ' CHAR
    ByRef err As Integer   ' UErrorCode* in/out
)
End Sub
' converter : UConverter* in/out
' target : CHAR** in/out
' targetLimit : LPCSTR
' source : WORD**
' sourceLimit : WORD*
' offsets : INT* in/out
' flush : CHAR
' err : UErrorCode* in/out
Declare PtrSafe Sub ucnv_fromUnicode Lib "icuuc" ( _
    ByRef converter As LongPtr, _
    ByVal target As LongPtr, _
    ByVal targetLimit As String, _
    ByVal source As LongPtr, _
    ByRef sourceLimit As Integer, _
    ByRef offsets As Long, _
    ByVal flush As Byte, _
    ByRef err As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ucnv_fromUnicode = ctypes.cdll.icuuc.ucnv_fromUnicode
ucnv_fromUnicode.restype = None
ucnv_fromUnicode.argtypes = [
    ctypes.c_void_p,  # converter : UConverter* in/out
    ctypes.c_void_p,  # target : CHAR** in/out
    wintypes.LPCSTR,  # targetLimit : LPCSTR
    ctypes.c_void_p,  # source : WORD**
    ctypes.POINTER(ctypes.c_ushort),  # sourceLimit : WORD*
    ctypes.POINTER(ctypes.c_int),  # offsets : INT* in/out
    ctypes.c_byte,  # flush : CHAR
    ctypes.c_void_p,  # err : UErrorCode* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
ucnv_fromUnicode = Fiddle::Function.new(
  lib['ucnv_fromUnicode'],
  [
    Fiddle::TYPE_VOIDP,  # converter : UConverter* in/out
    Fiddle::TYPE_VOIDP,  # target : CHAR** in/out
    Fiddle::TYPE_VOIDP,  # targetLimit : LPCSTR
    Fiddle::TYPE_VOIDP,  # source : WORD**
    Fiddle::TYPE_VOIDP,  # sourceLimit : WORD*
    Fiddle::TYPE_VOIDP,  # offsets : INT* in/out
    Fiddle::TYPE_CHAR,  # flush : CHAR
    Fiddle::TYPE_VOIDP,  # err : UErrorCode* in/out
  ],
  Fiddle::TYPE_VOID, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn ucnv_fromUnicode(
        converter: *mut isize,  // UConverter* in/out
        target: *mut *mut i8,  // CHAR** in/out
        targetLimit: *const u8,  // LPCSTR
        source: *const *const u16,  // WORD**
        sourceLimit: *const u16,  // WORD*
        offsets: *mut i32,  // INT* in/out
        flush: i8,  // CHAR
        err: *mut i32  // UErrorCode* in/out
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void ucnv_fromUnicode(ref IntPtr converter, IntPtr target, [MarshalAs(UnmanagedType.LPStr)] string targetLimit, IntPtr source, ref ushort sourceLimit, ref int offsets, sbyte flush, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ucnv_fromUnicode' -Namespace Win32 -PassThru
# $api::ucnv_fromUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
#uselib "icuuc.dll"
#func global ucnv_fromUnicode "ucnv_fromUnicode" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ucnv_fromUnicode varptr(converter), varptr(target), targetLimit, varptr(source), varptr(sourceLimit), varptr(offsets), flush, varptr(err)
; converter : UConverter* in/out -> "sptr"
; target : CHAR** in/out -> "sptr"
; targetLimit : LPCSTR -> "sptr"
; source : WORD** -> "sptr"
; sourceLimit : WORD* -> "sptr"
; offsets : INT* in/out -> "sptr"
; flush : CHAR -> "sptr"
; err : UErrorCode* in/out -> "sptr"
出力引数:
#uselib "icuuc.dll"
#func global ucnv_fromUnicode "ucnv_fromUnicode" var, var, str, var, var, var, int, var
; ucnv_fromUnicode converter, target, targetLimit, source, sourceLimit, offsets, flush, err
; converter : UConverter* in/out -> "var"
; target : CHAR** in/out -> "var"
; targetLimit : LPCSTR -> "str"
; source : WORD** -> "var"
; sourceLimit : WORD* -> "var"
; offsets : INT* in/out -> "var"
; flush : CHAR -> "int"
; err : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void ucnv_fromUnicode(UConverter* converter, CHAR** target, LPCSTR targetLimit, WORD** source, WORD* sourceLimit, INT* offsets, CHAR flush, UErrorCode* err)
#uselib "icuuc.dll"
#func global ucnv_fromUnicode "ucnv_fromUnicode" var, var, str, var, var, var, int, var
; ucnv_fromUnicode converter, target, targetLimit, source, sourceLimit, offsets, flush, err
; converter : UConverter* in/out -> "var"
; target : CHAR** in/out -> "var"
; targetLimit : LPCSTR -> "str"
; source : WORD** -> "var"
; sourceLimit : WORD* -> "var"
; offsets : INT* in/out -> "var"
; flush : CHAR -> "int"
; err : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procucnv_fromUnicode = icuuc.NewProc("ucnv_fromUnicode")
)

// converter (UConverter* in/out), target (CHAR** in/out), targetLimit (LPCSTR), source (WORD**), sourceLimit (WORD*), offsets (INT* in/out), flush (CHAR), err (UErrorCode* in/out)
r1, _, err := procucnv_fromUnicode.Call(
	uintptr(converter),
	uintptr(target),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(targetLimit))),
	uintptr(source),
	uintptr(sourceLimit),
	uintptr(offsets),
	uintptr(flush),
	uintptr(err),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure ucnv_fromUnicode(
  converter: Pointer;   // UConverter* in/out
  target: Pointer;   // CHAR** in/out
  targetLimit: PAnsiChar;   // LPCSTR
  source: Pointer;   // WORD**
  sourceLimit: Pointer;   // WORD*
  offsets: Pointer;   // INT* in/out
  flush: Shortint;   // CHAR
  err: Pointer   // UErrorCode* in/out
); cdecl;
  external 'icuuc.dll' name 'ucnv_fromUnicode';
result := DllCall("icuuc\ucnv_fromUnicode"
    , "Ptr", converter   ; UConverter* in/out
    , "Ptr", target   ; CHAR** in/out
    , "AStr", targetLimit   ; LPCSTR
    , "Ptr", source   ; WORD**
    , "Ptr", sourceLimit   ; WORD*
    , "Ptr", offsets   ; INT* in/out
    , "Char", flush   ; CHAR
    , "Ptr", err   ; UErrorCode* in/out
    , "Cdecl Int")   ; return: void
●ucnv_fromUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err) = DLL("icuuc.dll", "int ucnv_fromUnicode(void*, void*, char*, void*, void*, void*, char, void*)")
# 呼び出し: ucnv_fromUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
# converter : UConverter* in/out -> "void*"
# target : CHAR** in/out -> "void*"
# targetLimit : LPCSTR -> "char*"
# source : WORD** -> "void*"
# sourceLimit : WORD* -> "void*"
# offsets : INT* in/out -> "void*"
# flush : CHAR -> "char"
# 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 ucnv_fromUnicode(
    converter: [*c]isize, // UConverter* in/out
    target: [*c][*c]i8, // CHAR** in/out
    targetLimit: [*c]const u8, // LPCSTR
    source: [*c][*c]u16, // WORD**
    sourceLimit: [*c]u16, // WORD*
    offsets: [*c]i32, // INT* in/out
    flush: i8, // CHAR
    err: [*c]i32 // UErrorCode* in/out
) callconv(.c) void;
proc ucnv_fromUnicode(
    `converter`: ptr int,  # UConverter* in/out
    target: ptr int8,  # CHAR** in/out
    targetLimit: cstring,  # LPCSTR
    source: ptr uint16,  # WORD**
    sourceLimit: ptr uint16,  # WORD*
    offsets: ptr int32,  # INT* in/out
    flush: int8,  # CHAR
    err: ptr int32  # UErrorCode* in/out
) {.importc: "ucnv_fromUnicode", cdecl, dynlib: "icuuc.dll".}
pragma(lib, "icuuc");
extern(C)
void ucnv_fromUnicode(
    ptrdiff_t* converter,   // UConverter* in/out
    byte** target,   // CHAR** in/out
    const(char)* targetLimit,   // LPCSTR
    ushort** source,   // WORD**
    ushort* sourceLimit,   // WORD*
    int* offsets,   // INT* in/out
    byte flush,   // CHAR
    int* err   // UErrorCode* in/out
);
ccall((:ucnv_fromUnicode, "icuuc.dll"), Cvoid,
      (Ptr{Int}, Ptr{Int8}, Cstring, Ptr{UInt16}, Ptr{UInt16}, Ptr{Int32}, Int8, Ptr{Int32}),
      converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
# converter : UConverter* in/out -> Ptr{Int}
# target : CHAR** in/out -> Ptr{Int8}
# targetLimit : LPCSTR -> Cstring
# source : WORD** -> Ptr{UInt16}
# sourceLimit : WORD* -> Ptr{UInt16}
# offsets : INT* in/out -> Ptr{Int32}
# flush : CHAR -> Int8
# err : UErrorCode* in/out -> Ptr{Int32}
local ffi = require("ffi")
ffi.cdef[[
void ucnv_fromUnicode(
    intptr_t* converter,
    int8_t** target,
    const char* targetLimit,
    uint16_t** source,
    uint16_t* sourceLimit,
    int32_t* offsets,
    int8_t flush,
    int32_t* err);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.ucnv_fromUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
-- converter : UConverter* in/out
-- target : CHAR** in/out
-- targetLimit : LPCSTR
-- source : WORD**
-- sourceLimit : WORD*
-- offsets : INT* in/out
-- flush : CHAR
-- err : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const ucnv_fromUnicode = lib.func('__cdecl', 'ucnv_fromUnicode', 'void', ['intptr_t *', 'int8_t *', 'str', 'uint16_t *', 'uint16_t *', 'int32_t *', 'int8_t', 'int32_t *']);
// ucnv_fromUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
// converter : UConverter* in/out -> 'intptr_t *'
// target : CHAR** in/out -> 'int8_t *'
// targetLimit : LPCSTR -> 'str'
// source : WORD** -> 'uint16_t *'
// sourceLimit : WORD* -> 'uint16_t *'
// offsets : INT* in/out -> 'int32_t *'
// flush : CHAR -> 'int8_t'
// err : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("icuuc.dll", {
  ucnv_fromUnicode: { parameters: ["pointer", "pointer", "buffer", "pointer", "pointer", "pointer", "i8", "pointer"], result: "void" },
});
// lib.symbols.ucnv_fromUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err)
// converter : UConverter* in/out -> "pointer"
// target : CHAR** in/out -> "pointer"
// targetLimit : LPCSTR -> "buffer"
// source : WORD** -> "pointer"
// sourceLimit : WORD* -> "pointer"
// offsets : INT* in/out -> "pointer"
// flush : CHAR -> "i8"
// err : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void ucnv_fromUnicode(
    intptr_t* converter,
    int8_t** target,
    const char* targetLimit,
    uint16_t** source,
    uint16_t* sourceLimit,
    int32_t* offsets,
    int8_t flush,
    int32_t* err);
C, "icuuc.dll");
// $ffi->ucnv_fromUnicode(converter, target, targetLimit, source, sourceLimit, offsets, flush, err);
// converter : UConverter* in/out
// target : CHAR** in/out
// targetLimit : LPCSTR
// source : WORD**
// sourceLimit : WORD*
// offsets : INT* in/out
// flush : CHAR
// 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);
    void ucnv_fromUnicode(
        LongByReference converter,   // UConverter* in/out
        Pointer target,   // CHAR** in/out
        String targetLimit,   // LPCSTR
        Pointer source,   // WORD**
        ShortByReference sourceLimit,   // WORD*
        IntByReference offsets,   // INT* in/out
        byte flush,   // CHAR
        IntByReference err   // UErrorCode* in/out
    );
}
@[Link("icuuc")]
lib Libicuuc
  fun ucnv_fromUnicode = ucnv_fromUnicode(
    converter : LibC::SSizeT*,   # UConverter* in/out
    target : Int8**,   # CHAR** in/out
    targetLimit : UInt8*,   # LPCSTR
    source : UInt16**,   # WORD**
    sourceLimit : UInt16*,   # WORD*
    offsets : Int32*,   # INT* in/out
    flush : Int8,   # CHAR
    err : Int32*   # UErrorCode* in/out
  ) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ucnv_fromUnicodeNative = Void Function(Pointer<IntPtr>, Pointer<Int8>, Pointer<Utf8>, Pointer<Uint16>, Pointer<Uint16>, Pointer<Int32>, Int8, Pointer<Int32>);
typedef ucnv_fromUnicodeDart = void Function(Pointer<IntPtr>, Pointer<Int8>, Pointer<Utf8>, Pointer<Uint16>, Pointer<Uint16>, Pointer<Int32>, int, Pointer<Int32>);
final ucnv_fromUnicode = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<ucnv_fromUnicodeNative, ucnv_fromUnicodeDart>('ucnv_fromUnicode');
// converter : UConverter* in/out -> Pointer<IntPtr>
// target : CHAR** in/out -> Pointer<Int8>
// targetLimit : LPCSTR -> Pointer<Utf8>
// source : WORD** -> Pointer<Uint16>
// sourceLimit : WORD* -> Pointer<Uint16>
// offsets : INT* in/out -> Pointer<Int32>
// flush : CHAR -> Int8
// err : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure ucnv_fromUnicode(
  converter: Pointer;   // UConverter* in/out
  target: Pointer;   // CHAR** in/out
  targetLimit: PAnsiChar;   // LPCSTR
  source: Pointer;   // WORD**
  sourceLimit: Pointer;   // WORD*
  offsets: Pointer;   // INT* in/out
  flush: Shortint;   // CHAR
  err: Pointer   // UErrorCode* in/out
); cdecl;
  external 'icuuc.dll' name 'ucnv_fromUnicode';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ucnv_fromUnicode"
  c_ucnv_fromUnicode :: Ptr CIntPtr -> Ptr Int8 -> CString -> Ptr Word16 -> Ptr Word16 -> Ptr Int32 -> Int8 -> Ptr Int32 -> IO ()
-- converter : UConverter* in/out -> Ptr CIntPtr
-- target : CHAR** in/out -> Ptr Int8
-- targetLimit : LPCSTR -> CString
-- source : WORD** -> Ptr Word16
-- sourceLimit : WORD* -> Ptr Word16
-- offsets : INT* in/out -> Ptr Int32
-- flush : CHAR -> Int8
-- err : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ucnv_fromunicode =
  foreign "ucnv_fromUnicode"
    ((ptr intptr_t) @-> (ptr int8_t) @-> string @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr int32_t) @-> int8_t @-> (ptr int32_t) @-> returning void)
(* converter : UConverter* in/out -> (ptr intptr_t) *)
(* target : CHAR** in/out -> (ptr int8_t) *)
(* targetLimit : LPCSTR -> string *)
(* source : WORD** -> (ptr uint16_t) *)
(* sourceLimit : WORD* -> (ptr uint16_t) *)
(* offsets : INT* in/out -> (ptr int32_t) *)
(* flush : CHAR -> int8_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 ("ucnv_fromUnicode" ucnv-from-unicode :convention :cdecl) :void
  (converter :pointer)   ; UConverter* in/out
  (target :pointer)   ; CHAR** in/out
  (target-limit :string)   ; LPCSTR
  (source :pointer)   ; WORD**
  (source-limit :pointer)   ; WORD*
  (offsets :pointer)   ; INT* in/out
  (flush :int8)   ; CHAR
  (err :pointer))   ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ucnv_fromUnicode = Win32::API::More->new('icuuc',
    'void ucnv_fromUnicode(LPVOID converter, LPVOID target, LPCSTR targetLimit, LPVOID source, LPVOID sourceLimit, LPVOID offsets, char flush, LPVOID err)');
# my $ret = $ucnv_fromUnicode->Call($converter, $target, $targetLimit, $source, $sourceLimit, $offsets, $flush, $err);
# converter : UConverter* in/out -> LPVOID
# target : CHAR** in/out -> LPVOID
# targetLimit : LPCSTR -> LPCSTR
# source : WORD** -> LPVOID
# sourceLimit : WORD* -> LPVOID
# offsets : INT* in/out -> LPVOID
# flush : CHAR -> char
# err : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型