Win32 API 日本語リファレンス
ホームGlobalization › FindNLSStringEx

FindNLSStringEx

関数
ロケール名を指定して文字列内から部分文字列を検索する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

INT FindNLSStringEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD dwFindNLSStringFlags,
    LPCWSTR lpStringSource,
    INT cchSource,
    LPCWSTR lpStringValue,
    INT cchValue,
    INT* pcchFound,   // optional
    NLSVERSIONINFO* lpVersionInformation,   // optional
    void* lpReserved,   // optional
    LPARAM sortHandle
);

パラメーター

名前方向説明
lpLocaleNameLPCWSTRinoptional

ロケール名へのポインター、または次の定義済みの値のいずれか。

dwFindNLSStringFlagsDWORDin

検索操作の詳細を指定するフラグ。これらのフラグは相互に排他的で、既定値は FIND_FROMSTART です。アプリケーションは、検索フラグのいずれか 1 つを、次の表で定義されている任意のフィルター処理フラグと組み合わせて指定できます。アプリケーションがフラグを指定しない場合、この関数は指定されたロケールの既定の比較を使用します。Handling Sorting in Your Applications で説明されているとおり、バイナリ比較モードは存在しません。

意味
FIND_FROMSTART
文字列の先頭の文字から検索します。
FIND_FROMEND
文字列の末尾の文字から逆方向に検索します。
FIND_STARTSWITH
lpStringValue で指定された値が、lpStringSource で示されるソース文字列の先頭の値であるかどうかを判定します。
FIND_ENDSWITH
lpStringValue で指定された値が、lpStringSource で示されるソース文字列の末尾の値であるかどうかを判定します。

アプリケーションは、以下で定義されているフィルター処理フラグを検索フラグと組み合わせて使用できます。

意味
LINGUISTIC_IGNORECASE
言語的に適切な形で、検索時に大文字と小文字を区別しません。詳細については、「解説」を参照してください。
LINGUISTIC_IGNOREDIACRITIC
言語的に適切な形で、ダイアクリティカルマーク(発音区別符号)を無視します。詳細については、「解説」を参照してください。
注意 このフラグは、分解された文字、すなわち基底文字と 1 つ以上の非スペース文字がそれぞれ異なるコードポイント値を持つ文字に対して使用した場合、必ずしも予測可能な結果を生成しません。
NORM_IGNORECASE
検索時に大文字と小文字を区別しません。詳細については、「解説」を参照してください。
NORM_IGNOREKANATYPE
ひらがなとカタカナを区別しません。対応するひらがなとカタカナは等しいものとして比較されます。
NORM_IGNORENONSPACE
非スペース文字を無視します。詳細については、「解説」を参照してください。
NORM_IGNORESYMBOLS
記号および句読点を無視します。
NORM_IGNOREWIDTH
半角文字と全角文字の違いを無視します。たとえば、C a t == cat となります。全角形は、中国語および日本語の文字体系で用いられる書式上の区別です。
NORM_LINGUISTIC_CASING
大文字小文字の処理に、ファイルシステムの規則(既定)ではなく言語的な規則を使用します。詳細については、「解説」を参照してください。
lpStringSourceLPCWSTRinソース文字列へのポインター。この文字列の中から、lpStringValue で指定された文字列を関数が検索します。
cchSourceINTinlpStringSource で示される文字列のサイズ(終端の null 文字を除く文字数)。アプリケーションは、このパラメーターに 0 や、-1 以外の負の数を指定できません。ソース文字列が null 終端されており、関数にサイズを自動的に計算させたい場合は、-1 を指定します。
lpStringValueLPCWSTRin検索文字列へのポインター。関数はこの文字列をソース文字列の中から検索します。
cchValueINTinlpStringValue で示される文字列のサイズ(終端の null 文字を除く文字数)。アプリケーションは、このパラメーターに 0 や、-1 以外の負の数を指定できません。検索文字列が null 終端されており、関数にサイズを自動的に計算させたい場合は、-1 を指定します。
pcchFoundINT*outoptional

