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

u_strToJavaModifiedUTF8

関数
UTF-16文字列をJava修正UTF-8形式へ変換する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

LPSTR u_strToJavaModifiedUTF8(
    LPSTR dest,
    INT destCapacity,
    INT* pDestLength,
    const WORD* src,
    INT srcLength,
    UErrorCode* pErrorCode
);

パラメーター

名前方向説明
destLPSTRinJava修正UTF-8の変換結果を格納する出力バッファ。NULL可。
destCapacityINTindestの容量をバイト単位で指定する。0で事前長取得。
pDestLengthINT*inout実際に必要な出力バイト長を受け取るポインタ。NULL可。
srcWORD*in変換元のUTF-16文字列を指す。
srcLengthINTinsrcの長さをUChar単位で指定する。-1でNUL終端。
pErrorCodeUErrorCode*inoutICUエラーコードを入出力するポインタ。呼出前に成功値で初期化する。

戻り値の型: LPSTR

各言語での呼び出し定義

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

LPSTR u_strToJavaModifiedUTF8(
    LPSTR dest,
    INT destCapacity,
    INT* pDestLength,
    const WORD* src,
    INT srcLength,
    UErrorCode* pErrorCode
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr u_strToJavaModifiedUTF8(
    [MarshalAs(UnmanagedType.LPStr)] string dest,   // LPSTR
    int destCapacity,   // INT
    ref int pDestLength,   // INT* in/out
    ref ushort src,   // WORD*
    int srcLength,   // INT
    ref int pErrorCode   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_strToJavaModifiedUTF8(
    <MarshalAs(UnmanagedType.LPStr)> dest As String,   ' LPSTR
    destCapacity As Integer,   ' INT
    ByRef pDestLength As Integer,   ' INT* in/out
    ByRef src As UShort,   ' WORD*
    srcLength As Integer,   ' INT
    ByRef pErrorCode As Integer   ' UErrorCode* in/out
) As IntPtr
End Function
' dest : LPSTR
' destCapacity : INT
' pDestLength : INT* in/out
' src : WORD*
' srcLength : INT
' pErrorCode : UErrorCode* in/out
Declare PtrSafe Function u_strToJavaModifiedUTF8 Lib "icuuc" ( _
    ByVal dest As String, _
    ByVal destCapacity As Long, _
    ByRef pDestLength As Long, _
    ByRef src As Integer, _
    ByVal srcLength As Long, _
    ByRef pErrorCode As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

u_strToJavaModifiedUTF8 = ctypes.cdll.icuuc.u_strToJavaModifiedUTF8
u_strToJavaModifiedUTF8.restype = wintypes.LPSTR
u_strToJavaModifiedUTF8.argtypes = [
    wintypes.LPCSTR,  # dest : LPSTR
    ctypes.c_int,  # destCapacity : INT
    ctypes.POINTER(ctypes.c_int),  # pDestLength : INT* in/out
    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')
u_strToJavaModifiedUTF8 = Fiddle::Function.new(
  lib['u_strToJavaModifiedUTF8'],
  [
    Fiddle::TYPE_VOIDP,  # dest : LPSTR
    Fiddle::TYPE_INT,  # destCapacity : INT
    Fiddle::TYPE_VOIDP,  # pDestLength : INT* in/out
    Fiddle::TYPE_VOIDP,  # src : WORD*
    Fiddle::TYPE_INT,  # srcLength : INT
    Fiddle::TYPE_VOIDP,  # pErrorCode : UErrorCode* in/out
  ],
  Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn u_strToJavaModifiedUTF8(
        dest: *mut u8,  // LPSTR
        destCapacity: i32,  // INT
        pDestLength: *mut i32,  // INT* in/out
        src: *const u16,  // WORD*
        srcLength: i32,  // INT
        pErrorCode: *mut i32  // UErrorCode* in/out
    ) -> *mut u8;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr u_strToJavaModifiedUTF8([MarshalAs(UnmanagedType.LPStr)] string dest, int destCapacity, ref int pDestLength, ref ushort src, int srcLength, ref int pErrorCode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_strToJavaModifiedUTF8' -Namespace Win32 -PassThru
# $api::u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
#uselib "icuuc.dll"
#func global u_strToJavaModifiedUTF8 "u_strToJavaModifiedUTF8" sptr, sptr, sptr, sptr, sptr, sptr
; u_strToJavaModifiedUTF8 dest, destCapacity, varptr(pDestLength), varptr(src), srcLength, varptr(pErrorCode)   ; 戻り値は stat
; dest : LPSTR -> "sptr"
; destCapacity : INT -> "sptr"
; pDestLength : INT* in/out -> "sptr"
; src : WORD* -> "sptr"
; srcLength : INT -> "sptr"
; pErrorCode : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "icuuc.dll"
#cfunc global u_strToJavaModifiedUTF8 "u_strToJavaModifiedUTF8" str, int, var, var, int, var
; res = u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
; dest : LPSTR -> "str"
; destCapacity : INT -> "int"
; pDestLength : INT* in/out -> "var"
; src : WORD* -> "var"
; srcLength : INT -> "int"
; pErrorCode : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; LPSTR u_strToJavaModifiedUTF8(LPSTR dest, INT destCapacity, INT* pDestLength, WORD* src, INT srcLength, UErrorCode* pErrorCode)
#uselib "icuuc.dll"
#cfunc global u_strToJavaModifiedUTF8 "u_strToJavaModifiedUTF8" str, int, var, var, int, var
; res = u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
; dest : LPSTR -> "str"
; destCapacity : INT -> "int"
; pDestLength : INT* in/out -> "var"
; src : WORD* -> "var"
; srcLength : INT -> "int"
; pErrorCode : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procu_strToJavaModifiedUTF8 = icuuc.NewProc("u_strToJavaModifiedUTF8")
)

// dest (LPSTR), destCapacity (INT), pDestLength (INT* in/out), src (WORD*), srcLength (INT), pErrorCode (UErrorCode* in/out)
r1, _, err := procu_strToJavaModifiedUTF8.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(dest))),
	uintptr(destCapacity),
	uintptr(pDestLength),
	uintptr(src),
	uintptr(srcLength),
	uintptr(pErrorCode),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPSTR
function u_strToJavaModifiedUTF8(
  dest: PAnsiChar;   // LPSTR
  destCapacity: Integer;   // INT
  pDestLength: Pointer;   // INT* in/out
  src: Pointer;   // WORD*
  srcLength: Integer;   // INT
  pErrorCode: Pointer   // UErrorCode* in/out
): PAnsiChar; cdecl;
  external 'icuuc.dll' name 'u_strToJavaModifiedUTF8';
result := DllCall("icuuc\u_strToJavaModifiedUTF8"
    , "AStr", dest   ; LPSTR
    , "Int", destCapacity   ; INT
    , "Ptr", pDestLength   ; INT* in/out
    , "Ptr", src   ; WORD*
    , "Int", srcLength   ; INT
    , "Ptr", pErrorCode   ; UErrorCode* in/out
    , "Cdecl Ptr")   ; return: LPSTR
●u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode) = DLL("icuuc.dll", "char* u_strToJavaModifiedUTF8(char*, int, void*, void*, int, void*)")
# 呼び出し: u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
# dest : LPSTR -> "char*"
# destCapacity : INT -> "int"
# pDestLength : INT* in/out -> "void*"
# 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 u_strToJavaModifiedUTF8(
    dest: [*c]const u8, // LPSTR
    destCapacity: i32, // INT
    pDestLength: [*c]i32, // INT* in/out
    src: [*c]u16, // WORD*
    srcLength: i32, // INT
    pErrorCode: [*c]i32 // UErrorCode* in/out
) callconv(.c) [*c]const u8;
proc u_strToJavaModifiedUTF8(
    dest: cstring,  # LPSTR
    destCapacity: int32,  # INT
    pDestLength: ptr int32,  # INT* in/out
    src: ptr uint16,  # WORD*
    srcLength: int32,  # INT
    pErrorCode: ptr int32  # UErrorCode* in/out
): cstring {.importc: "u_strToJavaModifiedUTF8", cdecl, dynlib: "icuuc.dll".}
pragma(lib, "icuuc");
extern(C)
const(char)* u_strToJavaModifiedUTF8(
    const(char)* dest,   // LPSTR
    int destCapacity,   // INT
    int* pDestLength,   // INT* in/out
    ushort* src,   // WORD*
    int srcLength,   // INT
    int* pErrorCode   // UErrorCode* in/out
);
ccall((:u_strToJavaModifiedUTF8, "icuuc.dll"), Cstring,
      (Cstring, Int32, Ptr{Int32}, Ptr{UInt16}, Int32, Ptr{Int32}),
      dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
# dest : LPSTR -> Cstring
# destCapacity : INT -> Int32
# pDestLength : INT* in/out -> Ptr{Int32}
# src : WORD* -> Ptr{UInt16}
# srcLength : INT -> Int32
# pErrorCode : UErrorCode* in/out -> Ptr{Int32}
local ffi = require("ffi")
ffi.cdef[[
const char* u_strToJavaModifiedUTF8(
    const char* dest,
    int32_t destCapacity,
    int32_t* pDestLength,
    uint16_t* src,
    int32_t srcLength,
    int32_t* pErrorCode);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
-- dest : LPSTR
-- destCapacity : INT
-- pDestLength : INT* in/out
-- 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 u_strToJavaModifiedUTF8 = lib.func('__cdecl', 'u_strToJavaModifiedUTF8', 'void *', ['str', 'int32_t', 'int32_t *', 'uint16_t *', 'int32_t', 'int32_t *']);
// u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
// dest : LPSTR -> 'str'
// destCapacity : INT -> 'int32_t'
// pDestLength : INT* in/out -> '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", {
  u_strToJavaModifiedUTF8: { parameters: ["buffer", "i32", "pointer", "pointer", "i32", "pointer"], result: "pointer" },
});
// lib.symbols.u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode)
// dest : LPSTR -> "buffer"
// destCapacity : INT -> "i32"
// pDestLength : INT* in/out -> "pointer"
// src : WORD* -> "pointer"
// srcLength : INT -> "i32"
// pErrorCode : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
const char* u_strToJavaModifiedUTF8(
    const char* dest,
    int32_t destCapacity,
    int32_t* pDestLength,
    uint16_t* src,
    int32_t srcLength,
    int32_t* pErrorCode);
C, "icuuc.dll");
// $ffi->u_strToJavaModifiedUTF8(dest, destCapacity, pDestLength, src, srcLength, pErrorCode);
// dest : LPSTR
// destCapacity : INT
// pDestLength : INT* in/out
// 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);
    Pointer u_strToJavaModifiedUTF8(
        String dest,   // LPSTR
        int destCapacity,   // INT
        IntByReference pDestLength,   // INT* in/out
        ShortByReference src,   // WORD*
        int srcLength,   // INT
        IntByReference pErrorCode   // UErrorCode* in/out
    );
}
@[Link("icuuc")]
lib Libicuuc
  fun u_strToJavaModifiedUTF8 = u_strToJavaModifiedUTF8(
    dest : UInt8*,   # LPSTR
    destCapacity : Int32,   # INT
    pDestLength : Int32*,   # INT* in/out
    src : UInt16*,   # WORD*
    srcLength : Int32,   # INT
    pErrorCode : Int32*   # UErrorCode* in/out
  ) : UInt8*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef u_strToJavaModifiedUTF8Native = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Int32>, Pointer<Uint16>, Int32, Pointer<Int32>);
