StrCmpNIA
関数指定文字数だけ大小文字を区別せず文字列を比較する。
シグネチャ
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
INT StrCmpNIA(
LPCSTR psz1,
LPCSTR psz2,
INT nChar
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| psz1 | LPCSTR | in | 比較対象となる 1 番目の null 終端文字列へのポインター。 |
| psz2 | LPCSTR | in | 比較対象となる 2 番目の null 終端文字列へのポインター。 |
| nChar | INT | in | 各文字列の先頭から比較する文字数。 |
戻り値の型: INT
公式ドキュメント
2 つの文字列の先頭から指定した文字数を比較し、それらが同一かどうかを判定します。比較では大文字と小文字は区別されません。StrNCmpI マクロは名前のみがこの関数と異なります。(ANSI)
戻り値
型: int
文字列が同一の場合は 0 を返します。psz1 が指す文字列の先頭 nChar 文字が psz2 が指す文字列の対応する文字より大きい場合は正の値を返します。psz1 が指す文字列の先頭 nChar 文字が psz2 が指す文字列の対応する文字より小さい場合は負の値を返します。
解説(Remarks)
メモ
shlwapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして StrCmpNI を定義しています。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、不一致が生じてコンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、「Conventions for Function Prototypes」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHLWAPI.dll (ANSI / -A)
#include <windows.h>
INT StrCmpNIA(
LPCSTR psz1,
LPCSTR psz2,
INT nChar
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern int StrCmpNIA(
[MarshalAs(UnmanagedType.LPStr)] string psz1, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string psz2, // LPCSTR
int nChar // INT
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function StrCmpNIA(
<MarshalAs(UnmanagedType.LPStr)> psz1 As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> psz2 As String, ' LPCSTR
nChar As Integer ' INT
) As Integer
End Function' psz1 : LPCSTR
' psz2 : LPCSTR
' nChar : INT
Declare PtrSafe Function StrCmpNIA Lib "shlwapi" ( _
ByVal psz1 As String, _
ByVal psz2 As String, _
ByVal nChar As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
StrCmpNIA = ctypes.windll.shlwapi.StrCmpNIA
StrCmpNIA.restype = ctypes.c_int
StrCmpNIA.argtypes = [
wintypes.LPCSTR, # psz1 : LPCSTR
wintypes.LPCSTR, # psz2 : LPCSTR
ctypes.c_int, # nChar : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
StrCmpNIA = Fiddle::Function.new(
lib['StrCmpNIA'],
[
Fiddle::TYPE_VOIDP, # psz1 : LPCSTR
Fiddle::TYPE_VOIDP, # psz2 : LPCSTR
Fiddle::TYPE_INT, # nChar : INT
],
Fiddle::TYPE_INT)#[link(name = "shlwapi")]
extern "system" {
fn StrCmpNIA(
psz1: *const u8, // LPCSTR
psz2: *const u8, // LPCSTR
nChar: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern int StrCmpNIA([MarshalAs(UnmanagedType.LPStr)] string psz1, [MarshalAs(UnmanagedType.LPStr)] string psz2, int nChar);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_StrCmpNIA' -Namespace Win32 -PassThru
# $api::StrCmpNIA(psz1, psz2, nChar)#uselib "SHLWAPI.dll"
#func global StrCmpNIA "StrCmpNIA" sptr, sptr, sptr
; StrCmpNIA psz1, psz2, nChar ; 戻り値は stat
; psz1 : LPCSTR -> "sptr"
; psz2 : LPCSTR -> "sptr"
; nChar : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHLWAPI.dll"
#cfunc global StrCmpNIA "StrCmpNIA" str, str, int
; res = StrCmpNIA(psz1, psz2, nChar)
; psz1 : LPCSTR -> "str"
; psz2 : LPCSTR -> "str"
; nChar : INT -> "int"; INT StrCmpNIA(LPCSTR psz1, LPCSTR psz2, INT nChar)
#uselib "SHLWAPI.dll"
#cfunc global StrCmpNIA "StrCmpNIA" str, str, int
; res = StrCmpNIA(psz1, psz2, nChar)
; psz1 : LPCSTR -> "str"
; psz2 : LPCSTR -> "str"
; nChar : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procStrCmpNIA = shlwapi.NewProc("StrCmpNIA")
)
// psz1 (LPCSTR), psz2 (LPCSTR), nChar (INT)
r1, _, err := procStrCmpNIA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(psz1))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(psz2))),
uintptr(nChar),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction StrCmpNIA(
psz1: PAnsiChar; // LPCSTR
psz2: PAnsiChar; // LPCSTR
nChar: Integer // INT
): Integer; stdcall;
external 'SHLWAPI.dll' name 'StrCmpNIA';result := DllCall("SHLWAPI\StrCmpNIA"
, "AStr", psz1 ; LPCSTR
, "AStr", psz2 ; LPCSTR
, "Int", nChar ; INT
, "Int") ; return: INT●StrCmpNIA(psz1, psz2, nChar) = DLL("SHLWAPI.dll", "int StrCmpNIA(char*, char*, int)")
# 呼び出し: StrCmpNIA(psz1, psz2, nChar)
# psz1 : LPCSTR -> "char*"
# psz2 : LPCSTR -> "char*"
# nChar : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn StrCmpNIA(
psz1: [*c]const u8, // LPCSTR
psz2: [*c]const u8, // LPCSTR
nChar: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc StrCmpNIA(
psz1: cstring, # LPCSTR
psz2: cstring, # LPCSTR
nChar: int32 # INT
): int32 {.importc: "StrCmpNIA", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
int StrCmpNIA(
const(char)* psz1, // LPCSTR
const(char)* psz2, // LPCSTR
int nChar // INT
);ccall((:StrCmpNIA, "SHLWAPI.dll"), stdcall, Int32,
(Cstring, Cstring, Int32),
psz1, psz2, nChar)
# psz1 : LPCSTR -> Cstring
# psz2 : LPCSTR -> Cstring
# nChar : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t StrCmpNIA(
const char* psz1,
const char* psz2,
int32_t nChar);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.StrCmpNIA(psz1, psz2, nChar)
-- psz1 : LPCSTR
-- psz2 : LPCSTR
-- nChar : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const StrCmpNIA = lib.func('__stdcall', 'StrCmpNIA', 'int32_t', ['str', 'str', 'int32_t']);
// StrCmpNIA(psz1, psz2, nChar)
// psz1 : LPCSTR -> 'str'
// psz2 : LPCSTR -> 'str'
// nChar : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
StrCmpNIA: { parameters: ["buffer", "buffer", "i32"], result: "i32" },
});
// lib.symbols.StrCmpNIA(psz1, psz2, nChar)
// psz1 : LPCSTR -> "buffer"
// psz2 : LPCSTR -> "buffer"
// nChar : INT -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t StrCmpNIA(
const char* psz1,
const char* psz2,
int32_t nChar);
C, "SHLWAPI.dll");
// $ffi->StrCmpNIA(psz1, psz2, nChar);
// psz1 : LPCSTR
// psz2 : LPCSTR
// nChar : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Shlwapi extends StdCallLibrary {
Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.ASCII_OPTIONS);
int StrCmpNIA(
String psz1, // LPCSTR
String psz2, // LPCSTR
int nChar // INT
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun StrCmpNIA = StrCmpNIA(
psz1 : UInt8*, # LPCSTR
psz2 : UInt8*, # LPCSTR
nChar : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef StrCmpNIANative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Int32);
typedef StrCmpNIADart = int Function(Pointer<Utf8>, Pointer<Utf8>, int);
final StrCmpNIA = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<StrCmpNIANative, StrCmpNIADart>('StrCmpNIA');
// psz1 : LPCSTR -> Pointer<Utf8>
// psz2 : LPCSTR -> Pointer<Utf8>
// nChar : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function StrCmpNIA(
psz1: PAnsiChar; // LPCSTR
psz2: PAnsiChar; // LPCSTR
nChar: Integer // INT
): Integer; stdcall;
external 'SHLWAPI.dll' name 'StrCmpNIA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "StrCmpNIA"
c_StrCmpNIA :: CString -> CString -> Int32 -> IO Int32
-- psz1 : LPCSTR -> CString
-- psz2 : LPCSTR -> CString
-- nChar : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let strcmpnia =
foreign "StrCmpNIA"
(string @-> string @-> int32_t @-> returning int32_t)
(* psz1 : LPCSTR -> string *)
(* psz2 : LPCSTR -> string *)
(* nChar : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("StrCmpNIA" str-cmp-nia :convention :stdcall) :int32
(psz1 :string) ; LPCSTR
(psz2 :string) ; LPCSTR
(n-char :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $StrCmpNIA = Win32::API::More->new('SHLWAPI',
'int StrCmpNIA(LPCSTR psz1, LPCSTR psz2, int nChar)');
# my $ret = $StrCmpNIA->Call($psz1, $psz2, $nChar);
# psz1 : LPCSTR -> LPCSTR
# psz2 : LPCSTR -> LPCSTR
# nChar : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f StrCmpNIW (Unicode版) — 指定文字数だけ大小文字を区別せず文字列を比較する。