関数が見つけた文字列の長さを格納するバッファーへのポインター。見つかった文字列は、検索文字列より長い場合も短い場合もあります。検索文字列が見つからなかった場合、このパラメーターは変更されません。

このパラメーターには NULL を指定できます。その場合、見つかった文字列の長さがソース文字列の長さと異なるかどうかを関数は示しません。

pcchFound の値は cchValue に指定した値と一致することが多いですが、次の場合には異なることがあります。

  • cchValue に指定した値が負の場合。
  • 文字列が等価であるものの、長さが異なる場合。たとえば、"A" に "Combining Ring" を加えたもの(U+0041 U+030A)は、"A Ring"(U+00c5)と等価です。
lpVersionInformationNLSVERSIONINFO*inoptional予約済み。NULL を指定する必要があります。
lpReservedvoid*inoptional予約済み。NULL を指定する必要があります。
sortHandleLPARAMin予約済み。0 を指定する必要があります。

戻り値の型: INT

公式ドキュメント

名前で指定されたロケールについて、ある Unicode 文字列(ワイド文字)またはその等価な文字列を、別の Unicode 文字列の中から検索します。注意 バイナリ表現が大きく異なる文字列どうしが同一として比較されることがあるため、この関数にはセキュリティ上の懸念が生じる可能性があります。詳細については、Security Considerations: International Features における比較関数の説明を参照してください。

戻り値

成功した場合、lpStringSource で示されるソース文字列に対する 0 から始まるインデックスを返します。pcchFound の値と組み合わせることで、このインデックスはソース文字列内で見つかった文字列全体の正確な位置を示します。戻り値 0 はソース文字列に対する有効なインデックスであり、一致した文字列はソース文字列のオフセット 0 の位置にあります。

成功しなかった場合、関数は -1 を返します。拡張エラー情報を取得するには、アプリケーションは GetLastError を呼び出すことができます。この関数は次のいずれかのエラーコードを返す可能性があります。

解説(Remarks)

この関数は、検索方向、文字の等価性によるフィルター処理、ロケール固有のフィルター処理など、さまざまな検索オプションを提供します。等価性は、関数呼び出し時に指定したロケールおよびフラグに依存することに注意してください。フィルター処理フラグは検索結果を変化させることがあります。たとえば、検索時に大文字小文字やダイアクリティカルマークを無視すると、一致する可能性のある候補が増えます。

既定では、この関数は Locale パラメーターにトルコ語(トルコ)やアゼルバイジャン語(アゼルバイジャン)が指定されている場合でも、小文字の "i" を大文字の "I" にマッピングします。トルコ語またはアゼルバイジャン語でこの動作を上書きするには、アプリケーションは NORM_LINGUISTIC_CASING を指定する必要があります。適切なロケールに対してこのフラグを指定すると、"ı"(点のない小文字 I)は "I"(点のない大文字 I)の小文字形となり、"i"(点のある小文字 I)は "ı"(点のある大文字 I)の小文字形となります。

多くの文字体系(特にラテン文字)では、NORM_IGNORENONSPACELINGUISTIC_IGNOREDIACRITIC と一致し、NORM_IGNORECASELINGUISTIC_IGNORECASE と一致しますが、次の例外があります。

失敗時に 0 を返す他の NLS API 関数とは対照的に、この関数は失敗した場合に -1 を返します。成功した場合は、0 から始まるインデックスを返します。このインデックスを使用することで、関数は 1 個ずれ(off-by-one)エラーや 1 文字分のバッファーオーバーランを回避できます。

この関数は、成功した場合でも SetLastError を呼び出す数少ない NLS 関数の 1 つです。検索文字列との一致に失敗した場合に、スレッド内の直前のエラーをクリアするためにこの呼び出しを行います。これにより、GetLastError が返す値がクリアされます。

