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