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

IdnToNameprepUnicode

関数
国際化ドメイン名にNameprep正規化を適用する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

INT IdnToNameprepUnicode(
    DWORD dwFlags,
    LPCWSTR lpUnicodeCharStr,
    INT cchUnicodeChar,
    LPWSTR lpNameprepCharStr,   // optional
    INT cchNameprepChar
);

パラメーター

名前方向
dwFlagsDWORDin
lpUnicodeCharStrLPCWSTRin
cchUnicodeCharINTin
lpNameprepCharStrLPWSTRoutoptional
cchNameprepCharINTin

戻り値の型: INT

各言語での呼び出し定義

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

INT IdnToNameprepUnicode(
    DWORD dwFlags,
    LPCWSTR lpUnicodeCharStr,
    INT cchUnicodeChar,
    LPWSTR lpNameprepCharStr,   // optional
    INT cchNameprepChar
);
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern int IdnToNameprepUnicode(
    uint dwFlags,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpUnicodeCharStr,   // LPCWSTR
    int cchUnicodeChar,   // INT
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpNameprepCharStr,   // LPWSTR optional, out
    int cchNameprepChar   // INT
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function IdnToNameprepUnicode(
    dwFlags As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpUnicodeCharStr As String,   ' LPCWSTR
    cchUnicodeChar As Integer,   ' INT
    <MarshalAs(UnmanagedType.LPWStr)> lpNameprepCharStr As System.Text.StringBuilder,   ' LPWSTR optional, out
    cchNameprepChar As Integer   ' INT
) As Integer
End Function
' dwFlags : DWORD
' lpUnicodeCharStr : LPCWSTR
' cchUnicodeChar : INT
' lpNameprepCharStr : LPWSTR optional, out
' cchNameprepChar : INT
Declare PtrSafe Function IdnToNameprepUnicode Lib "kernel32" ( _
    ByVal dwFlags As Long, _
    ByVal lpUnicodeCharStr As LongPtr, _
    ByVal cchUnicodeChar As Long, _
    ByVal lpNameprepCharStr As LongPtr, _
    ByVal cchNameprepChar As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

IdnToNameprepUnicode = ctypes.windll.kernel32.IdnToNameprepUnicode
IdnToNameprepUnicode.restype = ctypes.c_int
IdnToNameprepUnicode.argtypes = [
    wintypes.DWORD,  # dwFlags : DWORD
    wintypes.LPCWSTR,  # lpUnicodeCharStr : LPCWSTR
    ctypes.c_int,  # cchUnicodeChar : INT
    wintypes.LPWSTR,  # lpNameprepCharStr : LPWSTR optional, out
    ctypes.c_int,  # cchNameprepChar : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procIdnToNameprepUnicode = kernel32.NewProc("IdnToNameprepUnicode")
)

// dwFlags (DWORD), lpUnicodeCharStr (LPCWSTR), cchUnicodeChar (INT), lpNameprepCharStr (LPWSTR optional, out), cchNameprepChar (INT)
r1, _, err := procIdnToNameprepUnicode.Call(
	uintptr(dwFlags),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpUnicodeCharStr))),
	uintptr(cchUnicodeChar),
	uintptr(lpNameprepCharStr),
	uintptr(cchNameprepChar),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function IdnToNameprepUnicode(
  dwFlags: DWORD;   // DWORD
  lpUnicodeCharStr: PWideChar;   // LPCWSTR
  cchUnicodeChar: Integer;   // INT
  lpNameprepCharStr: PWideChar;   // LPWSTR optional, out
  cchNameprepChar: Integer   // INT
): Integer; stdcall;
  external 'KERNEL32.dll' name 'IdnToNameprepUnicode';
result := DllCall("KERNEL32\IdnToNameprepUnicode"
    , "UInt", dwFlags   ; DWORD
    , "WStr", lpUnicodeCharStr   ; LPCWSTR
    , "Int", cchUnicodeChar   ; INT
    , "Ptr", lpNameprepCharStr   ; LPWSTR optional, out
    , "Int", cchNameprepChar   ; INT
    , "Int")   ; return: INT
●IdnToNameprepUnicode(dwFlags, lpUnicodeCharStr, cchUnicodeChar, lpNameprepCharStr, cchNameprepChar) = DLL("KERNEL32.dll", "int IdnToNameprepUnicode(dword, char*, int, char*, int)")
# 呼び出し: IdnToNameprepUnicode(dwFlags, lpUnicodeCharStr, cchUnicodeChar, lpNameprepCharStr, cchNameprepChar)
# dwFlags : DWORD -> "dword"
# lpUnicodeCharStr : LPCWSTR -> "char*"
# cchUnicodeChar : INT -> "int"
# lpNameprepCharStr : LPWSTR optional, out -> "char*"
# cchNameprepChar : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。