typedef u_strToJavaModifiedUTF8Dart = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Int32>, Pointer<Uint16>, int, Pointer<Int32>);
final u_strToJavaModifiedUTF8 = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<u_strToJavaModifiedUTF8Native, u_strToJavaModifiedUTF8Dart>('u_strToJavaModifiedUTF8');
// dest : LPSTR -> Pointer<Utf8>
// destCapacity : INT -> Int32
// pDestLength : INT* in/out -> Pointer<Int32>
// src : WORD* -> Pointer<Uint16>
// srcLength : INT -> Int32
// pErrorCode : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function u_strToJavaModifiedUTF8(
  dest: PAnsiChar;   // LPSTR
  destCapacity: Integer;   // INT
  pDestLength: Pointer;   // INT* in/out
  src: Pointer;   // WORD*
  srcLength: Integer;   // INT
  pErrorCode: Pointer   // UErrorCode* in/out
): PAnsiChar; cdecl;
  external 'icuuc.dll' name 'u_strToJavaModifiedUTF8';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "u_strToJavaModifiedUTF8"
  c_u_strToJavaModifiedUTF8 :: CString -> Int32 -> Ptr Int32 -> Ptr Word16 -> Int32 -> Ptr Int32 -> IO CString
-- dest : LPSTR -> CString
-- destCapacity : INT -> Int32
-- pDestLength : INT* in/out -> Ptr 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 u_strtojavamodifiedutf8 =
  foreign "u_strToJavaModifiedUTF8"
    (string @-> int32_t @-> (ptr int32_t) @-> (ptr uint16_t) @-> int32_t @-> (ptr int32_t) @-> returning string)
(* dest : LPSTR -> string *)
(* destCapacity : INT -> int32_t *)
(* pDestLength : INT* in/out -> (ptr 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 ("u_strToJavaModifiedUTF8" u-str-to-java-modified-utf8 :convention :cdecl) :string
  (dest :string)   ; LPSTR
  (dest-capacity :int32)   ; INT
  (p-dest-length :pointer)   ; INT* in/out
  (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 $u_strToJavaModifiedUTF8 = Win32::API::More->new('icuuc',
    'LPSTR u_strToJavaModifiedUTF8(LPCSTR dest, int destCapacity, LPVOID pDestLength, LPVOID src, int srcLength, LPVOID pErrorCode)');
# my $ret = $u_strToJavaModifiedUTF8->Call($dest, $destCapacity, $pDestLength, $src, $srcLength, $pErrorCode);
# dest : LPSTR -> LPCSTR
# destCapacity : INT -> int
# pDestLength : INT* in/out -> LPVOID
# src : WORD* -> LPVOID
# srcLength : INT -> int
# pErrorCode : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型