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

u_memchr

関数
UChar領域内で指定文字を先頭から検索する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

WORD* u_memchr(
    const WORD* s,
    WORD c,
    INT count
);

パラメーター

名前方向説明
sWORD*in検索対象のUTF-16バッファへのポインタ。
cWORDin検索する単一UTF-16コードユニット。
countINTin検索範囲のUChar数。最初の出現位置を返し、無ければNULLを返す。

戻り値の型: WORD*

各言語での呼び出し定義

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

WORD* u_memchr(
    const WORD* s,
    WORD c,
    INT count
);
[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr u_memchr(
    ref ushort s,   // WORD*
    ushort c,   // WORD
    int count   // INT
);
<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_memchr(
    ByRef s As UShort,   ' WORD*
    c As UShort,   ' WORD
    count As Integer   ' INT
) As IntPtr
End Function
' s : WORD*
' c : WORD
' count : INT
Declare PtrSafe Function u_memchr Lib "icuuc" ( _
    ByRef s As Integer, _
    ByVal c As Integer, _
    ByVal count As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

u_memchr = ctypes.cdll.icuuc.u_memchr
u_memchr.restype = ctypes.c_void_p
u_memchr.argtypes = [
    ctypes.POINTER(ctypes.c_ushort),  # s : WORD*
    ctypes.c_ushort,  # c : WORD
    ctypes.c_int,  # count : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('icuuc.dll')
u_memchr = Fiddle::Function.new(
  lib['u_memchr'],
  [
    Fiddle::TYPE_VOIDP,  # s : WORD*
    -Fiddle::TYPE_SHORT,  # c : WORD
    Fiddle::TYPE_INT,  # count : INT
  ],
  Fiddle::TYPE_VOIDP, Fiddle::Function::CDECL)
#[link(name = "icuuc")]
extern "C" {
    fn u_memchr(
        s: *const u16,  // WORD*
        c: u16,  // WORD
        count: i32  // INT
    ) -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr u_memchr(ref ushort s, ushort c, int count);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_memchr' -Namespace Win32 -PassThru
# $api::u_memchr(s, c, count)
#uselib "icuuc.dll"
#func global u_memchr "u_memchr" sptr, sptr, sptr
; u_memchr varptr(s), c, count   ; 戻り値は stat
; s : WORD* -> "sptr"
; c : WORD -> "sptr"
; count : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "icuuc.dll"
#cfunc global u_memchr "u_memchr" var, int, int
; res = u_memchr(s, c, count)
; s : WORD* -> "var"
; c : WORD -> "int"
; count : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WORD* u_memchr(WORD* s, WORD c, INT count)
#uselib "icuuc.dll"
#cfunc global u_memchr "u_memchr" var, int, int
; res = u_memchr(s, c, count)
; s : WORD* -> "var"
; c : WORD -> "int"
; count : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procu_memchr = icuuc.NewProc("u_memchr")
)

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

typedef u_memchrNative = Pointer<Uint16> Function(Pointer<Uint16>, Uint16, Int32);
typedef u_memchrDart = Pointer<Uint16> Function(Pointer<Uint16>, int, int);
final u_memchr = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<u_memchrNative, u_memchrDart>('u_memchr');
// s : WORD* -> Pointer<Uint16>
// c : WORD -> Uint16
// count : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function u_memchr(
  s: Pointer;   // WORD*
  c: Word;   // WORD
  count: Integer   // INT
): Pointer; cdecl;
  external 'icuuc.dll' name 'u_memchr';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "u_memchr"
  c_u_memchr :: Ptr Word16 -> Word16 -> Int32 -> IO (Ptr Word16)
-- s : WORD* -> Ptr Word16
-- c : WORD -> Word16
-- count : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let u_memchr =
  foreign "u_memchr"
    ((ptr uint16_t) @-> uint16_t @-> int32_t @-> returning (ptr uint16_t))
(* s : WORD* -> (ptr uint16_t) *)
(* c : WORD -> uint16_t *)
(* count : 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_memchr" u-memchr :convention :cdecl) :pointer
  (s :pointer)   ; WORD*
  (c :uint16)   ; WORD
  (count :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $u_memchr = Win32::API::More->new('icuuc',
    'LPVOID u_memchr(LPVOID s, WORD c, int count)');
# my $ret = $u_memchr->Call($s, $c, $count);
# s : WORD* -> LPVOID
# c : WORD -> WORD
# count : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API