Win32 API 日本語リファレンス
ホームUI.Shell › StrCmpNW

StrCmpNW

関数
先頭から指定文字数だけ二つの文字列を比較する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

INT StrCmpNW(
    LPCWSTR psz1,
    LPCWSTR psz2,
    INT nChar
);

パラメーター

名前方向
psz1LPCWSTRin
psz2LPCWSTRin
nCharINTin

戻り値の型: INT

各言語での呼び出し定義

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

INT StrCmpNW(
    LPCWSTR psz1,
    LPCWSTR psz2,
    INT nChar
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int StrCmpNW(
    [MarshalAs(UnmanagedType.LPWStr)] string psz1,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string psz2,   // LPCWSTR
    int nChar   // INT
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function StrCmpNW(
    <MarshalAs(UnmanagedType.LPWStr)> psz1 As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> psz2 As String,   ' LPCWSTR
    nChar As Integer   ' INT
) As Integer
End Function
' psz1 : LPCWSTR
' psz2 : LPCWSTR
' nChar : INT
Declare PtrSafe Function StrCmpNW Lib "shlwapi" ( _
    ByVal psz1 As LongPtr, _
    ByVal psz2 As LongPtr, _
    ByVal nChar As Long) 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

StrCmpNW = ctypes.windll.shlwapi.StrCmpNW
StrCmpNW.restype = ctypes.c_int
StrCmpNW.argtypes = [
    wintypes.LPCWSTR,  # psz1 : LPCWSTR
    wintypes.LPCWSTR,  # psz2 : LPCWSTR
    ctypes.c_int,  # nChar : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
StrCmpNW = Fiddle::Function.new(
  lib['StrCmpNW'],
  [
    Fiddle::TYPE_VOIDP,  # psz1 : LPCWSTR
    Fiddle::TYPE_VOIDP,  # psz2 : LPCWSTR
    Fiddle::TYPE_INT,  # nChar : INT
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shlwapi")]
extern "system" {
    fn StrCmpNW(
        psz1: *const u16,  // LPCWSTR
        psz2: *const u16,  // LPCWSTR
        nChar: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode)]
public static extern int StrCmpNW([MarshalAs(UnmanagedType.LPWStr)] string psz1, [MarshalAs(UnmanagedType.LPWStr)] string psz2, int nChar);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrCmpNW' -Namespace Win32 -PassThru
# $api::StrCmpNW(psz1, psz2, nChar)
#uselib "SHLWAPI.dll"
#func global StrCmpNW "StrCmpNW" wptr, wptr, wptr
; StrCmpNW psz1, psz2, nChar   ; 戻り値は stat
; psz1 : LPCWSTR -> "wptr"
; psz2 : LPCWSTR -> "wptr"
; nChar : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global StrCmpNW "StrCmpNW" wstr, wstr, int
; res = StrCmpNW(psz1, psz2, nChar)
; psz1 : LPCWSTR -> "wstr"
; psz2 : LPCWSTR -> "wstr"
; nChar : INT -> "int"
; INT StrCmpNW(LPCWSTR psz1, LPCWSTR psz2, INT nChar)
#uselib "SHLWAPI.dll"
#cfunc global StrCmpNW "StrCmpNW" wstr, wstr, int
; res = StrCmpNW(psz1, psz2, nChar)
; psz1 : LPCWSTR -> "wstr"
; psz2 : LPCWSTR -> "wstr"
; nChar : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrCmpNW = shlwapi.NewProc("StrCmpNW")
)

// psz1 (LPCWSTR), psz2 (LPCWSTR), nChar (INT)
r1, _, err := procStrCmpNW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(psz1))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(psz2))),
	uintptr(nChar),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function StrCmpNW(
  psz1: PWideChar;   // LPCWSTR
  psz2: PWideChar;   // LPCWSTR
  nChar: Integer   // INT
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'StrCmpNW';
result := DllCall("SHLWAPI\StrCmpNW"
    , "WStr", psz1   ; LPCWSTR
    , "WStr", psz2   ; LPCWSTR
    , "Int", nChar   ; INT
    , "Int")   ; return: INT
●StrCmpNW(psz1, psz2, nChar) = DLL("SHLWAPI.dll", "int StrCmpNW(char*, char*, int)")
# 呼び出し: StrCmpNW(psz1, psz2, nChar)
# psz1 : LPCWSTR -> "char*"
# psz2 : LPCWSTR -> "char*"
# nChar : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。