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
csLPSTRin
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`,…) を使用。