FindNLSStringEx
関数シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| lpLocaleName | LPCWSTR | inoptional | ロケール名へのポインター、または次の定義済みの値のいずれか。 | ||||||||||
| dwFindNLSStringFlags | DWORD | in | 検索操作の詳細を指定するフラグ。これらのフラグは相互に排他的で、既定値は FIND_FROMSTART です。アプリケーションは、検索フラグのいずれか 1 つを、次の表で定義されている任意のフィルター処理フラグと組み合わせて指定できます。アプリケーションがフラグを指定しない場合、この関数は指定されたロケールの既定の比較を使用します。Handling Sorting in Your Applications で説明されているとおり、バイナリ比較モードは存在しません。
アプリケーションは、以下で定義されているフィルター処理フラグを検索フラグと組み合わせて使用できます。 | ||||||||||
| lpStringSource | LPCWSTR | in | ソース文字列へのポインター。この文字列の中から、lpStringValue で指定された文字列を関数が検索します。 | ||||||||||
| cchSource | INT | in | lpStringSource で示される文字列のサイズ(終端の null 文字を除く文字数)。アプリケーションは、このパラメーターに 0 や、-1 以外の負の数を指定できません。ソース文字列が null 終端されており、関数にサイズを自動的に計算させたい場合は、-1 を指定します。 | ||||||||||
| lpStringValue | LPCWSTR | in | 検索文字列へのポインター。関数はこの文字列をソース文字列の中から検索します。 | ||||||||||
| cchValue | INT | in | lpStringValue で示される文字列のサイズ(終端の null 文字を除く文字数)。アプリケーションは、このパラメーターに 0 や、-1 以外の負の数を指定できません。検索文字列が null 終端されており、関数にサイズを自動的に計算させたい場合は、-1 を指定します。 | ||||||||||
| pcchFound | INT* | outoptional | 関数が見つけた文字列の長さを格納するバッファーへのポインター。見つかった文字列は、検索文字列より長い場合も短い場合もあります。検索文字列が見つからなかった場合、このパラメーターは変更されません。 このパラメーターには NULL を指定できます。その場合、見つかった文字列の長さがソース文字列の長さと異なるかどうかを関数は示しません。 pcchFound の値は cchValue に指定した値と一致することが多いですが、次の場合には異なることがあります。
| ||||||||||
| lpVersionInformation | NLSVERSIONINFO* | inoptional | 予約済み。NULL を指定する必要があります。 | ||||||||||
| lpReserved | void* | inoptional | 予約済み。NULL を指定する必要があります。 | ||||||||||
| sortHandle | LPARAM | in | 予約済み。0 を指定する必要があります。 |
戻り値の型: INT
公式ドキュメント
名前で指定されたロケールについて、ある Unicode 文字列(ワイド文字)またはその等価な文字列を、別の Unicode 文字列の中から検索します。注意 バイナリ表現が大きく異なる文字列どうしが同一として比較されることがあるため、この関数にはセキュリティ上の懸念が生じる可能性があります。詳細については、Security Considerations: International Features における比較関数の説明を参照してください。
戻り値
成功した場合、lpStringSource で示されるソース文字列に対する 0 から始まるインデックスを返します。pcchFound の値と組み合わせることで、このインデックスはソース文字列内で見つかった文字列全体の正確な位置を示します。戻り値 0 はソース文字列に対する有効なインデックスであり、一致した文字列はソース文字列のオフセット 0 の位置にあります。
成功しなかった場合、関数は -1 を返します。拡張エラー情報を取得するには、アプリケーションは GetLastError を呼び出すことができます。この関数は次のいずれかのエラーコードを返す可能性があります。
- ERROR_INVALID_FLAGS。フラグに指定された値が無効でした。
- ERROR_INVALID_PARAMETER。いずれかのパラメーター値が無効でした。
- ERROR_SUCCESS。処理は正常に完了しましたが、結果が得られませんでした。
解説(Remarks)
この関数は、検索方向、文字の等価性によるフィルター処理、ロケール固有のフィルター処理など、さまざまな検索オプションを提供します。等価性は、関数呼び出し時に指定したロケールおよびフラグに依存することに注意してください。フィルター処理フラグは検索結果を変化させることがあります。たとえば、検索時に大文字小文字やダイアクリティカルマークを無視すると、一致する可能性のある候補が増えます。
既定では、この関数は Locale パラメーターにトルコ語(トルコ)やアゼルバイジャン語(アゼルバイジャン)が指定されている場合でも、小文字の "i" を大文字の "I" にマッピングします。トルコ語またはアゼルバイジャン語でこの動作を上書きするには、アプリケーションは NORM_LINGUISTIC_CASING を指定する必要があります。適切なロケールに対してこのフラグを指定すると、"ı"(点のない小文字 I)は "I"(点のない大文字 I)の小文字形となり、"i"(点のある小文字 I)は "ı"(点のある大文字 I)の小文字形となります。
多くの文字体系(特にラテン文字)では、NORM_IGNORENONSPACE は LINGUISTIC_IGNOREDIACRITIC と一致し、NORM_IGNORECASE は LINGUISTIC_IGNORECASE と一致しますが、次の例外があります。
- NORM_IGNORENONSPACE は、ダイアクリティカルマークであるかどうかにかかわらず、あらゆる第 2 レベルの区別を無視します。韓国語、日本語、中国語、インド系言語などの文字体系では、この区別をダイアクリティカルマーク以外の目的にも使用します。LINGUISTIC_IGNOREDIACRITIC は、単に第 2 のソート重みを無視するのではなく、実際のダイアクリティカルマークのみを無視します。
- NORM_IGNORECASE は、実際の言語的な大文字小文字であるかどうかにかかわらず、あらゆる第 3 レベルの区別を無視します。たとえば、アラビア文字やインド系文字では、このフラグは文字の異体字を区別します。しかし、その違いは言語的な大文字小文字に対応するものではありません。LINGUISTIC_IGNORECASE は、第 3 のソート重みを無視するのではなく、実際の言語的な大文字小文字のみを無視します。
この関数は、成功した場合でも SetLastError を呼び出す数少ない NLS 関数の 1 つです。検索文字列との一致に失敗した場合に、スレッド内の直前のエラーをクリアするためにこの呼び出しを行います。これにより、GetLastError が返す値がクリアされます。
Windows 8 以降: アプリが Windows.Globalization 名前空間の言語タグをこの関数に渡す場合は、まず ResolveLocaleName を呼び出してタグを変換する必要があります。
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 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global FindNLSStringEx "FindNLSStringEx" wstr, int, wstr, int, wstr, int, sptr, sptr, sptr, sptr ; res = FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, varptr(pcchFound), varptr(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 -> "sptr" ; lpVersionInformation : NLSVERSIONINFO* optional -> "sptr" ; lpReserved : void* optional -> "sptr" ; sortHandle : LPARAM -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, intptr, intptr, intptr ; res = FindNLSStringEx(lpLocaleName, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, varptr(pcchFound), varptr(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 -> "intptr" ; lpVersionInformation : NLSVERSIONINFO* optional -> "intptr" ; lpReserved : void* optional -> "intptr" ; sortHandle : LPARAM -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // INTfunction 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 を使用。関連項目
- f FindNLSString — ロケールを考慮して文字列内から部分文字列を検索する。
- f CompareStringEx — ロケール名を指定して二つの文字列を比較する。
- f LCMapStringEx — ロケール名を指定して文字列を変換またはソートキー生成する。