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