Windows 8 以降: アプリが Windows.Globalization 名前空間の言語タグをこの関数に渡す場合は、まず ResolveLocaleName を呼び出してタグを変換する必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

INT FindNLSStringEx(
    LPCWSTR lpLocaleName,   // optional
    DWORD dwFindNLSStringFlags,
    LPCWSTR lpStringSource,
    INT cchSource,
    LPCWSTR lpStringValue,
    INT cchValue,
    INT* pcchFound,   // optional
    NLSVERSIONINFO* lpVersionInformation,   // optional
    void* lpReserved,   // optional
    LPARAM sortHandle
);
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern int FindNLSStringEx(
    [MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName,   // LPCWSTR optional
    uint dwFindNLSStringFlags,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpStringSource,   // LPCWSTR
    int cchSource,   // INT
    [MarshalAs(UnmanagedType.LPWStr)] string lpStringValue,   // LPCWSTR
    int cchValue,   // INT
    IntPtr pcchFound,   // INT* optional, out
    IntPtr lpVersionInformation,   // NLSVERSIONINFO* optional
    IntPtr lpReserved,   // void* optional
    IntPtr sortHandle   // LPARAM
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindNLSStringEx(
    <MarshalAs(UnmanagedType.LPWStr)> lpLocaleName As String,   ' LPCWSTR optional
    dwFindNLSStringFlags As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpStringSource As String,   ' LPCWSTR
    cchSource As Integer,   ' INT
    <MarshalAs(UnmanagedType.LPWStr)> lpStringValue As String,   ' LPCWSTR
    cchValue As Integer,   ' INT
    pcchFound As IntPtr,   ' INT* optional, out
    lpVersionInformation As IntPtr,   ' NLSVERSIONINFO* optional
    lpReserved As IntPtr,   ' void* optional
    sortHandle As IntPtr   ' LPARAM
) As Integer
End Function
' lpLocaleName : LPCWSTR optional
' dwFindNLSStringFlags : DWORD
' lpStringSource : LPCWSTR
' cchSource : INT
' lpStringValue : LPCWSTR
' cchValue : INT
' pcchFound : INT* optional, out
' lpVersionInformation : NLSVERSIONINFO* optional
' lpReserved : void* optional
' sortHandle : LPARAM
Declare PtrSafe Function FindNLSStringEx Lib "kernel32" ( _
    ByVal lpLocaleName As LongPtr, _
    ByVal dwFindNLSStringFlags As Long, _
    ByVal lpStringSource As LongPtr, _
    ByVal cchSource As Long, _
    ByVal lpStringValue As LongPtr, _
    ByVal cchValue As Long, _
    ByVal pcchFound As LongPtr, _
    ByVal lpVersionInformation As LongPtr, _
    ByVal lpReserved As LongPtr, _
    ByVal sortHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FindNLSStringEx = ctypes.windll.kernel32.FindNLSStringEx
FindNLSStringEx.restype = ctypes.c_int
FindNLSStringEx.argtypes = [
    wintypes.LPCWSTR,  # lpLocaleName : LPCWSTR optional
    wintypes.DWORD,  # dwFindNLSStringFlags : DWORD
    wintypes.LPCWSTR,  # lpStringSource : LPCWSTR
    ctypes.c_int,  # cchSource : INT
    wintypes.LPCWSTR,  # lpStringValue : LPCWSTR
    ctypes.c_int,  # cchValue : INT
    ctypes.POINTER(ctypes.c_int),  # pcchFound : INT* optional, out
    ctypes.c_void_p,  # lpVersionInformation : NLSVERSIONINFO* optional
    ctypes.POINTER(None),  # lpReserved : void* optional
    ctypes.c_ssize_t,  # sortHandle : LPARAM
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
FindNLSStringEx = Fiddle::Function.new(
  lib['FindNLSStringEx'],
  [
    Fiddle::TYPE_VOIDP,  # lpLocaleName : LPCWSTR optional
    -Fiddle::TYPE_INT,  # dwFindNLSStringFlags : DWORD
    Fiddle::TYPE_VOIDP,  # lpStringSource : LPCWSTR
    Fiddle::TYPE_INT,  # cchSource : INT
    Fiddle::TYPE_VOIDP,  # lpStringValue : LPCWSTR
    Fiddle::TYPE_INT,  # cchValue : INT
    Fiddle::TYPE_VOIDP,  # pcchFound : INT* optional, out
    Fiddle::TYPE_VOIDP,  # lpVersionInformation : NLSVERSIONINFO* optional
    Fiddle::TYPE_VOIDP,  # lpReserved : void* optional
    Fiddle::TYPE_INTPTR_T,  # sortHandle : LPARAM
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn FindNLSStringEx(
        lpLocaleName: *const u16,  // LPCWSTR optional
        dwFindNLSStringFlags: u32,  // DWORD
        lpStringSource: *const u16,  // LPCWSTR
        cchSource: i32,  // INT
        lpStringValue: *const u16,  // LPCWSTR
        cchValue: i32,  // INT
        pcchFound: *mut i32,  // INT* optional, out
        lpVersionInformation: *mut NLSVERSIONINFO,  // NLSVERSIONINFO* optional
        lpReserved: *mut (),  // void* optional
        sortHandle: isize  // LPARAM
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern int FindNLSStringEx([MarshalAs(UnmanagedType.LPWStr)] string lpLocaleName, uint dwFindNLSStringFlags, [MarshalAs(UnmanagedType.LPWStr)] string lpStringSource, int cchSource, [MarshalAs(UnmanagedType.LPWStr)] string lpStringValue, int cchValue, IntPtr pcchFound, IntPtr lpVersionInformation, IntPtr lpReserved, IntPtr sortHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FindNLSStringEx' -Namespace Win32 -PassThru
# $api::FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle)
#uselib "KERNEL32.dll"
#func global FindNLSStringEx "FindNLSStringEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; FindNLSStringEx lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, varptr(pcchFound), varptr(lpVersionInformation), lpReserved, sortHandle   ; 戻り値は stat
; lpLocaleName : LPCWSTR optional -> "sptr"
; dwFindNLSStringFlags : DWORD -> "sptr"
; lpStringSource : LPCWSTR -> "sptr"
; cchSource : INT -> "sptr"
; lpStringValue : LPCWSTR -> "sptr"
; cchValue : INT -> "sptr"
; pcchFound : INT* optional, out -> "sptr"
; lpVersionInformation : NLSVERSIONINFO* optional -> "sptr"
; lpReserved : void* optional -> "sptr"
; sortHandle : LPARAM -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global FindNLSStringEx "FindNLSStringEx" wstr, int, wstr, int, wstr, int, var, var, sptr, sptr
; res = FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle)
; lpLocaleName : LPCWSTR optional -> "wstr"
; dwFindNLSStringFlags : DWORD -> "int"
; lpStringSource : LPCWSTR -> "wstr"
; cchSource : INT -> "int"
; lpStringValue : LPCWSTR -> "wstr"
; cchValue : INT -> "int"
; pcchFound : INT* optional, out -> "var"
; lpVersionInformation : NLSVERSIONINFO* optional -> "var"
; lpReserved : void* optional -> "sptr"
; sortHandle : LPARAM -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT FindNLSStringEx(LPCWSTR lpLocaleName, DWORD dwFindNLSStringFlags, LPCWSTR lpStringSource, INT cchSource, LPCWSTR lpStringValue, INT cchValue, INT* pcchFound, NLSVERSIONINFO* lpVersionInformation, void* lpReserved, LPARAM sortHandle)
#uselib "KERNEL32.dll"
#cfunc global FindNLSStringEx "FindNLSStringEx" wstr, int, wstr, int, wstr, int, var, var, intptr, intptr
; res = FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle)
; lpLocaleName : LPCWSTR optional -> "wstr"
; dwFindNLSStringFlags : DWORD -> "int"
; lpStringSource : LPCWSTR -> "wstr"
; cchSource : INT -> "int"
; lpStringValue : LPCWSTR -> "wstr"
; cchValue : INT -> "int"
; pcchFound : INT* optional, out -> "var"
; lpVersionInformation : NLSVERSIONINFO* optional -> "var"
; lpReserved : void* optional -> "intptr"
; sortHandle : LPARAM -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFindNLSStringEx = kernel32.NewProc("FindNLSStringEx")
)

// lpLocaleName (LPCWSTR optional), dwFindNLSStringFlags (DWORD), lpStringSource (LPCWSTR), cchSource (INT), lpStringValue (LPCWSTR), cchValue (INT), pcchFound (INT* optional, out), lpVersionInformation (NLSVERSIONINFO* optional), lpReserved (void* optional), sortHandle (LPARAM)
r1, _, err := procFindNLSStringEx.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpLocaleName))),
	uintptr(dwFindNLSStringFlags),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpStringSource))),
	uintptr(cchSource),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpStringValue))),
	uintptr(cchValue),
	uintptr(pcchFound),
	uintptr(lpVersionInformation),
	uintptr(lpReserved),
	uintptr(sortHandle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function FindNLSStringEx(
  lpLocaleName: PWideChar;   // LPCWSTR optional
  dwFindNLSStringFlags: DWORD;   // DWORD
  lpStringSource: PWideChar;   // LPCWSTR
  cchSource: Integer;   // INT
  lpStringValue: PWideChar;   // LPCWSTR
  cchValue: Integer;   // INT
  pcchFound: Pointer;   // INT* optional, out
  lpVersionInformation: Pointer;   // NLSVERSIONINFO* optional
  lpReserved: Pointer;   // void* optional
  sortHandle: NativeInt   // LPARAM
): Integer; stdcall;
  external 'KERNEL32.dll' name 'FindNLSStringEx';
result := DllCall("KERNEL32\FindNLSStringEx"
    , "WStr", lpLocaleName   ; LPCWSTR optional
    , "UInt", dwFindNLSStringFlags   ; DWORD
    , "WStr", lpStringSource   ; LPCWSTR
    , "Int", cchSource   ; INT
    , "WStr", lpStringValue   ; LPCWSTR
    , "Int", cchValue   ; INT
    , "Ptr", pcchFound   ; INT* optional, out
    , "Ptr", lpVersionInformation   ; NLSVERSIONINFO* optional
    , "Ptr", lpReserved   ; void* optional
    , "Ptr", sortHandle   ; LPARAM
    , "Int")   ; return: INT
●FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle) = DLL("KERNEL32.dll", "int FindNLSStringEx(char*, dword, char*, int, char*, int, void*, void*, void*, int)")
# 呼び出し: FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle)
# lpLocaleName : LPCWSTR optional -> "char*"
# dwFindNLSStringFlags : DWORD -> "dword"
# lpStringSource : LPCWSTR -> "char*"
# cchSource : INT -> "int"
# lpStringValue : LPCWSTR -> "char*"
# cchValue : INT -> "int"
# pcchFound : INT* optional, out -> "void*"
# lpVersionInformation : NLSVERSIONINFO* optional -> "void*"
# lpReserved : void* optional -> "void*"
# sortHandle : LPARAM -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn FindNLSStringEx(
    lpLocaleName: [*c]const u16, // LPCWSTR optional
    dwFindNLSStringFlags: u32, // DWORD
    lpStringSource: [*c]const u16, // LPCWSTR
    cchSource: i32, // INT
    lpStringValue: [*c]const u16, // LPCWSTR
    cchValue: i32, // INT
    pcchFound: [*c]i32, // INT* optional, out
    lpVersionInformation: [*c]NLSVERSIONINFO, // NLSVERSIONINFO* optional
    lpReserved: ?*anyopaque, // void* optional
    sortHandle: isize // LPARAM
) callconv(std.os.windows.WINAPI) i32;
proc FindNLSStringEx(
    lpLocaleName: WideCString,  # LPCWSTR optional
    dwFindNLSStringFlags: uint32,  # DWORD
    lpStringSource: WideCString,  # LPCWSTR
    cchSource: int32,  # INT
    lpStringValue: WideCString,  # LPCWSTR
    cchValue: int32,  # INT
    pcchFound: ptr int32,  # INT* optional, out
    lpVersionInformation: ptr NLSVERSIONINFO,  # NLSVERSIONINFO* optional
    lpReserved: pointer,  # void* optional
    sortHandle: int  # LPARAM
): int32 {.importc: "FindNLSStringEx", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int FindNLSStringEx(
    const(wchar)* lpLocaleName,   // LPCWSTR optional
    uint dwFindNLSStringFlags,   // DWORD
    const(wchar)* lpStringSource,   // LPCWSTR
    int cchSource,   // INT
    const(wchar)* lpStringValue,   // LPCWSTR
    int cchValue,   // INT
    int* pcchFound,   // INT* optional, out
    NLSVERSIONINFO* lpVersionInformation,   // NLSVERSIONINFO* optional
    void* lpReserved,   // void* optional
    ptrdiff_t sortHandle   // LPARAM
);
ccall((:FindNLSStringEx, "KERNEL32.dll"), stdcall, Int32,
      (Cwstring, UInt32, Cwstring, Int32, Cwstring, Int32, Ptr{Int32}, Ptr{NLSVERSIONINFO}, Ptr{Cvoid}, Int),
      lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle)
# lpLocaleName : LPCWSTR optional -> Cwstring
# dwFindNLSStringFlags : DWORD -> UInt32
# lpStringSource : LPCWSTR -> Cwstring
# cchSource : INT -> Int32
# lpStringValue : LPCWSTR -> Cwstring
# cchValue : INT -> Int32
# pcchFound : INT* optional, out -> Ptr{Int32}
# lpVersionInformation : NLSVERSIONINFO* optional -> Ptr{NLSVERSIONINFO}
# lpReserved : void* optional -> Ptr{Cvoid}
# sortHandle : LPARAM -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t FindNLSStringEx(
    const uint16_t* lpLocaleName,
    uint32_t dwFindNLSStringFlags,
    const uint16_t* lpStringSource,
    int32_t cchSource,
    const uint16_t* lpStringValue,
    int32_t cchValue,
    int32_t* pcchFound,
    void* lpVersionInformation,
    void* lpReserved,
    intptr_t sortHandle);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle)
