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

ures_getUTF8StringByKey

関数
リソースバンドルからキー指定でUTF-8文字列を取得する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

LPSTR ures_getUTF8StringByKey(
    const UResourceBundle* resB,
    LPCSTR key,
    LPSTR dest,
    INT* pLength,
    CHAR forceCopy,
    UErrorCode* status
);

パラメーター

名前方向説明
resBUResourceBundle*in親となるリソースバンドル(テーブル)。
keyLPCSTRin取得する文字列のキー名。
destLPSTRinUTF-8文字列を格納する出力バッファ。
pLengthINT*inout入力でdest容量、出力で実長を受け渡すポインタ。
forceCopyCHARin真なら常にdestへコピー、偽なら内部ポインタを返す場合がある。
statusUErrorCode*inoutICUエラーコードを受け渡すポインタ。U_ZERO_ERRORへ初期化が必要。

戻り値の型: LPSTR

各言語での呼び出し定義

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

LPSTR ures_getUTF8StringByKey(
    const UResourceBundle* resB,
    LPCSTR key,
    LPSTR dest,
    INT* pLength,
    CHAR forceCopy,
    UErrorCode* status
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ures_getUTF8StringByKey(
    ref IntPtr resB,   // UResourceBundle*
    [MarshalAs(UnmanagedType.LPStr)] string key,   // LPCSTR
    [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_getUTF8StringByKey(
    ByRef resB As IntPtr,   ' UResourceBundle*
    <MarshalAs(UnmanagedType.LPStr)> key As String,   ' LPCSTR
    <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*
' key : LPCSTR
' dest : LPSTR
' pLength : INT* in/out
' forceCopy : CHAR
' status : UErrorCode* in/out
Declare PtrSafe Function ures_getUTF8StringByKey Lib "icuuc" ( _
    ByRef resB As LongPtr, _
    ByVal key As String, _
    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_getUTF8StringByKey = ctypes.cdll.icuuc.ures_getUTF8StringByKey
ures_getUTF8StringByKey.restype = wintypes.LPSTR
ures_getUTF8StringByKey.argtypes = [
    ctypes.c_void_p,  # resB : UResourceBundle*
    wintypes.LPCSTR,  # key : LPCSTR
    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_getUTF8StringByKey = Fiddle::Function.new(
  lib['ures_getUTF8StringByKey'],
  [
    Fiddle::TYPE_VOIDP,  # resB : UResourceBundle*
    Fiddle::TYPE_VOIDP,  # key : LPCSTR
    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_getUTF8StringByKey(
        resB: *const isize,  // UResourceBundle*
        key: *const u8,  // LPCSTR
        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_getUTF8StringByKey(ref IntPtr resB, [MarshalAs(UnmanagedType.LPStr)] string key, [MarshalAs(UnmanagedType.LPStr)] string dest, ref int pLength, sbyte forceCopy, ref int status);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_ures_getUTF8StringByKey' -Namespace Win32 -PassThru
# $api::ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status)
#uselib "icuuc.dll"
#func global ures_getUTF8StringByKey "ures_getUTF8StringByKey" sptr, sptr, sptr, sptr, sptr, sptr
; ures_getUTF8StringByKey varptr(resB), key, dest, varptr(pLength), forceCopy, varptr(status)   ; 戻り値は stat
; resB : UResourceBundle* -> "sptr"
; key : LPCSTR -> "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_getUTF8StringByKey "ures_getUTF8StringByKey" var, str, str, var, int, var
; res = ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status)
; resB : UResourceBundle* -> "var"
; key : LPCSTR -> "str"
; dest : LPSTR -> "str"
; pLength : INT* in/out -> "var"
; forceCopy : CHAR -> "int"
; status : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; LPSTR ures_getUTF8StringByKey(UResourceBundle* resB, LPCSTR key, LPSTR dest, INT* pLength, CHAR forceCopy, UErrorCode* status)
#uselib "icuuc.dll"
#cfunc global ures_getUTF8StringByKey "ures_getUTF8StringByKey" var, str, str, var, int, var
; res = ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status)
; resB : UResourceBundle* -> "var"
; key : LPCSTR -> "str"
; dest : LPSTR -> "str"
; pLength : INT* in/out -> "var"
; forceCopy : CHAR -> "int"
; status : UErrorCode* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procures_getUTF8StringByKey = icuuc.NewProc("ures_getUTF8StringByKey")
)

// resB (UResourceBundle*), key (LPCSTR), dest (LPSTR), pLength (INT* in/out), forceCopy (CHAR), status (UErrorCode* in/out)
r1, _, err := procures_getUTF8StringByKey.Call(
	uintptr(resB),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(key))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(dest))),
	uintptr(pLength),
	uintptr(forceCopy),
	uintptr(status),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPSTR
function ures_getUTF8StringByKey(
  resB: Pointer;   // UResourceBundle*
  key: PAnsiChar;   // LPCSTR
  dest: PAnsiChar;   // LPSTR
  pLength: Pointer;   // INT* in/out
  forceCopy: Shortint;   // CHAR
  status: Pointer   // UErrorCode* in/out
): PAnsiChar; cdecl;
  external 'icuuc.dll' name 'ures_getUTF8StringByKey';
result := DllCall("icuuc\ures_getUTF8StringByKey"
    , "Ptr", resB   ; UResourceBundle*
    , "AStr", key   ; LPCSTR
    , "AStr", dest   ; LPSTR
    , "Ptr", pLength   ; INT* in/out
    , "Char", forceCopy   ; CHAR
    , "Ptr", status   ; UErrorCode* in/out
    , "Cdecl Ptr")   ; return: LPSTR
●ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status) = DLL("icuuc.dll", "char* ures_getUTF8StringByKey(void*, char*, char*, void*, char, void*)")
# 呼び出し: ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status)
# resB : UResourceBundle* -> "void*"
# key : LPCSTR -> "char*"
# 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_getUTF8StringByKey(
    resB: [*c]isize, // UResourceBundle*
    key: [*c]const u8, // LPCSTR
    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_getUTF8StringByKey(
    resB: ptr int,  # UResourceBundle*
    key: cstring,  # LPCSTR
    dest: cstring,  # LPSTR
    pLength: ptr int32,  # INT* in/out
    forceCopy: int8,  # CHAR
    status: ptr int32  # UErrorCode* in/out
): cstring {.importc: "ures_getUTF8StringByKey", cdecl, dynlib: "icuuc.dll".}
pragma(lib, "icuuc");
extern(C)
const(char)* ures_getUTF8StringByKey(
    ptrdiff_t* resB,   // UResourceBundle*
    const(char)* key,   // LPCSTR
    const(char)* dest,   // LPSTR
    int* pLength,   // INT* in/out
    byte forceCopy,   // CHAR
    int* status   // UErrorCode* in/out
);
ccall((:ures_getUTF8StringByKey, "icuuc.dll"), Cstring,
      (Ptr{Int}, Cstring, Cstring, Ptr{Int32}, Int8, Ptr{Int32}),
      resB, key, dest, pLength, forceCopy, status)
# resB : UResourceBundle* -> Ptr{Int}
# key : LPCSTR -> Cstring
# 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_getUTF8StringByKey(
    intptr_t* resB,
    const char* key,
    const char* dest,
    int32_t* pLength,
    int8_t forceCopy,
    int32_t* status);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status)
-- resB : UResourceBundle*
-- key : LPCSTR
-- 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_getUTF8StringByKey = lib.func('__cdecl', 'ures_getUTF8StringByKey', 'void *', ['intptr_t *', 'str', 'str', 'int32_t *', 'int8_t', 'int32_t *']);
// ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status)
// resB : UResourceBundle* -> 'intptr_t *'
// key : LPCSTR -> 'str'
// 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_getUTF8StringByKey: { parameters: ["pointer", "buffer", "buffer", "pointer", "i8", "pointer"], result: "pointer" },
});
// lib.symbols.ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status)
// resB : UResourceBundle* -> "pointer"
// key : LPCSTR -> "buffer"
// 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_getUTF8StringByKey(
    intptr_t* resB,
    const char* key,
    const char* dest,
    int32_t* pLength,
    int8_t forceCopy,
    int32_t* status);
