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

u_UCharsToChars

関数
UChar配列をASCII文字列に変換する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

void u_UCharsToChars(
    const WORD* us,
    LPSTR cs,
    INT length
);

パラメーター

名前方向説明
usWORD*in変換元のUTF-16(UChar)文字列へのポインタ。
csLPSTRin変換後の不変ASCII(char)を書き込む出力バッファへのポインタ。
lengthINTin変換する文字数。

戻り値の型: void

各言語での呼び出し定義

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

void u_UCharsToChars(
    const WORD* us,
    LPSTR cs,
    INT length
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern void u_UCharsToChars(
    ref ushort us,   // WORD*
    [MarshalAs(UnmanagedType.LPStr)] string cs,   // LPSTR
    int length   // INT
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Sub u_UCharsToChars(
    ByRef us As UShort,   ' WORD*
    <MarshalAs(UnmanagedType.LPStr)> cs As String,   ' LPSTR
    length As Integer   ' INT
)
End Sub
' us : WORD*
' cs : LPSTR
' length : INT
Declare PtrSafe Sub u_UCharsToChars Lib "icuuc" ( _
    ByRef us As Integer, _
    ByVal cs As String, _
    ByVal length As Long)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

u_UCharsToChars = ctypes.cdll.icuuc.u_UCharsToChars
u_UCharsToChars.restype = None
u_UCharsToChars.argtypes = [
    ctypes.POINTER(ctypes.c_ushort),  # us : WORD*
    wintypes.LPCSTR,  # cs : LPSTR
    ctypes.c_int,  # length : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
u_UCharsToChars = Fiddle::Function.new(
  lib['u_UCharsToChars'],
  [
    Fiddle::TYPE_VOIDP,  # us : WORD*
    Fiddle::TYPE_VOIDP,  # cs : LPSTR
    Fiddle::TYPE_INT,  # length : INT
  ],
  Fiddle::TYPE_VOID, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn u_UCharsToChars(
        us: *const u16,  // WORD*
        cs: *mut u8,  // LPSTR
        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_UCharsToChars(ref ushort us, [MarshalAs(UnmanagedType.LPStr)] string cs, int length);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_UCharsToChars' -Namespace Win32 -PassThru
# $api::u_UCharsToChars(us, cs, length)
#uselib "icuuc.dll"
#func global u_UCharsToChars "u_UCharsToChars" sptr, sptr, sptr
; u_UCharsToChars varptr(us), cs, length
; us : WORD* -> "sptr"
; cs : LPSTR -> "sptr"
; length : INT -> "sptr"
出力引数:
#uselib "icuuc.dll"
#func global u_UCharsToChars "u_UCharsToChars" var, str, int
; u_UCharsToChars us, cs, length
; us : WORD* -> "var"
; cs : LPSTR -> "str"
; length : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void u_UCharsToChars(WORD* us, LPSTR cs, INT length)
#uselib "icuuc.dll"
#func global u_UCharsToChars "u_UCharsToChars" var, str, int
; u_UCharsToChars us, cs, length
; us : WORD* -> "var"
; cs : LPSTR -> "str"
; length : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procu_UCharsToChars = icuuc.NewProc("u_UCharsToChars")
)

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

typedef u_UCharsToCharsNative = Void Function(Pointer<Uint16>, Pointer<Utf8>, Int32);
typedef u_UCharsToCharsDart = void Function(Pointer<Uint16>, Pointer<Utf8>, int);
final u_UCharsToChars = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<u_UCharsToCharsNative, u_UCharsToCharsDart>('u_UCharsToChars');
// us : WORD* -> Pointer<Uint16>
// cs : LPSTR -> Pointer<Utf8>
// length : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure u_UCharsToChars(
  us: Pointer;   // WORD*
  cs: PAnsiChar;   // LPSTR
  length: Integer   // INT
); cdecl;
  external 'icuuc.dll' name 'u_UCharsToChars';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "u_UCharsToChars"
  c_u_UCharsToChars :: Ptr Word16 -> CString -> Int32 -> IO ()
-- us : WORD* -> Ptr Word16
-- cs : LPSTR -> CString
-- length : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let u_ucharstochars =
  foreign "u_UCharsToChars"
    ((ptr uint16_t) @-> string @-> int32_t @-> returning void)
(* us : WORD* -> (ptr uint16_t) *)
(* cs : LPSTR -> string *)
(* 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_UCharsToChars" u-uchars-to-chars :convention :cdecl) :void
  (us :pointer)   ; WORD*
  (cs :string)   ; LPSTR
  (length :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $u_UCharsToChars = Win32::API::More->new('icuuc',
    'void u_UCharsToChars(LPVOID us, LPCSTR cs, int length)');
# my $ret = $u_UCharsToChars->Call($us, $cs, $length);
# us : WORD* -> LPVOID
# cs : LPSTR -> LPCSTR
# length : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。