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

ures_getStringByKey

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

シグネチャ

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

WORD* ures_getStringByKey(
    const UResourceBundle* resB,
    LPCSTR key,
    INT* len,
    UErrorCode* status
);

パラメーター

名前方向説明
resBUResourceBundle*in親となるリソースバンドル(テーブル)。
keyLPCSTRin取得する文字列のキー名。
lenINT*inout返す文字列の長さを格納する出力ポインタ。NULL可。
statusUErrorCode*inoutICUエラーコードを受け渡すポインタ。U_ZERO_ERRORへ初期化が必要。

戻り値の型: WORD*

各言語での呼び出し定義

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

WORD* ures_getStringByKey(
    const UResourceBundle* resB,
    LPCSTR key,
    INT* len,
    UErrorCode* status
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr ures_getStringByKey(
    ref IntPtr resB,   // UResourceBundle*
    [MarshalAs(UnmanagedType.LPStr)] string key,   // LPCSTR
    ref int len,   // INT* in/out
    ref int status   // UErrorCode* in/out
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ures_getStringByKey(
    ByRef resB As IntPtr,   ' UResourceBundle*
    <MarshalAs(UnmanagedType.LPStr)> key As String,   ' LPCSTR
    ByRef len As Integer,   ' INT* in/out
    ByRef status As Integer   ' UErrorCode* in/out
) As IntPtr
End Function
' resB : UResourceBundle*
' key : LPCSTR
' len : INT* in/out
' status : UErrorCode* in/out
Declare PtrSafe Function ures_getStringByKey Lib "icuuc" ( _
    ByRef resB As LongPtr, _
    ByVal key As String, _
    ByRef len As Long, _
    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_getStringByKey = ctypes.cdll.icuuc.ures_getStringByKey
ures_getStringByKey.restype = ctypes.c_void_p
ures_getStringByKey.argtypes = [
    ctypes.c_void_p,  # resB : UResourceBundle*
    wintypes.LPCSTR,  # key : LPCSTR
    ctypes.POINTER(ctypes.c_int),  # len : INT* in/out
    ctypes.c_void_p,  # status : UErrorCode* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procures_getStringByKey = icuuc.NewProc("ures_getStringByKey")
)

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

typedef ures_getStringByKeyNative = Pointer<Uint16> Function(Pointer<IntPtr>, Pointer<Utf8>, Pointer<Int32>, Pointer<Int32>);
typedef ures_getStringByKeyDart = Pointer<Uint16> Function(Pointer<IntPtr>, Pointer<Utf8>, Pointer<Int32>, Pointer<Int32>);
final ures_getStringByKey = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<ures_getStringByKeyNative, ures_getStringByKeyDart>('ures_getStringByKey');
// resB : UResourceBundle* -> Pointer<IntPtr>
// key : LPCSTR -> Pointer<Utf8>
// len : INT* in/out -> Pointer<Int32>
// status : UErrorCode* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ures_getStringByKey(
  resB: Pointer;   // UResourceBundle*
  key: PAnsiChar;   // LPCSTR
  len: Pointer;   // INT* in/out
  status: Pointer   // UErrorCode* in/out
): Pointer; cdecl;
  external 'icuuc.dll' name 'ures_getStringByKey';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ures_getStringByKey"
  c_ures_getStringByKey :: Ptr CIntPtr -> CString -> Ptr Int32 -> Ptr Int32 -> IO (Ptr Word16)
-- resB : UResourceBundle* -> Ptr CIntPtr
-- key : LPCSTR -> CString
-- len : INT* in/out -> Ptr Int32
-- status : UErrorCode* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ures_getstringbykey =
  foreign "ures_getStringByKey"
    ((ptr intptr_t) @-> string @-> (ptr int32_t) @-> (ptr int32_t) @-> returning (ptr uint16_t))
(* resB : UResourceBundle* -> (ptr intptr_t) *)
(* key : LPCSTR -> string *)
(* len : INT* in/out -> (ptr int32_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_getStringByKey" ures-get-string-by-key :convention :cdecl) :pointer
  (res-b :pointer)   ; UResourceBundle*
  (key :string)   ; LPCSTR
  (len :pointer)   ; INT* in/out
  (status :pointer))   ; UErrorCode* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ures_getStringByKey = Win32::API::More->new('icuuc',
    'LPVOID ures_getStringByKey(LPVOID resB, LPCSTR key, LPVOID len, LPVOID status)');
# my $ret = $ures_getStringByKey->Call($resB, $key, $len, $status);
# resB : UResourceBundle* -> LPVOID
# key : LPCSTR -> LPCSTR
# len : INT* in/out -> LPVOID
# status : UErrorCode* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型