-- lpLocaleName : LPCWSTR optional
-- dwFindNLSStringFlags : DWORD
-- lpStringSource : LPCWSTR
-- cchSource : INT
-- lpStringValue : LPCWSTR
-- cchValue : INT
-- pcchFound : INT* optional, out
-- lpVersionInformation : NLSVERSIONINFO* optional
-- lpReserved : void* optional
-- sortHandle : LPARAM
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const FindNLSStringEx = lib.func('__stdcall', 'FindNLSStringEx', 'int32_t', ['str16', 'uint32_t', 'str16', 'int32_t', 'str16', 'int32_t', 'int32_t *', 'void *', 'void *', 'intptr_t']);
// FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle)
// lpLocaleName : LPCWSTR optional -> 'str16'
// dwFindNLSStringFlags : DWORD -> 'uint32_t'
// lpStringSource : LPCWSTR -> 'str16'
// cchSource : INT -> 'int32_t'
// lpStringValue : LPCWSTR -> 'str16'
// cchValue : INT -> 'int32_t'
// pcchFound : INT* optional, out -> 'int32_t *'
// lpVersionInformation : NLSVERSIONINFO* optional -> 'void *'
// lpReserved : void* optional -> 'void *'
// sortHandle : LPARAM -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  FindNLSStringEx: { parameters: ["buffer", "u32", "buffer", "i32", "buffer", "i32", "pointer", "pointer", "pointer", "isize"], result: "i32" },
});
// lib.symbols.FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle)
// lpLocaleName : LPCWSTR optional -> "buffer"
// dwFindNLSStringFlags : DWORD -> "u32"
// lpStringSource : LPCWSTR -> "buffer"
// cchSource : INT -> "i32"
// lpStringValue : LPCWSTR -> "buffer"
// cchValue : INT -> "i32"
// pcchFound : INT* optional, out -> "pointer"
// lpVersionInformation : NLSVERSIONINFO* optional -> "pointer"
// lpReserved : void* optional -> "pointer"
// sortHandle : LPARAM -> "isize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t FindNLSStringEx(
    const uint16_t* lpLocaleName,
    uint32_t dwFindNLSStringFlags,
    const uint16_t* lpStringSource,
    int32_t cchSource,
    const uint16_t* lpStringValue,
    int32_t cchValue,
    int32_t* pcchFound,
    void* lpVersionInformation,
    void* lpReserved,
    intptr_t sortHandle);