C, "icuuc.dll");
// $ffi->ures_getUTF8StringByKey(resB, key, dest, pLength, forceCopy, status);
// resB : UResourceBundle*
// key : LPCSTR
// 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_getUTF8StringByKey(
        LongByReference resB,   // UResourceBundle*
        String key,   // LPCSTR
        String dest,   // LPSTR
        IntByReference pLength,   // INT* in/out
        byte forceCopy,   // CHAR
        IntByReference status   // UErrorCode* in/out
    );
}
@[Link("icuuc")]
lib Libicuuc
  fun ures_getUTF8StringByKey = ures_getUTF8StringByKey(
    resB : LibC::SSizeT*,   # UResourceBundle*
    key : UInt8*,   # LPCSTR
    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_getUTF8StringByKeyNative = Pointer<Utf8> Function(Pointer<IntPtr>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Int32>, Int8, Pointer<Int32>);
typedef ures_getUTF8StringByKeyDart = Pointer<Utf8> Function(Pointer<IntPtr>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Int32>, int, Pointer<Int32>);
final ures_getUTF8StringByKey = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<ures_getUTF8StringByKeyNative, ures_getUTF8StringByKeyDart>('ures_getUTF8StringByKey');
// resB : UResourceBundle* -> Pointer<IntPtr>
// key : LPCSTR -> Pointer<Utf8>
// 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_getUTF8StringByKey(
  resB: Pointer;   // UResourceBundle*
  key: PAnsiChar;   // LPCSTR
  dest: PAnsiChar;   // LPSTR
  pLength: Pointer;   // INT* in/out
  forceCopy: Shortint;   // CHAR
  status: Pointer   // UErrorCode* in/out
): PAnsiChar; cdecl;
  external 'icuuc.dll' name 'ures_getUTF8StringByKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ures_getUTF8StringByKey"
  c_ures_getUTF8StringByKey :: Ptr CIntPtr -> CString -> CString -> Ptr Int32 -> Int8 -> Ptr Int32 -> IO CString
-- resB : UResourceBundle* -> Ptr CIntPtr
-- key : LPCSTR -> CString
-- 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_getutf8stringbykey =
  foreign "ures_getUTF8StringByKey"
    ((ptr intptr_t) @-> string @-> string @-> (ptr int32_t) @-> int8_t @-> (ptr int32_t) @-> returning string)
(* resB : UResourceBundle* -> (ptr intptr_t) *)
(* key : LPCSTR -> string *)
(* 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_getUTF8StringByKey" ures-get-utf8-string-by-key :convention :cdecl) :string
  (res-b :pointer)   ; UResourceBundle*
  (key :string)   ; LPCSTR
  (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_getUTF8StringByKey = Win32::API::More->new('icuuc',
    'LPSTR ures_getUTF8StringByKey(LPVOID resB, LPCSTR key, LPCSTR dest, LPVOID pLength, char forceCopy, LPVOID status)');
# my $ret = $ures_getUTF8StringByKey->Call($resB, $key, $dest, $pLength, $forceCopy, $status);
# resB : UResourceBundle* -> LPVOID
# key : LPCSTR -> LPCSTR
# dest : LPSTR -> LPCSTR
# pLength : INT* in/out -> LPVOID
# forceCopy : CHAR -> char
# status : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型