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

u_strCompare

関数
長さ指定で二つの文字列を比較する。
DLLicuuc.dll呼出規約cdecl

シグネチャ

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

INT u_strCompare(
    const WORD* s1,
    INT length1,
    const WORD* s2,
    INT length2,
    CHAR codePointOrder
);

パラメーター

名前方向説明
s1WORD*in比較する第一UTF-16文字列へのポインタ。
length1INTins1の長さ(UChar単位)。-1の場合はNUL終端として扱う。
s2WORD*in比較する第二UTF-16文字列へのポインタ。
length2INTins2の長さ(UChar単位)。-1の場合はNUL終端として扱う。
codePointOrderCHARinTRUEならコードポイント順、FALSEならコードユニット順で比較する。

戻り値の型: INT

各言語での呼び出し定義

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

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

u_strCompare = ctypes.cdll.icuuc.u_strCompare
u_strCompare.restype = ctypes.c_int
u_strCompare.argtypes = [
    ctypes.POINTER(ctypes.c_ushort),  # s1 : WORD*
    ctypes.c_int,  # length1 : INT
    ctypes.POINTER(ctypes.c_ushort),  # s2 : WORD*
    ctypes.c_int,  # length2 : INT
    ctypes.c_byte,  # codePointOrder : CHAR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	icuuc = windows.NewLazySystemDLL("icuuc.dll")
	procu_strCompare = icuuc.NewProc("u_strCompare")
)

// s1 (WORD*), length1 (INT), s2 (WORD*), length2 (INT), codePointOrder (CHAR)
r1, _, err := procu_strCompare.Call(
	uintptr(s1),
	uintptr(length1),
	uintptr(s2),
	uintptr(length2),
	uintptr(codePointOrder),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function u_strCompare(
  s1: Pointer;   // WORD*
  length1: Integer;   // INT
  s2: Pointer;   // WORD*
  length2: Integer;   // INT
  codePointOrder: Shortint   // CHAR
): Integer; cdecl;
  external 'icuuc.dll' name 'u_strCompare';
result := DllCall("icuuc\u_strCompare"
    , "Ptr", s1   ; WORD*
    , "Int", length1   ; INT
    , "Ptr", s2   ; WORD*
    , "Int", length2   ; INT
    , "Char", codePointOrder   ; CHAR
    , "Cdecl Int")   ; return: INT
●u_strCompare(s1, length1, s2, length2, codePointOrder) = DLL("icuuc.dll", "int u_strCompare(void*, int, void*, int, char)")
# 呼び出し: u_strCompare(s1, length1, s2, length2, codePointOrder)
# s1 : WORD* -> "void*"
# length1 : INT -> "int"
# s2 : WORD* -> "void*"
# length2 : INT -> "int"
# codePointOrder : CHAR -> "char"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。
const std = @import("std");

extern "icuuc" fn u_strCompare(
    s1: [*c]u16, // WORD*
    length1: i32, // INT
    s2: [*c]u16, // WORD*
    length2: i32, // INT
    codePointOrder: i8 // CHAR
) callconv(.c) i32;
proc u_strCompare(
    s1: ptr uint16,  # WORD*
    length1: int32,  # INT
    s2: ptr uint16,  # WORD*
    length2: int32,  # INT
    codePointOrder: int8  # CHAR
): int32 {.importc: "u_strCompare", cdecl, dynlib: "icuuc.dll".}
pragma(lib, "icuuc");
extern(C)
int u_strCompare(
    ushort* s1,   // WORD*
    int length1,   // INT
    ushort* s2,   // WORD*
    int length2,   // INT
    byte codePointOrder   // CHAR
);
ccall((:u_strCompare, "icuuc.dll"), Int32,
      (Ptr{UInt16}, Int32, Ptr{UInt16}, Int32, Int8),
      s1, length1, s2, length2, codePointOrder)
# s1 : WORD* -> Ptr{UInt16}
# length1 : INT -> Int32
# s2 : WORD* -> Ptr{UInt16}
# length2 : INT -> Int32
# codePointOrder : CHAR -> Int8
local ffi = require("ffi")
ffi.cdef[[
int32_t u_strCompare(
    uint16_t* s1,
    int32_t length1,
    uint16_t* s2,
    int32_t length2,
    int8_t codePointOrder);
]]
local icuuc = ffi.load("icuuc")
-- icuuc.u_strCompare(s1, length1, s2, length2, codePointOrder)
-- s1 : WORD*
-- length1 : INT
-- s2 : WORD*
-- length2 : INT
-- codePointOrder : CHAR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('icuuc.dll');
const u_strCompare = lib.func('__cdecl', 'u_strCompare', 'int32_t', ['uint16_t *', 'int32_t', 'uint16_t *', 'int32_t', 'int8_t']);
// u_strCompare(s1, length1, s2, length2, codePointOrder)
// s1 : WORD* -> 'uint16_t *'
// length1 : INT -> 'int32_t'
// s2 : WORD* -> 'uint16_t *'
// length2 : INT -> 'int32_t'
// codePointOrder : CHAR -> 'int8_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("icuuc.dll", {
  u_strCompare: { parameters: ["pointer", "i32", "pointer", "i32", "i8"], result: "i32" },
});
// lib.symbols.u_strCompare(s1, length1, s2, length2, codePointOrder)
// s1 : WORD* -> "pointer"
// length1 : INT -> "i32"
// s2 : WORD* -> "pointer"
// length2 : INT -> "i32"
// codePointOrder : CHAR -> "i8"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t u_strCompare(
    uint16_t* s1,
    int32_t length1,
    uint16_t* s2,
    int32_t length2,
    int8_t codePointOrder);
