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

StrCmpNCW

関数
C言語ロケールで先頭指定文字数だけ文字列を比較する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT StrCmpNCW(
    LPCWSTR pszStr1,
    LPCWSTR pszStr2,
    INT nChar
);

パラメーター

名前方向
pszStr1LPCWSTRin
pszStr2LPCWSTRin
nCharINTin

戻り値の型: INT

各言語での呼び出し定義

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

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

StrCmpNCW = ctypes.windll.shlwapi.StrCmpNCW
StrCmpNCW.restype = ctypes.c_int
StrCmpNCW.argtypes = [
    wintypes.LPCWSTR,  # pszStr1 : LPCWSTR
    wintypes.LPCWSTR,  # pszStr2 : LPCWSTR
    ctypes.c_int,  # nChar : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
StrCmpNCW = Fiddle::Function.new(
  lib['StrCmpNCW'],
  [
    Fiddle::TYPE_VOIDP,  # pszStr1 : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszStr2 : LPCWSTR
    Fiddle::TYPE_INT,  # nChar : INT
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shlwapi")]
extern "system" {
    fn StrCmpNCW(
        pszStr1: *const u16,  // LPCWSTR
        pszStr2: *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 StrCmpNCW([MarshalAs(UnmanagedType.LPWStr)] string pszStr1, [MarshalAs(UnmanagedType.LPWStr)] string pszStr2, int nChar);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrCmpNCW' -Namespace Win32 -PassThru
# $api::StrCmpNCW(pszStr1, pszStr2, nChar)
#uselib "SHLWAPI.dll"
#func global StrCmpNCW "StrCmpNCW" wptr, wptr, wptr
; StrCmpNCW pszStr1, pszStr2, nChar   ; 戻り値は stat
; pszStr1 : LPCWSTR -> "wptr"
; pszStr2 : LPCWSTR -> "wptr"
; nChar : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global StrCmpNCW "StrCmpNCW" wstr, wstr, int
; res = StrCmpNCW(pszStr1, pszStr2, nChar)
; pszStr1 : LPCWSTR -> "wstr"
; pszStr2 : LPCWSTR -> "wstr"
; nChar : INT -> "int"
; INT StrCmpNCW(LPCWSTR pszStr1, LPCWSTR pszStr2, INT nChar)
#uselib "SHLWAPI.dll"
#cfunc global StrCmpNCW "StrCmpNCW" wstr, wstr, int
; res = StrCmpNCW(pszStr1, pszStr2, nChar)
; pszStr1 : LPCWSTR -> "wstr"
; pszStr2 : LPCWSTR -> "wstr"
; nChar : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procStrCmpNCW = shlwapi.NewProc("StrCmpNCW")
)

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