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