ホーム › Globalization › u_charsToUChars
u_charsToUChars
関数ASCII文字列をUChar配列に変換する。
シグネチャ
// icuuc.dll
#include <windows.h>
void u_charsToUChars(
LPCSTR cs,
WORD* us,
INT length
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| cs | LPCSTR | in | 変換元の不変ASCII(char)文字列へのポインタ。 |
| us | WORD* | inout | 変換後のUTF-16(UChar)を書き込む出力バッファへのポインタ。 |
| length | INT | in | 変換する文字数。NUL終端の自動判定はしない。 |
戻り値の型: void
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
void u_charsToUChars(
LPCSTR cs,
WORD* us,
INT length
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void u_charsToUChars(
[MarshalAs(UnmanagedType.LPStr)] string cs, // LPCSTR
ref ushort us, // WORD* in/out
int length // INT
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub u_charsToUChars(
<MarshalAs(UnmanagedType.LPStr)> cs As String, ' LPCSTR
ByRef us As UShort, ' WORD* in/out
length As Integer ' INT
)
End Sub' cs : LPCSTR
' us : WORD* in/out
' length : INT
Declare PtrSafe Sub u_charsToUChars Lib "icuuc" ( _
ByVal cs As String, _
ByRef us As Integer, _
ByVal length As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
u_charsToUChars = ctypes.cdll.icuuc.u_charsToUChars
u_charsToUChars.restype = None
u_charsToUChars.argtypes = [
wintypes.LPCSTR, # cs : LPCSTR
ctypes.POINTER(ctypes.c_ushort), # us : WORD* in/out
ctypes.c_int, # length : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
u_charsToUChars = Fiddle::Function.new(
lib['u_charsToUChars'],
[
Fiddle::TYPE_VOIDP, # cs : LPCSTR
Fiddle::TYPE_VOIDP, # us : WORD* in/out
Fiddle::TYPE_INT, # length : INT
],
Fiddle::TYPE_VOID, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn u_charsToUChars(
cs: *const u8, // LPCSTR
us: *mut u16, // WORD* in/out
length: i32 // INT
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void u_charsToUChars([MarshalAs(UnmanagedType.LPStr)] string cs, ref ushort us, int length);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_charsToUChars' -Namespace Win32 -PassThru
# $api::u_charsToUChars(cs, us, length)#uselib "icuuc.dll"
#func global u_charsToUChars "u_charsToUChars" sptr, sptr, sptr
; u_charsToUChars cs, varptr(us), length
; cs : LPCSTR -> "sptr"
; us : WORD* in/out -> "sptr"
; length : INT -> "sptr"出力引数:
#uselib "icuuc.dll" #func global u_charsToUChars "u_charsToUChars" str, var, int ; u_charsToUChars cs, us, length ; cs : LPCSTR -> "str" ; us : WORD* in/out -> "var" ; length : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #func global u_charsToUChars "u_charsToUChars" str, sptr, int ; u_charsToUChars cs, varptr(us), length ; cs : LPCSTR -> "str" ; us : WORD* in/out -> "sptr" ; length : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void u_charsToUChars(LPCSTR cs, WORD* us, INT length) #uselib "icuuc.dll" #func global u_charsToUChars "u_charsToUChars" str, var, int ; u_charsToUChars cs, us, length ; cs : LPCSTR -> "str" ; us : WORD* in/out -> "var" ; length : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void u_charsToUChars(LPCSTR cs, WORD* us, INT length) #uselib "icuuc.dll" #func global u_charsToUChars "u_charsToUChars" str, intptr, int ; u_charsToUChars cs, varptr(us), length ; cs : LPCSTR -> "str" ; us : WORD* in/out -> "intptr" ; length : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procu_charsToUChars = icuuc.NewProc("u_charsToUChars")
)
// cs (LPCSTR), us (WORD* in/out), length (INT)
r1, _, err := procu_charsToUChars.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(cs))),
uintptr(us),
uintptr(length),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure u_charsToUChars(
cs: PAnsiChar; // LPCSTR
us: Pointer; // WORD* in/out
length: Integer // INT
); cdecl;
external 'icuuc.dll' name 'u_charsToUChars';result := DllCall("icuuc\u_charsToUChars"
, "AStr", cs ; LPCSTR
, "Ptr", us ; WORD* in/out
, "Int", length ; INT
, "Cdecl Int") ; return: void●u_charsToUChars(cs, us, length) = DLL("icuuc.dll", "int u_charsToUChars(char*, void*, int)")
# 呼び出し: u_charsToUChars(cs, us, length)
# cs : LPCSTR -> "char*"
# us : WORD* in/out -> "void*"
# length : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "icuuc" fn u_charsToUChars(
cs: [*c]const u8, // LPCSTR
us: [*c]u16, // WORD* in/out
length: i32 // INT
) callconv(.c) void;proc u_charsToUChars(
cs: cstring, # LPCSTR
us: ptr uint16, # WORD* in/out
length: int32 # INT
) {.importc: "u_charsToUChars", cdecl, dynlib: "icuuc.dll".}pragma(lib, "icuuc");
extern(C)
void u_charsToUChars(
const(char)* cs, // LPCSTR
ushort* us, // WORD* in/out
int length // INT
);ccall((:u_charsToUChars, "icuuc.dll"), Cvoid,
(Cstring, Ptr{UInt16}, Int32),
cs, us, length)
# cs : LPCSTR -> Cstring
# us : WORD* in/out -> Ptr{UInt16}
# length : INT -> Int32local ffi = require("ffi")
ffi.cdef[[
void u_charsToUChars(
const char* cs,
uint16_t* us,
int32_t length);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.u_charsToUChars(cs, us, length)
-- cs : LPCSTR
-- us : WORD* in/out
-- length : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const u_charsToUChars = lib.func('__cdecl', 'u_charsToUChars', 'void', ['str', 'uint16_t *', 'int32_t']);
// u_charsToUChars(cs, us, length)
// cs : LPCSTR -> 'str'
// us : WORD* in/out -> 'uint16_t *'
// length : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("icuuc.dll", {
u_charsToUChars: { parameters: ["buffer", "pointer", "i32"], result: "void" },
});
// lib.symbols.u_charsToUChars(cs, us, length)
// cs : LPCSTR -> "buffer"
// us : WORD* in/out -> "pointer"
// length : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void u_charsToUChars(
const char* cs,
uint16_t* us,
int32_t length);
C, "icuuc.dll");
// $ffi->u_charsToUChars(cs, us, length);
// cs : LPCSTR
// us : WORD* in/out
// length : INT
// 構造体/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);
void u_charsToUChars(
String cs, // LPCSTR
ShortByReference us, // WORD* in/out
int length // INT
);
}@[Link("icuuc")]
lib Libicuuc
fun u_charsToUChars = u_charsToUChars(
cs : UInt8*, # LPCSTR
us : UInt16*, # WORD* in/out
length : Int32 # INT
) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef u_charsToUCharsNative = Void Function(Pointer<Utf8>, Pointer<Uint16>, Int32);
typedef u_charsToUCharsDart = void Function(Pointer<Utf8>, Pointer<Uint16>, int);
final u_charsToUChars = DynamicLibrary.open('icuuc.dll')
.lookupFunction<u_charsToUCharsNative, u_charsToUCharsDart>('u_charsToUChars');
// cs : LPCSTR -> Pointer<Utf8>
// us : WORD* in/out -> Pointer<Uint16>
// length : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
procedure u_charsToUChars(
cs: PAnsiChar; // LPCSTR
us: Pointer; // WORD* in/out
length: Integer // INT
); cdecl;
external 'icuuc.dll' name 'u_charsToUChars';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "u_charsToUChars"
c_u_charsToUChars :: CString -> Ptr Word16 -> Int32 -> IO ()
-- cs : LPCSTR -> CString
-- us : WORD* in/out -> Ptr Word16
-- length : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let u_charstouchars =
foreign "u_charsToUChars"
(string @-> (ptr uint16_t) @-> int32_t @-> returning void)
(* cs : LPCSTR -> string *)
(* us : WORD* in/out -> (ptr uint16_t) *)
(* length : INT -> 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_charsToUChars" u-chars-to-uchars :convention :cdecl) :void
(cs :string) ; LPCSTR
(us :pointer) ; WORD* in/out
(length :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $u_charsToUChars = Win32::API::More->new('icuuc',
'void u_charsToUChars(LPCSTR cs, LPVOID us, int length)');
# my $ret = $u_charsToUChars->Call($cs, $us, $length);
# cs : LPCSTR -> LPCSTR
# us : WORD* in/out -> LPVOID
# length : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。