C, "KERNEL32.dll");
// $ffi->FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound, lpVersionInformation, lpReserved, sortHandle);
// lpLocaleName : LPCWSTR optional
// dwFindNLSStringFlags : DWORD
// lpStringSource : LPCWSTR
// cchSource : INT
// lpStringValue : LPCWSTR
// cchValue : INT
// pcchFound : INT* optional, out
// lpVersionInformation : NLSVERSIONINFO* optional
// lpReserved : void* optional
// sortHandle : LPARAM
// 構造体/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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    int FindNLSStringEx(
        WString lpLocaleName,   // LPCWSTR optional
        int dwFindNLSStringFlags,   // DWORD
        WString lpStringSource,   // LPCWSTR
        int cchSource,   // INT
        WString lpStringValue,   // LPCWSTR
        int cchValue,   // INT
        IntByReference pcchFound,   // INT* optional, out
        Pointer lpVersionInformation,   // NLSVERSIONINFO* optional
        Pointer lpReserved,   // void* optional
        long sortHandle   // LPARAM
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun FindNLSStringEx = FindNLSStringEx(
    lpLocaleName : UInt16*,   # LPCWSTR optional
    dwFindNLSStringFlags : UInt32,   # DWORD
    lpStringSource : UInt16*,   # LPCWSTR
    cchSource : Int32,   # INT
    lpStringValue : UInt16*,   # LPCWSTR
    cchValue : Int32,   # INT
    pcchFound : Int32*,   # INT* optional, out
    lpVersionInformation : NLSVERSIONINFO*,   # NLSVERSIONINFO* optional
    lpReserved : Void*,   # void* optional
    sortHandle : LibC::SSizeT   # LPARAM
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef FindNLSStringExNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>, Int32, Pointer<Utf16>, Int32, Pointer<Int32>, Pointer<Void>, Pointer<Void>, IntPtr);
typedef FindNLSStringExDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>, int, Pointer<Utf16>, int, Pointer<Int32>, Pointer<Void>, Pointer<Void>, int);
final FindNLSStringEx = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<FindNLSStringExNative, FindNLSStringExDart>('FindNLSStringEx');
// lpLocaleName : LPCWSTR optional -> Pointer<Utf16>
// dwFindNLSStringFlags : DWORD -> Uint32
// lpStringSource : LPCWSTR -> Pointer<Utf16>
// cchSource : INT -> Int32
// lpStringValue : LPCWSTR -> Pointer<Utf16>
// cchValue : INT -> Int32
// pcchFound : INT* optional, out -> Pointer<Int32>
// lpVersionInformation : NLSVERSIONINFO* optional -> Pointer<Void>
// lpReserved : void* optional -> Pointer<Void>
// sortHandle : LPARAM -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function FindNLSStringEx(
  lpLocaleName: PWideChar;   // LPCWSTR optional
  dwFindNLSStringFlags: DWORD;   // DWORD
  lpStringSource: PWideChar;   // LPCWSTR
  cchSource: Integer;   // INT
  lpStringValue: PWideChar;   // LPCWSTR
  cchValue: Integer;   // INT
  pcchFound: Pointer;   // INT* optional, out
  lpVersionInformation: Pointer;   // NLSVERSIONINFO* optional
  lpReserved: Pointer;   // void* optional
  sortHandle: NativeInt   // LPARAM
): Integer; stdcall;
  external 'KERNEL32.dll' name 'FindNLSStringEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "FindNLSStringEx"
  c_FindNLSStringEx :: CWString -> Word32 -> CWString -> Int32 -> CWString -> Int32 -> Ptr Int32 -> Ptr () -> Ptr () -> CIntPtr -> IO Int32