C, "icuuc.dll");
// $ffi->u_strCompare(s1, length1, s2, length2, codePointOrder);
// s1 : WORD*
// length1 : INT
// s2 : WORD*
// length2 : INT
// codePointOrder : CHAR
// 構造体/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_strCompare(
        ShortByReference s1,   // WORD*
        int length1,   // INT
        ShortByReference s2,   // WORD*
        int length2,   // INT
        byte codePointOrder   // CHAR
    );
}
@[Link("icuuc")]
lib Libicuuc
  fun u_strCompare = u_strCompare(
    s1 : UInt16*,   # WORD*
    length1 : Int32,   # INT
    s2 : UInt16*,   # WORD*
    length2 : Int32,   # INT
    codePointOrder : Int8   # CHAR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef u_strCompareNative = Int32 Function(Pointer<Uint16>, Int32, Pointer<Uint16>, Int32, Int8);
typedef u_strCompareDart = int Function(Pointer<Uint16>, int, Pointer<Uint16>, int, int);
final u_strCompare = DynamicLibrary.open('icuuc.dll')
    .lookupFunction<u_strCompareNative, u_strCompareDart>('u_strCompare');
// s1 : WORD* -> Pointer<Uint16>
// length1 : INT -> Int32
// s2 : WORD* -> Pointer<Uint16>
// length2 : INT -> Int32
// codePointOrder : CHAR -> Int8
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function u_strCompare(
  s1: Pointer;   // WORD*
  length1: Integer;   // INT
  s2: Pointer;   // WORD*
  length2: Integer;   // INT
  codePointOrder: Shortint   // CHAR
): Integer; cdecl;
  external 'icuuc.dll' name 'u_strCompare';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "u_strCompare"
  c_u_strCompare :: Ptr Word16 -> Int32 -> Ptr Word16 -> Int32 -> Int8 -> IO Int32
-- s1 : WORD* -> Ptr Word16
-- length1 : INT -> Int32
-- s2 : WORD* -> Ptr Word16
-- length2 : INT -> Int32
-- codePointOrder : CHAR -> Int8
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let u_strcompare =
  foreign "u_strCompare"
    ((ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> int8_t @-> returning int32_t)
(* s1 : WORD* -> (ptr uint16_t) *)
(* length1 : INT -> int32_t *)
(* s2 : WORD* -> (ptr uint16_t) *)
(* length2 : INT -> int32_t *)
(* codePointOrder : CHAR -> int8_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library icuuc (t "icuuc.dll"))
(cffi:use-foreign-library icuuc)

(cffi:defcfun ("u_strCompare" u-str-compare :convention :cdecl) :int32
  (s1 :pointer)   ; WORD*
  (length1 :int32)   ; INT
  (s2 :pointer)   ; WORD*
  (length2 :int32)   ; INT
  (code-point-order :int8))   ; CHAR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $u_strCompare = Win32::API::More->new('icuuc',
    'int u_strCompare(LPVOID s1, int length1, LPVOID s2, int length2, char codePointOrder)');
# my $ret = $u_strCompare->Call($s1, $length1, $s2, $length2, $codePointOrder);
# s1 : WORD* -> LPVOID
# length1 : INT -> int
# s2 : WORD* -> LPVOID
# length2 : INT -> int
# codePointOrder : CHAR -> char
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。