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

u_charsToUChars

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

シグネチャ

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

void u_charsToUChars(
    LPCSTR cs,
    WORD* us,
    INT length
);

パラメーター

名前方向
csLPCSTRin
usWORD*inout
lengthINTin

戻り値の型: 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // void
procedure 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`,…) を使用。