-- lpLocaleName : LPCWSTR optional -> CWString
-- dwFindNLSStringFlags : DWORD -> Word32
-- lpStringSource : LPCWSTR -> CWString
-- cchSource : INT -> Int32
-- lpStringValue : LPCWSTR -> CWString
-- cchValue : INT -> Int32
-- pcchFound : INT* optional, out -> Ptr Int32
-- lpVersionInformation : NLSVERSIONINFO* optional -> Ptr ()
-- lpReserved : void* optional -> Ptr ()
-- sortHandle : LPARAM -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let findnlsstringex =
  foreign "FindNLSStringEx"
    ((ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> (ptr int32_t) @-> (ptr void) @-> (ptr void) @-> intptr_t @-> returning int32_t)
(* lpLocaleName : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFindNLSStringFlags : DWORD -> uint32_t *)
(* lpStringSource : LPCWSTR -> (ptr uint16_t) *)
(* cchSource : INT -> int32_t *)
(* lpStringValue : LPCWSTR -> (ptr uint16_t) *)
(* cchValue : INT -> int32_t *)
(* pcchFound : INT* optional, out -> (ptr int32_t) *)
(* lpVersionInformation : NLSVERSIONINFO* optional -> (ptr void) *)
(* lpReserved : void* optional -> (ptr void) *)
(* sortHandle : LPARAM -> intptr_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("FindNLSStringEx" find-nlsstring-ex :convention :stdcall) :int32
  (lp-locale-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-find-nlsstring-flags :uint32)   ; DWORD
  (lp-string-source (:string :encoding :utf-16le))   ; LPCWSTR
  (cch-source :int32)   ; INT
  (lp-string-value (:string :encoding :utf-16le))   ; LPCWSTR
  (cch-value :int32)   ; INT
  (pcch-found :pointer)   ; INT* optional, out
  (lp-version-information :pointer)   ; NLSVERSIONINFO* optional
  (lp-reserved :pointer)   ; void* optional
  (sort-handle :int64))   ; LPARAM
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $FindNLSStringEx = Win32::API::More->new('KERNEL32',
    'int FindNLSStringEx(LPCWSTR lpLocaleName, DWORD dwFindNLSStringFlags, LPCWSTR lpStringSource, int cchSource, LPCWSTR lpStringValue, int cchValue, LPVOID pcchFound, LPVOID lpVersionInformation, LPVOID lpReserved, LPARAM sortHandle)');
# my $ret = $FindNLSStringEx->Call($lpLocaleName, $dwFindNLSStringFlags, $lpStringSource, $cchSource, $lpStringValue, $cchValue, $pcchFound, $lpVersionInformation, $lpReserved, $sortHandle);
# lpLocaleName : LPCWSTR optional -> LPCWSTR
# dwFindNLSStringFlags : DWORD -> DWORD
# lpStringSource : LPCWSTR -> LPCWSTR
# cchSource : INT -> int
# lpStringValue : LPCWSTR -> LPCWSTR
# cchValue : INT -> int
# pcchFound : INT* optional, out -> LPVOID
# lpVersionInformation : NLSVERSIONINFO* optional -> LPVOID
# lpReserved : void* optional -> LPVOID
# sortHandle : LPARAM -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
公式の関連項目
使用する型