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

ucnv_setSubstChars

関数
変換器に変換失敗時の代替文字を設定する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

void ucnv_setSubstChars(
    UConverter* converter,
    LPCSTR subChars,
    CHAR len,
    UErrorCode* err
);

パラメーター

名前方向説明
converterUConverter*inout対象のコンバーターへのポインタ。
subCharsLPCSTRin新たに設定する置換バイト列へのポインタ。
lenCHARinsubCharsのバイト数。
errUErrorCode*inoutエラーコードを入出力するポインタ。事前にU_ZERO_ERRORで初期化する。

戻り値の型: void

各言語での呼び出し定義

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

void ucnv_setSubstChars(
    UConverter* converter,
    LPCSTR subChars,
    CHAR len,
    UErrorCode* err
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void ucnv_setSubstChars(
    ref IntPtr converter,   // UConverter* in/out
    [MarshalAs(UnmanagedType.LPStr)] string subChars,   // LPCSTR
    sbyte len,   // CHAR
    ref int err   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub ucnv_setSubstChars(
    ByRef converter As IntPtr,   ' UConverter* in/out
    <MarshalAs(UnmanagedType.LPStr)> subChars As String,   ' LPCSTR
    len As SByte,   ' CHAR
    ByRef err As Integer   ' UErrorCode* in/out
)
End Sub
' converter : UConverter* in/out
' subChars : LPCSTR
' len : CHAR
' err : UErrorCode* in/out
Declare PtrSafe Sub ucnv_setSubstChars Lib "icuuc" ( _
    ByRef converter As LongPtr, _
    ByVal subChars As String, _
    ByVal len 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_setSubstChars = ctypes.cdll.icuuc.ucnv_setSubstChars
ucnv_setSubstChars.restype = None
ucnv_setSubstChars.argtypes = [
    ctypes.c_void_p,  # converter : UConverter* in/out
    wintypes.LPCSTR,  # subChars : LPCSTR
    ctypes.c_byte,  # len : CHAR
    ctypes.c_void_p,  # err : UErrorCode* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
ucnv_setSubstChars = Fiddle::Function.new(
  lib['ucnv_setSubstChars'],
  [
    Fiddle::TYPE_VOIDP,  # converter : UConverter* in/out
    Fiddle::TYPE_VOIDP,  # subChars : LPCSTR
    Fiddle::TYPE_CHAR,  # len : CHAR
    Fiddle::TYPE_VOIDP,  # err : UErrorCode* in/out
  ],
  Fiddle::TYPE_VOID, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn ucnv_setSubstChars(
        converter: *mut isize,  // UConverter* in/out
        subChars: *const u8,  // LPCSTR
        len: 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_setSubstChars(ref IntPtr converter, [MarshalAs(UnmanagedType.LPStr)] string subChars, sbyte len, ref int err);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ucnv_setSubstChars' -Namespace Win32 -PassThru
# $api::ucnv_setSubstChars(converter, subChars, len, err)
#uselib "icuuc.dll"
#func global ucnv_setSubstChars "ucnv_setSubstChars" sptr, sptr, sptr, sptr
; ucnv_setSubstChars varptr(converter), subChars, len, varptr(err)
; converter : UConverter* in/out -> "sptr"
; subChars : LPCSTR -> "sptr"
; len : CHAR -> "sptr"
; err : UErrorCode* in/out -> "sptr"
出力引数:
#uselib "icuuc.dll"
#func global ucnv_setSubstChars "ucnv_setSubstChars" var, str, int, var
; ucnv_setSubstChars converter, subChars, len, err
; converter : UConverter* in/out -> "var"
; subChars : LPCSTR -> "str"
; len : CHAR -> "int"
; err : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void ucnv_setSubstChars(UConverter* converter, LPCSTR subChars, CHAR len, UErrorCode* err)
#uselib "icuuc.dll"
#func global ucnv_setSubstChars "ucnv_setSubstChars" var, str, int, var
; ucnv_setSubstChars converter, subChars, len, err
; converter : UConverter* in/out -> "var"
; subChars : LPCSTR -> "str"
; len : CHAR -> "int"
; err : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procucnv_setSubstChars = icuuc.NewProc("ucnv_setSubstChars")
)

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

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

foreign import ccall safe "ucnv_setSubstChars"
  c_ucnv_setSubstChars :: Ptr CIntPtr -> CString -> Int8 -> Ptr Int32 -> IO ()
-- converter : UConverter* in/out -> Ptr CIntPtr
-- subChars : LPCSTR -> CString
-- len : CHAR -> Int8
-- err : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ucnv_setsubstchars =
  foreign "ucnv_setSubstChars"
    ((ptr intptr_t) @-> string @-> int8_t @-> (ptr int32_t) @-> returning void)
(* converter : UConverter* in/out -> (ptr intptr_t) *)
(* subChars : LPCSTR -> string *)
(* len : 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_setSubstChars" ucnv-set-subst-chars :convention :cdecl) :void
  (converter :pointer)   ; UConverter* in/out
  (sub-chars :string)   ; LPCSTR
  (len :int8)   ; CHAR
  (err :pointer))   ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ucnv_setSubstChars = Win32::API::More->new('icuuc',
    'void ucnv_setSubstChars(LPVOID converter, LPCSTR subChars, char len, LPVOID err)');
# my $ret = $ucnv_setSubstChars->Call($converter, $subChars, $len, $err);
# converter : UConverter* in/out -> LPVOID
# subChars : LPCSTR -> LPCSTR
# len : CHAR -> char
# err : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型