ホーム › Globalization › FindNLSString
FindNLSString
関数ロケールを考慮して文字列内から部分文字列を検索する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
INT FindNLSString(
DWORD Locale,
DWORD dwFindNLSStringFlags,
LPCWSTR lpStringSource,
INT cchSource,
LPCWSTR lpStringValue,
INT cchValue,
INT* pcchFound // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Locale | DWORD | in |
| dwFindNLSStringFlags | DWORD | in |
| lpStringSource | LPCWSTR | in |
| cchSource | INT | in |
| lpStringValue | LPCWSTR | in |
| cchValue | INT | in |
| pcchFound | INT* | outoptional |
戻り値の型: INT
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
INT FindNLSString(
DWORD Locale,
DWORD dwFindNLSStringFlags,
LPCWSTR lpStringSource,
INT cchSource,
LPCWSTR lpStringValue,
INT cchValue,
INT* pcchFound // optional
);[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern int FindNLSString(
uint Locale, // DWORD
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
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindNLSString(
Locale As UInteger, ' DWORD
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
) As Integer
End Function' Locale : DWORD
' dwFindNLSStringFlags : DWORD
' lpStringSource : LPCWSTR
' cchSource : INT
' lpStringValue : LPCWSTR
' cchValue : INT
' pcchFound : INT* optional, out
Declare PtrSafe Function FindNLSString Lib "kernel32" ( _
ByVal Locale As Long, _
ByVal dwFindNLSStringFlags As Long, _
ByVal lpStringSource As LongPtr, _
ByVal cchSource As Long, _
ByVal lpStringValue As LongPtr, _
ByVal cchValue As Long, _
ByVal pcchFound As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FindNLSString = ctypes.windll.kernel32.FindNLSString
FindNLSString.restype = ctypes.c_int
FindNLSString.argtypes = [
wintypes.DWORD, # Locale : DWORD
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
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
FindNLSString = Fiddle::Function.new(
lib['FindNLSString'],
[
-Fiddle::TYPE_INT, # Locale : DWORD
-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_INT)#[link(name = "kernel32")]
extern "system" {
fn FindNLSString(
Locale: u32, // DWORD
dwFindNLSStringFlags: u32, // DWORD
lpStringSource: *const u16, // LPCWSTR
cchSource: i32, // INT
lpStringValue: *const u16, // LPCWSTR
cchValue: i32, // INT
pcchFound: *mut i32 // INT* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern int FindNLSString(uint Locale, uint dwFindNLSStringFlags, [MarshalAs(UnmanagedType.LPWStr)] string lpStringSource, int cchSource, [MarshalAs(UnmanagedType.LPWStr)] string lpStringValue, int cchValue, IntPtr pcchFound);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FindNLSString' -Namespace Win32 -PassThru
# $api::FindNLSString(Locale, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound)#uselib "KERNEL32.dll"
#func global FindNLSString "FindNLSString" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; FindNLSString Locale, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, varptr(pcchFound) ; 戻り値は stat
; Locale : DWORD -> "sptr"
; dwFindNLSStringFlags : DWORD -> "sptr"
; lpStringSource : LPCWSTR -> "sptr"
; cchSource : INT -> "sptr"
; lpStringValue : LPCWSTR -> "sptr"
; cchValue : INT -> "sptr"
; pcchFound : INT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global FindNLSString "FindNLSString" int, int, wstr, int, wstr, int, var ; res = FindNLSString(Locale, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound) ; Locale : DWORD -> "int" ; dwFindNLSStringFlags : DWORD -> "int" ; lpStringSource : LPCWSTR -> "wstr" ; cchSource : INT -> "int" ; lpStringValue : LPCWSTR -> "wstr" ; cchValue : INT -> "int" ; pcchFound : INT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global FindNLSString "FindNLSString" int, int, wstr, int, wstr, int, sptr ; res = FindNLSString(Locale, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, varptr(pcchFound)) ; Locale : DWORD -> "int" ; dwFindNLSStringFlags : DWORD -> "int" ; lpStringSource : LPCWSTR -> "wstr" ; cchSource : INT -> "int" ; lpStringValue : LPCWSTR -> "wstr" ; cchValue : INT -> "int" ; pcchFound : INT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT FindNLSString(DWORD Locale, DWORD dwFindNLSStringFlags, LPCWSTR lpStringSource, INT cchSource, LPCWSTR lpStringValue, INT cchValue, INT* pcchFound) #uselib "KERNEL32.dll" #cfunc global FindNLSString "FindNLSString" int, int, wstr, int, wstr, int, var ; res = FindNLSString(Locale, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound) ; Locale : DWORD -> "int" ; dwFindNLSStringFlags : DWORD -> "int" ; lpStringSource : LPCWSTR -> "wstr" ; cchSource : INT -> "int" ; lpStringValue : LPCWSTR -> "wstr" ; cchValue : INT -> "int" ; pcchFound : INT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT FindNLSString(DWORD Locale, DWORD dwFindNLSStringFlags, LPCWSTR lpStringSource, INT cchSource, LPCWSTR lpStringValue, INT cchValue, INT* pcchFound) #uselib "KERNEL32.dll" #cfunc global FindNLSString "FindNLSString" int, int, wstr, int, wstr, int, intptr ; res = FindNLSString(Locale, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, varptr(pcchFound)) ; Locale : DWORD -> "int" ; dwFindNLSStringFlags : DWORD -> "int" ; lpStringSource : LPCWSTR -> "wstr" ; cchSource : INT -> "int" ; lpStringValue : LPCWSTR -> "wstr" ; cchValue : INT -> "int" ; pcchFound : INT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procFindNLSString = kernel32.NewProc("FindNLSString")
)
// Locale (DWORD), dwFindNLSStringFlags (DWORD), lpStringSource (LPCWSTR), cchSource (INT), lpStringValue (LPCWSTR), cchValue (INT), pcchFound (INT* optional, out)
r1, _, err := procFindNLSString.Call(
uintptr(Locale),
uintptr(dwFindNLSStringFlags),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpStringSource))),
uintptr(cchSource),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpStringValue))),
uintptr(cchValue),
uintptr(pcchFound),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction FindNLSString(
Locale: DWORD; // DWORD
dwFindNLSStringFlags: DWORD; // DWORD
lpStringSource: PWideChar; // LPCWSTR
cchSource: Integer; // INT
lpStringValue: PWideChar; // LPCWSTR
cchValue: Integer; // INT
pcchFound: Pointer // INT* optional, out
): Integer; stdcall;
external 'KERNEL32.dll' name 'FindNLSString';result := DllCall("KERNEL32\FindNLSString"
, "UInt", Locale ; DWORD
, "UInt", dwFindNLSStringFlags ; DWORD
, "WStr", lpStringSource ; LPCWSTR
, "Int", cchSource ; INT
, "WStr", lpStringValue ; LPCWSTR
, "Int", cchValue ; INT
, "Ptr", pcchFound ; INT* optional, out
, "Int") ; return: INT●FindNLSString(Locale, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound) = DLL("KERNEL32.dll", "int FindNLSString(dword, dword, char*, int, char*, int, void*)")
# 呼び出し: FindNLSString(Locale, dwFindNLSStringFlags, lpStringSource, cchSource, lpStringValue, cchValue, pcchFound)
# Locale : DWORD -> "dword"
# dwFindNLSStringFlags : DWORD -> "dword"
# lpStringSource : LPCWSTR -> "char*"
# cchSource : INT -> "int"
# lpStringValue : LPCWSTR -> "char*"
# cchValue : INT -> "int"
# pcchFound : INT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。