ホーム › Globalization › u_strncmp
u_strncmp
関数二つの文字列を最大n文字まで比較する。
シグネチャ
// icuuc.dll
#include <windows.h>
INT u_strncmp(
const WORD* ucs1,
const WORD* ucs2,
INT n
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ucs1 | WORD* | in |
| ucs2 | WORD* | in |
| n | INT | in |
戻り値の型: INT
各言語での呼び出し定義
// icuuc.dll
#include <windows.h>
INT u_strncmp(
const WORD* ucs1,
const WORD* ucs2,
INT n
);[DllImport("icuuc.dll", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int u_strncmp(
ref ushort ucs1, // WORD*
ref ushort ucs2, // WORD*
int n // INT
);<DllImport("icuuc.dll", ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function u_strncmp(
ByRef ucs1 As UShort, ' WORD*
ByRef ucs2 As UShort, ' WORD*
n As Integer ' INT
) As Integer
End Function' ucs1 : WORD*
' ucs2 : WORD*
' n : INT
Declare PtrSafe Function u_strncmp Lib "icuuc" ( _
ByRef ucs1 As Integer, _
ByRef ucs2 As Integer, _
ByVal n As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
u_strncmp = ctypes.cdll.icuuc.u_strncmp
u_strncmp.restype = ctypes.c_int
u_strncmp.argtypes = [
ctypes.POINTER(ctypes.c_ushort), # ucs1 : WORD*
ctypes.POINTER(ctypes.c_ushort), # ucs2 : WORD*
ctypes.c_int, # n : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('icuuc.dll')
u_strncmp = Fiddle::Function.new(
lib['u_strncmp'],
[
Fiddle::TYPE_VOIDP, # ucs1 : WORD*
Fiddle::TYPE_VOIDP, # ucs2 : WORD*
Fiddle::TYPE_INT, # n : INT
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "icuuc")]
extern "C" {
fn u_strncmp(
ucs1: *const u16, // WORD*
ucs2: *const u16, // WORD*
n: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("icuuc.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int u_strncmp(ref ushort ucs1, ref ushort ucs2, int n);
"@
$api = Add-Type -MemberDefinition $sig -Name 'icuuc_u_strncmp' -Namespace Win32 -PassThru
# $api::u_strncmp(ucs1, ucs2, n)#uselib "icuuc.dll"
#func global u_strncmp "u_strncmp" sptr, sptr, sptr
; u_strncmp varptr(ucs1), varptr(ucs2), n ; 戻り値は stat
; ucs1 : WORD* -> "sptr"
; ucs2 : WORD* -> "sptr"
; n : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "icuuc.dll" #cfunc global u_strncmp "u_strncmp" var, var, int ; res = u_strncmp(ucs1, ucs2, n) ; ucs1 : WORD* -> "var" ; ucs2 : WORD* -> "var" ; n : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "icuuc.dll" #cfunc global u_strncmp "u_strncmp" sptr, sptr, int ; res = u_strncmp(varptr(ucs1), varptr(ucs2), n) ; ucs1 : WORD* -> "sptr" ; ucs2 : WORD* -> "sptr" ; n : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT u_strncmp(WORD* ucs1, WORD* ucs2, INT n) #uselib "icuuc.dll" #cfunc global u_strncmp "u_strncmp" var, var, int ; res = u_strncmp(ucs1, ucs2, n) ; ucs1 : WORD* -> "var" ; ucs2 : WORD* -> "var" ; n : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT u_strncmp(WORD* ucs1, WORD* ucs2, INT n) #uselib "icuuc.dll" #cfunc global u_strncmp "u_strncmp" intptr, intptr, int ; res = u_strncmp(varptr(ucs1), varptr(ucs2), n) ; ucs1 : WORD* -> "intptr" ; ucs2 : WORD* -> "intptr" ; n : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
icuuc = windows.NewLazySystemDLL("icuuc.dll")
procu_strncmp = icuuc.NewProc("u_strncmp")
)
// ucs1 (WORD*), ucs2 (WORD*), n (INT)
r1, _, err := procu_strncmp.Call(
uintptr(ucs1),
uintptr(ucs2),
uintptr(n),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction u_strncmp(
ucs1: Pointer; // WORD*
ucs2: Pointer; // WORD*
n: Integer // INT
): Integer; cdecl;
external 'icuuc.dll' name 'u_strncmp';result := DllCall("icuuc\u_strncmp"
, "Ptr", ucs1 ; WORD*
, "Ptr", ucs2 ; WORD*
, "Int", n ; INT
, "Cdecl Int") ; return: INT●u_strncmp(ucs1, ucs2, n) = DLL("icuuc.dll", "int u_strncmp(void*, void*, int)")
# 呼び出し: u_strncmp(ucs1, ucs2, n)
# ucs1 : WORD* -> "void*"
# ucs2 : WORD* -> "void*"
# n : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。