ホーム › Globalization › CompareStringOrdinal
CompareStringOrdinal
関数二つの文字列を序数的に比較する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
COMPARESTRING_RESULT CompareStringOrdinal(
LPCWSTR lpString1,
INT cchCount1,
LPCWSTR lpString2,
INT cchCount2,
BOOL bIgnoreCase
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpString1 | LPCWSTR | in |
| cchCount1 | INT | in |
| lpString2 | LPCWSTR | in |
| cchCount2 | INT | in |
| bIgnoreCase | BOOL | in |
戻り値の型: COMPARESTRING_RESULT
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
COMPARESTRING_RESULT CompareStringOrdinal(
LPCWSTR lpString1,
INT cchCount1,
LPCWSTR lpString2,
INT cchCount2,
BOOL bIgnoreCase
);[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern int CompareStringOrdinal(
[MarshalAs(UnmanagedType.LPWStr)] string lpString1, // LPCWSTR
int cchCount1, // INT
[MarshalAs(UnmanagedType.LPWStr)] string lpString2, // LPCWSTR
int cchCount2, // INT
bool bIgnoreCase // BOOL
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CompareStringOrdinal(
<MarshalAs(UnmanagedType.LPWStr)> lpString1 As String, ' LPCWSTR
cchCount1 As Integer, ' INT
<MarshalAs(UnmanagedType.LPWStr)> lpString2 As String, ' LPCWSTR
cchCount2 As Integer, ' INT
bIgnoreCase As Boolean ' BOOL
) As Integer
End Function' lpString1 : LPCWSTR
' cchCount1 : INT
' lpString2 : LPCWSTR
' cchCount2 : INT
' bIgnoreCase : BOOL
Declare PtrSafe Function CompareStringOrdinal Lib "kernel32" ( _
ByVal lpString1 As LongPtr, _
ByVal cchCount1 As Long, _
ByVal lpString2 As LongPtr, _
ByVal cchCount2 As Long, _
ByVal bIgnoreCase As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CompareStringOrdinal = ctypes.windll.kernel32.CompareStringOrdinal
CompareStringOrdinal.restype = ctypes.c_int
CompareStringOrdinal.argtypes = [
wintypes.LPCWSTR, # lpString1 : LPCWSTR
ctypes.c_int, # cchCount1 : INT
wintypes.LPCWSTR, # lpString2 : LPCWSTR
ctypes.c_int, # cchCount2 : INT
wintypes.BOOL, # bIgnoreCase : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
CompareStringOrdinal = Fiddle::Function.new(
lib['CompareStringOrdinal'],
[
Fiddle::TYPE_VOIDP, # lpString1 : LPCWSTR
Fiddle::TYPE_INT, # cchCount1 : INT
Fiddle::TYPE_VOIDP, # lpString2 : LPCWSTR
Fiddle::TYPE_INT, # cchCount2 : INT
Fiddle::TYPE_INT, # bIgnoreCase : BOOL
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn CompareStringOrdinal(
lpString1: *const u16, // LPCWSTR
cchCount1: i32, // INT
lpString2: *const u16, // LPCWSTR
cchCount2: i32, // INT
bIgnoreCase: i32 // BOOL
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern int CompareStringOrdinal([MarshalAs(UnmanagedType.LPWStr)] string lpString1, int cchCount1, [MarshalAs(UnmanagedType.LPWStr)] string lpString2, int cchCount2, bool bIgnoreCase);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CompareStringOrdinal' -Namespace Win32 -PassThru
# $api::CompareStringOrdinal(lpString1, cchCount1, lpString2, cchCount2, bIgnoreCase)#uselib "KERNEL32.dll"
#func global CompareStringOrdinal "CompareStringOrdinal" sptr, sptr, sptr, sptr, sptr
; CompareStringOrdinal lpString1, cchCount1, lpString2, cchCount2, bIgnoreCase ; 戻り値は stat
; lpString1 : LPCWSTR -> "sptr"
; cchCount1 : INT -> "sptr"
; lpString2 : LPCWSTR -> "sptr"
; cchCount2 : INT -> "sptr"
; bIgnoreCase : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global CompareStringOrdinal "CompareStringOrdinal" wstr, int, wstr, int, int
; res = CompareStringOrdinal(lpString1, cchCount1, lpString2, cchCount2, bIgnoreCase)
; lpString1 : LPCWSTR -> "wstr"
; cchCount1 : INT -> "int"
; lpString2 : LPCWSTR -> "wstr"
; cchCount2 : INT -> "int"
; bIgnoreCase : BOOL -> "int"; COMPARESTRING_RESULT CompareStringOrdinal(LPCWSTR lpString1, INT cchCount1, LPCWSTR lpString2, INT cchCount2, BOOL bIgnoreCase)
#uselib "KERNEL32.dll"
#cfunc global CompareStringOrdinal "CompareStringOrdinal" wstr, int, wstr, int, int
; res = CompareStringOrdinal(lpString1, cchCount1, lpString2, cchCount2, bIgnoreCase)
; lpString1 : LPCWSTR -> "wstr"
; cchCount1 : INT -> "int"
; lpString2 : LPCWSTR -> "wstr"
; cchCount2 : INT -> "int"
; bIgnoreCase : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procCompareStringOrdinal = kernel32.NewProc("CompareStringOrdinal")
)
// lpString1 (LPCWSTR), cchCount1 (INT), lpString2 (LPCWSTR), cchCount2 (INT), bIgnoreCase (BOOL)
r1, _, err := procCompareStringOrdinal.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpString1))),
uintptr(cchCount1),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpString2))),
uintptr(cchCount2),
uintptr(bIgnoreCase),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // COMPARESTRING_RESULTfunction CompareStringOrdinal(
lpString1: PWideChar; // LPCWSTR
cchCount1: Integer; // INT
lpString2: PWideChar; // LPCWSTR
cchCount2: Integer; // INT
bIgnoreCase: BOOL // BOOL
): Integer; stdcall;
external 'KERNEL32.dll' name 'CompareStringOrdinal';result := DllCall("KERNEL32\CompareStringOrdinal"
, "WStr", lpString1 ; LPCWSTR
, "Int", cchCount1 ; INT
, "WStr", lpString2 ; LPCWSTR
, "Int", cchCount2 ; INT
, "Int", bIgnoreCase ; BOOL
, "Int") ; return: COMPARESTRING_RESULT●CompareStringOrdinal(lpString1, cchCount1, lpString2, cchCount2, bIgnoreCase) = DLL("KERNEL32.dll", "int CompareStringOrdinal(char*, int, char*, int, bool)")
# 呼び出し: CompareStringOrdinal(lpString1, cchCount1, lpString2, cchCount2, bIgnoreCase)
# lpString1 : LPCWSTR -> "char*"
# cchCount1 : INT -> "int"
# lpString2 : LPCWSTR -> "char*"
# cchCount2 : INT -> "int"
# bIgnoreCase : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。