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