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