ホーム › Globalization › ures_getUTF8StringByIndex
ures_getUTF8StringByIndex
関数リソースバンドルからインデックス指定でUTF-8文字列を取得する。
シグネチャ
// icuuc.dll
#include <windows.h>
LPSTR ures_getUTF8StringByIndex(
const UResourceBundle* resB,
INT stringIndex,
LPSTR dest,
INT* pLength,
CHAR forceCopy,
UErrorCode* status
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| resB | UResourceBundle* | in | 親となるリソースバンドル。 |
| stringIndex | INT | in | 取得する文字列の0始まりインデックス。 |
| dest | LPSTR | in | UTF-8文字列を格納する出力バッファ。 |
| pLength | INT* | inout | 入力でdest容量、出力で実長を受け渡すポインタ。 |
| forceCopy | CHAR | in | 真なら常にdestへコピー、偽なら内部ポインタを返す場合がある。 |
| status | UErrorCode* | inout | ICUエラーコードを受け渡すポインタ。U_ZERO_ERRORへ初期化が必要。 |
戻り値の型: LPSTR
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
LPSTR ures_getUTF8StringByIndex(
const UResourceBundle* resB,
INT stringIndex,
LPSTR dest,
INT* pLength,
CHAR forceCopy,
UErrorCode* status
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ures_getUTF8StringByIndex(
ref IntPtr resB, // UResourceBundle*
int stringIndex, // INT
[MarshalAs(UnmanagedType.LPStr)] string dest, // LPSTR
ref int pLength, // INT* in/out
sbyte forceCopy, // CHAR
ref int status // UErrorCode* in/out
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ures_getUTF8StringByIndex(
ByRef resB As IntPtr, ' UResourceBundle*
stringIndex As Integer, ' INT
<MarshalAs(UnmanagedType.LPStr)> dest As String, ' LPSTR
ByRef pLength As Integer, ' INT* in/out
forceCopy As SByte, ' CHAR
ByRef status As Integer ' UErrorCode* in/out
) As IntPtr
End Function' resB : UResourceBundle*
' stringIndex : INT
' dest : LPSTR
' pLength : INT* in/out
' forceCopy : CHAR
' status : UErrorCode* in/out
Declare PtrSafe Function ures_getUTF8StringByIndex Lib "icuuc" ( _
ByRef resB As LongPtr, _
ByVal stringIndex As Long, _
ByVal dest As String, _
ByRef pLength As Long, _
ByVal forceCopy As Byte, _
ByRef status As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ures_getUTF8StringByIndex = ctypes.cdll.icuuc.ures_getUTF8StringByIndex
ures_getUTF8StringByIndex.restype = wintypes.LPSTR
ures_getUTF8StringByIndex.argtypes = [
ctypes.c_void_p, # resB : UResourceBundle*
ctypes.c_int, # stringIndex : INT
wintypes.LPCSTR, # dest : LPSTR
ctypes.POINTER(ctypes.c_int), # pLength : INT* in/out
ctypes.c_byte, # forceCopy : CHAR
ctypes.c_void_p, # status : UErrorCode* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
ures_getUTF8StringByIndex = Fiddle::Function.new(
lib['ures_getUTF8StringByIndex'],
[
Fiddle::TYPE_VOIDP, # resB : UResourceBundle*
Fiddle::TYPE_INT, # stringIndex : INT
Fiddle::TYPE_VOIDP, # dest : LPSTR
Fiddle::TYPE_VOIDP, # pLength : INT* in/out
Fiddle::TYPE_CHAR, # forceCopy : CHAR
Fiddle::TYPE_VOIDP, # status : UErrorCode* in/out
],
Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn ures_getUTF8StringByIndex(
resB: *const isize, // UResourceBundle*
stringIndex: i32, // INT
dest: *mut u8, // LPSTR
pLength: *mut i32, // INT* in/out
forceCopy: i8, // CHAR
status: *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 ures_getUTF8StringByIndex(ref IntPtr resB, int stringIndex, [MarshalAs(UnmanagedType.LPStr)] string dest, ref int pLength, sbyte forceCopy, ref int status);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ures_getUTF8StringByIndex' -Namespace Win32 -PassThru
# $api::ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status)#uselib "icuuc.dll"
#func global ures_getUTF8StringByIndex "ures_getUTF8StringByIndex" sptr, sptr, sptr, sptr, sptr, sptr
; ures_getUTF8StringByIndex varptr(resB), stringIndex, dest, varptr(pLength), forceCopy, varptr(status) ; 戻り値は stat
; resB : UResourceBundle* -> "sptr"
; stringIndex : INT -> "sptr"
; dest : LPSTR -> "sptr"
; pLength : INT* in/out -> "sptr"
; forceCopy : CHAR -> "sptr"
; status : UErrorCode* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global ures_getUTF8StringByIndex "ures_getUTF8StringByIndex" var, int, str, var, int, var ; res = ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status) ; resB : UResourceBundle* -> "var" ; stringIndex : INT -> "int" ; dest : LPSTR -> "str" ; pLength : INT* in/out -> "var" ; forceCopy : CHAR -> "int" ; status : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global ures_getUTF8StringByIndex "ures_getUTF8StringByIndex" sptr, int, str, sptr, int, sptr ; res = ures_getUTF8StringByIndex(varptr(resB), stringIndex, dest, varptr(pLength), forceCopy, varptr(status)) ; resB : UResourceBundle* -> "sptr" ; stringIndex : INT -> "int" ; dest : LPSTR -> "str" ; pLength : INT* in/out -> "sptr" ; forceCopy : CHAR -> "int" ; status : UErrorCode* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; LPSTR ures_getUTF8StringByIndex(UResourceBundle* resB, INT stringIndex, LPSTR dest, INT* pLength, CHAR forceCopy, UErrorCode* status) #uselib "icuuc.dll" #cfunc global ures_getUTF8StringByIndex "ures_getUTF8StringByIndex" var, int, str, var, int, var ; res = ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status) ; resB : UResourceBundle* -> "var" ; stringIndex : INT -> "int" ; dest : LPSTR -> "str" ; pLength : INT* in/out -> "var" ; forceCopy : CHAR -> "int" ; status : UErrorCode* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; LPSTR ures_getUTF8StringByIndex(UResourceBundle* resB, INT stringIndex, LPSTR dest, INT* pLength, CHAR forceCopy, UErrorCode* status) #uselib "icuuc.dll" #cfunc global ures_getUTF8StringByIndex "ures_getUTF8StringByIndex" intptr, int, str, intptr, int, intptr ; res = ures_getUTF8StringByIndex(varptr(resB), stringIndex, dest, varptr(pLength), forceCopy, varptr(status)) ; resB : UResourceBundle* -> "intptr" ; stringIndex : INT -> "int" ; dest : LPSTR -> "str" ; pLength : INT* in/out -> "intptr" ; forceCopy : CHAR -> "int" ; status : UErrorCode* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procures_getUTF8StringByIndex = icuuc.NewProc("ures_getUTF8StringByIndex")
)
// resB (UResourceBundle*), stringIndex (INT), dest (LPSTR), pLength (INT* in/out), forceCopy (CHAR), status (UErrorCode* in/out)
r1, _, err := procures_getUTF8StringByIndex.Call(
uintptr(resB),
uintptr(stringIndex),
uintptr(unsafe.Pointer(windows.BytePtrFromString(dest))),
uintptr(pLength),
uintptr(forceCopy),
uintptr(status),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LPSTRfunction ures_getUTF8StringByIndex(
resB: Pointer; // UResourceBundle*
stringIndex: Integer; // INT
dest: PAnsiChar; // LPSTR
pLength: Pointer; // INT* in/out
forceCopy: Shortint; // CHAR
status: Pointer // UErrorCode* in/out
): PAnsiChar; cdecl;
external 'icuuc.dll' name 'ures_getUTF8StringByIndex';result := DllCall("icuuc\ures_getUTF8StringByIndex"
, "Ptr", resB ; UResourceBundle*
, "Int", stringIndex ; INT
, "AStr", dest ; LPSTR
, "Ptr", pLength ; INT* in/out
, "Char", forceCopy ; CHAR
, "Ptr", status ; UErrorCode* in/out
, "Cdecl Ptr") ; return: LPSTR●ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status) = DLL("icuuc.dll", "char* ures_getUTF8StringByIndex(void*, int, char*, void*, char, void*)")
# 呼び出し: ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status)
# resB : UResourceBundle* -> "void*"
# stringIndex : INT -> "int"
# dest : LPSTR -> "char*"
# pLength : INT* in/out -> "void*"
# forceCopy : CHAR -> "char"
# 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 ures_getUTF8StringByIndex(
resB: [*c]isize, // UResourceBundle*
stringIndex: i32, // INT
dest: [*c]const u8, // LPSTR
pLength: [*c]i32, // INT* in/out
forceCopy: i8, // CHAR
status: [*c]i32 // UErrorCode* in/out
) callconv(.c) [*c]const u8;proc ures_getUTF8StringByIndex(
resB: ptr int, # UResourceBundle*
stringIndex: int32, # INT
dest: cstring, # LPSTR
pLength: ptr int32, # INT* in/out
forceCopy: int8, # CHAR
status: ptr int32 # UErrorCode* in/out
): cstring {.importc: "ures_getUTF8StringByIndex", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
const(char)* ures_getUTF8StringByIndex(
ptrdiff_t* resB, // UResourceBundle*
int stringIndex, // INT
const(char)* dest, // LPSTR
int* pLength, // INT* in/out
byte forceCopy, // CHAR
int* status // UErrorCode* in/out
);ccall((:ures_getUTF8StringByIndex, "icuuc.dll"), Cstring,
(Ptr{Int}, Int32, Cstring, Ptr{Int32}, Int8, Ptr{Int32}),
resB, stringIndex, dest, pLength, forceCopy, status)
# resB : UResourceBundle* -> Ptr{Int}
# stringIndex : INT -> Int32
# dest : LPSTR -> Cstring
# pLength : INT* in/out -> Ptr{Int32}
# forceCopy : CHAR -> Int8
# status : UErrorCode* in/out -> Ptr{Int32}local ffi = require("ffi")
ffi.cdef[[
const char* ures_getUTF8StringByIndex(
intptr_t* resB,
int32_t stringIndex,
const char* dest,
int32_t* pLength,
int8_t forceCopy,
int32_t* status);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status)
-- resB : UResourceBundle*
-- stringIndex : INT
-- dest : LPSTR
-- pLength : INT* in/out
-- forceCopy : CHAR
-- status : UErrorCode* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const ures_getUTF8StringByIndex = lib.func('__cdecl', 'ures_getUTF8StringByIndex', 'void *', ['intptr_t *', 'int32_t', 'str', 'int32_t *', 'int8_t', 'int32_t *']);
// ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status)
// resB : UResourceBundle* -> 'intptr_t *'
// stringIndex : INT -> 'int32_t'
// dest : LPSTR -> 'str'
// pLength : INT* in/out -> 'int32_t *'
// forceCopy : CHAR -> 'int8_t'
// status : UErrorCode* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
ures_getUTF8StringByIndex: { parameters: ["pointer", "i32", "buffer", "pointer", "i8", "pointer"], result: "pointer" },
});
// lib.symbols.ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status)
// resB : UResourceBundle* -> "pointer"
// stringIndex : INT -> "i32"
// dest : LPSTR -> "buffer"
// pLength : INT* in/out -> "pointer"
// forceCopy : CHAR -> "i8"
// status : UErrorCode* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
const char* ures_getUTF8StringByIndex(
intptr_t* resB,
int32_t stringIndex,
const char* dest,
int32_t* pLength,
int8_t forceCopy,
int32_t* status);
C, "icuuc.dll");
// $ffi->ures_getUTF8StringByIndex(resB, stringIndex, dest, pLength, forceCopy, status);
// resB : UResourceBundle*
// stringIndex : INT
// dest : LPSTR
// pLength : INT* in/out
// forceCopy : CHAR
// 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 ures_getUTF8StringByIndex(
LongByReference resB, // UResourceBundle*
int stringIndex, // INT
String dest, // LPSTR
IntByReference pLength, // INT* in/out
byte forceCopy, // CHAR
IntByReference status // UErrorCode* in/out
);
}@[Link("icuuc")]
lib Libicuuc
fun ures_getUTF8StringByIndex = ures_getUTF8StringByIndex(
resB : LibC::SSizeT*, # UResourceBundle*
stringIndex : Int32, # INT
dest : UInt8*, # LPSTR
pLength : Int32*, # INT* in/out
forceCopy : Int8, # CHAR
status : Int32* # UErrorCode* in/out
) : UInt8*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ures_getUTF8StringByIndexNative = Pointer<Utf8> Function(Pointer<IntPtr>, Int32, Pointer<Utf8>, Pointer<Int32>, Int8, Pointer<Int32>);
typedef ures_getUTF8StringByIndexDart = Pointer<Utf8> Function(Pointer<IntPtr>, int, Pointer<Utf8>, Pointer<Int32>, int, Pointer<Int32>);
final ures_getUTF8StringByIndex = DynamicLibrary.open('icuuc.dll')
.lookupFunction<ures_getUTF8StringByIndexNative, ures_getUTF8StringByIndexDart>('ures_getUTF8StringByIndex');
// resB : UResourceBundle* -> Pointer<IntPtr>
// stringIndex : INT -> Int32
// dest : LPSTR -> Pointer<Utf8>
// pLength : INT* in/out -> Pointer<Int32>
// forceCopy : CHAR -> Int8
// status : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ures_getUTF8StringByIndex(
resB: Pointer; // UResourceBundle*
stringIndex: Integer; // INT
dest: PAnsiChar; // LPSTR
pLength: Pointer; // INT* in/out
forceCopy: Shortint; // CHAR
status: Pointer // UErrorCode* in/out
): PAnsiChar; cdecl;
external 'icuuc.dll' name 'ures_getUTF8StringByIndex';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ures_getUTF8StringByIndex"
c_ures_getUTF8StringByIndex :: Ptr CIntPtr -> Int32 -> CString -> Ptr Int32 -> Int8 -> Ptr Int32 -> IO CString
-- resB : UResourceBundle* -> Ptr CIntPtr
-- stringIndex : INT -> Int32
-- dest : LPSTR -> CString
-- pLength : INT* in/out -> Ptr Int32
-- forceCopy : CHAR -> Int8
-- status : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ures_getutf8stringbyindex =
foreign "ures_getUTF8StringByIndex"
((ptr intptr_t) @-> int32_t @-> string @-> (ptr int32_t) @-> int8_t @-> (ptr int32_t) @-> returning string)
(* resB : UResourceBundle* -> (ptr intptr_t) *)
(* stringIndex : INT -> int32_t *)
(* dest : LPSTR -> string *)
(* pLength : INT* in/out -> (ptr int32_t) *)
(* forceCopy : CHAR -> int8_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 ("ures_getUTF8StringByIndex" ures-get-utf8-string-by-index :convention :cdecl) :string
(res-b :pointer) ; UResourceBundle*
(string-index :int32) ; INT
(dest :string) ; LPSTR
(p-length :pointer) ; INT* in/out
(force-copy :int8) ; CHAR
(status :pointer)) ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ures_getUTF8StringByIndex = Win32::API::More->new('icuuc',
'LPSTR ures_getUTF8StringByIndex(LPVOID resB, int stringIndex, LPCSTR dest, LPVOID pLength, char forceCopy, LPVOID status)');
# my $ret = $ures_getUTF8StringByIndex->Call($resB, $stringIndex, $dest, $pLength, $forceCopy, $status);
# resB : UResourceBundle* -> LPVOID
# stringIndex : INT -> int
# dest : LPSTR -> LPCSTR
# pLength : INT* in/out -> LPVOID
# forceCopy : CHAR -> char
# status : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型