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

utext_openUTF8

関数
UTF-8文字列に対するUTextを開く。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

UText* utext_openUTF8(
    UText* ut,
    LPCSTR s,
    LONGLONG length,
    UErrorCode* status
);

パラメーター

名前方向説明
utUText*inout再利用するUTextオブジェクトへのポインタ。NULLなら新規確保される。
sLPCSTRinUTextでラップする対象のUTF-8文字列へのポインタ。
lengthLONGLONGinsの長さ(バイト数)。NUL終端なら-1を指定できる。
statusUErrorCode*inoutICUのエラーコードを受け渡すポインタ。呼び出し前にU_ZERO_ERRORで初期化する。

戻り値の型: UText*

各言語での呼び出し定義

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

UText* utext_openUTF8(
    UText* ut,
    LPCSTR s,
    LONGLONG length,
    UErrorCode* status
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr utext_openUTF8(
    IntPtr ut,   // UText* in/out
    [MarshalAs(UnmanagedType.LPStr)] string s,   // LPCSTR
    long length,   // LONGLONG
    ref int status   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function utext_openUTF8(
    ut As IntPtr,   ' UText* in/out
    <MarshalAs(UnmanagedType.LPStr)> s As String,   ' LPCSTR
    length As Long,   ' LONGLONG
    ByRef status As Integer   ' UErrorCode* in/out
) As IntPtr
End Function
' ut : UText* in/out
' s : LPCSTR
' length : LONGLONG
' status : UErrorCode* in/out
Declare PtrSafe Function utext_openUTF8 Lib "icuuc" ( _
    ByVal ut As LongPtr, _
    ByVal s As String, _
    ByVal length As LongLong, _
    ByRef status As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

utext_openUTF8 = ctypes.cdll.icuuc.utext_openUTF8
utext_openUTF8.restype = ctypes.c_void_p
utext_openUTF8.argtypes = [
    ctypes.c_void_p,  # ut : UText* in/out
    wintypes.LPCSTR,  # s : LPCSTR
    ctypes.c_longlong,  # length : LONGLONG
    ctypes.c_void_p,  # status : UErrorCode* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
utext_openUTF8 = Fiddle::Function.new(
  lib['utext_openUTF8'],
  [
    Fiddle::TYPE_VOIDP,  # ut : UText* in/out
    Fiddle::TYPE_VOIDP,  # s : LPCSTR
    Fiddle::TYPE_LONG_LONG,  # length : LONGLONG
    Fiddle::TYPE_VOIDP,  # status : UErrorCode* in/out
  ],
  Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn utext_openUTF8(
        ut: *mut UText,  // UText* in/out
        s: *const u8,  // LPCSTR
        length: i64,  // LONGLONG
        status: *mut i32  // UErrorCode* in/out
    ) -> *mut UText;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr utext_openUTF8(IntPtr ut, [MarshalAs(UnmanagedType.LPStr)] string s, long length, ref int status);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_utext_openUTF8' -Namespace Win32 -PassThru
# $api::utext_openUTF8(ut, s, length, status)
#uselib "icuuc.dll"
#func global utext_openUTF8 "utext_openUTF8" sptr, sptr, sptr, sptr
; utext_openUTF8 varptr(ut), s, length, varptr(status)   ; 戻り値は stat
; ut : UText* in/out -> "sptr"
; s : LPCSTR -> "sptr"
; length : LONGLONG -> "sptr"
; status : UErrorCode* in/out -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "icuuc.dll"
#cfunc global utext_openUTF8 "utext_openUTF8" var, str, int64, var
; res = utext_openUTF8(ut, s, length, status)
; ut : UText* in/out -> "var"
; s : LPCSTR -> "str"
; length : LONGLONG -> "int64"
; status : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; UText* utext_openUTF8(UText* ut, LPCSTR s, LONGLONG length, UErrorCode* status)
#uselib "icuuc.dll"
#cfunc global utext_openUTF8 "utext_openUTF8" var, str, int64, var
; res = utext_openUTF8(ut, s, length, status)
; ut : UText* in/out -> "var"
; s : LPCSTR -> "str"
; length : LONGLONG -> "int64"
; status : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procutext_openUTF8 = icuuc.NewProc("utext_openUTF8")
)

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

typedef utext_openUTF8Native = Pointer<Void> Function(Pointer<Void>, Pointer<Utf8>, Int64, Pointer<Int32>);
typedef utext_openUTF8Dart = Pointer<Void> Function(Pointer<Void>, Pointer<Utf8>, int, Pointer<Int32>);
final utext_openUTF8 = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<utext_openUTF8Native, utext_openUTF8Dart>('utext_openUTF8');
// ut : UText* in/out -> Pointer<Void>
// s : LPCSTR -> Pointer<Utf8>
// length : LONGLONG -> Int64
// status : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function utext_openUTF8(
  ut: Pointer;   // UText* in/out
  s: PAnsiChar;   // LPCSTR
  length: Int64;   // LONGLONG
  status: Pointer   // UErrorCode* in/out
): Pointer; cdecl;
  external 'icuuc.dll' name 'utext_openUTF8';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "utext_openUTF8"
  c_utext_openUTF8 :: Ptr () -> CString -> Int64 -> Ptr Int32 -> IO (Ptr ())
-- ut : UText* in/out -> Ptr ()
-- s : LPCSTR -> CString
-- length : LONGLONG -> Int64
-- status : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let utext_openutf8 =
  foreign "utext_openUTF8"
    ((ptr void) @-> string @-> int64_t @-> (ptr int32_t) @-> returning (ptr void))
(* ut : UText* in/out -> (ptr void) *)
(* s : LPCSTR -> string *)
(* length : LONGLONG -> int64_t *)
(* status : 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 ("utext_openUTF8" utext-open-utf8 :convention :cdecl) :pointer
  (ut :pointer)   ; UText* in/out
  (s :string)   ; LPCSTR
  (length :int64)   ; LONGLONG
  (status :pointer))   ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $utext_openUTF8 = Win32::API::More->new('icuuc',
    'LPVOID utext_openUTF8(LPVOID ut, LPCSTR s, INT64 length, LPVOID status)');
# my $ret = $utext_openUTF8->Call($ut, $s, $length, $status);
# ut : UText* in/out -> LPVOID
# s : LPCSTR -> LPCSTR
# length : LONGLONG -> INT64
# status : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型