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変換オプションを指定するフラグ。詳細な定義については、IdnToAsciidwFlags パラメーターを参照してください。
lpUnicodeCharStrLPCWSTRinIDN またはその他の国際化ラベルを表す Unicode 文字列へのポインター。
cchUnicodeCharINTinlpUnicodeCharStr で示される入力 Unicode 文字列内の Unicode 文字数。
lpNameprepCharStrLPWSTRoutoptionalNamePrep 処理を通じて変換された入力 Unicode 文字列を受け取るバッファーへのポインター。あるいは、cchNameprepChar を 0 に設定した場合、この関数はこのパラメーターに NULL を取得できます。この場合、関数はこのバッファーに必要なサイズを返します。
cchNameprepCharINTinlpNameprepCharStr で示されるバッファーのサイズ (文字数)。アプリケーションはサイズを 0 に設定することで、lpNameprepCharStrNULL を取得し、関数に必要なバッファーサイズを返させることができます。

戻り値の型: INT

公式ドキュメント

国際化ドメイン名 (IDN) またはその他の国際化ラベルを、Network Working Group RFC 3491 で規定された NamePrep 形式に変換します。ただし、Punycode への追加変換は行いません。

戻り値

成功した場合、lpNameprepCharStr に取得された文字数を返します。取得された文字列は、入力 Unicode 文字列が null で終端されている場合にのみ null で終端されます。

関数が成功し、cchNameprepChar の値が 0 の場合、関数は必要なサイズを文字数で返します。これには、終端の null 文字が入力バッファーの一部であった場合はその null 文字も含まれます。

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

解説(Remarks)

IdnToAscii の「解説」を参照してください。

NLS: 国際化ドメイン名 (IDN) 変換サンプル は、この関数の使用方法を示しています。

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

各言語での呼び出し定義

// 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)。
const std = @import("std");

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

typedef IdnToNameprepUnicodeNative = Int32 Function(Uint32, Pointer<Utf16>, Int32, Pointer<Utf16>, Int32);
typedef IdnToNameprepUnicodeDart = int Function(int, Pointer<Utf16>, int, Pointer<Utf16>, int);
final IdnToNameprepUnicode = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<IdnToNameprepUnicodeNative, IdnToNameprepUnicodeDart>('IdnToNameprepUnicode');
// dwFlags : DWORD -> Uint32
// lpUnicodeCharStr : LPCWSTR -> Pointer<Utf16>
// cchUnicodeChar : INT -> Int32
// lpNameprepCharStr : LPWSTR optional, out -> Pointer<Utf16>
// cchNameprepChar : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "IdnToNameprepUnicode"
  c_IdnToNameprepUnicode :: Word32 -> CWString -> Int32 -> CWString -> Int32 -> IO Int32
-- dwFlags : DWORD -> Word32
-- lpUnicodeCharStr : LPCWSTR -> CWString
-- cchUnicodeChar : INT -> Int32
-- lpNameprepCharStr : LPWSTR optional, out -> CWString
-- cchNameprepChar : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let idntonameprepunicode =
  foreign "IdnToNameprepUnicode"
    (uint32_t @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> int32_t @-> returning int32_t)
(* dwFlags : DWORD -> uint32_t *)
(* lpUnicodeCharStr : LPCWSTR -> (ptr uint16_t) *)
(* cchUnicodeChar : INT -> int32_t *)
(* lpNameprepCharStr : LPWSTR optional, out -> (ptr uint16_t) *)
(* cchNameprepChar : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("IdnToNameprepUnicode" idn-to-nameprep-unicode :convention :stdcall) :int32
  (dw-flags :uint32)   ; DWORD
  (lp-unicode-char-str (:string :encoding :utf-16le))   ; LPCWSTR
  (cch-unicode-char :int32)   ; INT
  (lp-nameprep-char-str :pointer)   ; LPWSTR optional, out
  (cch-nameprep-char :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $IdnToNameprepUnicode = Win32::API::More->new('KERNEL32',
    'int IdnToNameprepUnicode(DWORD dwFlags, LPCWSTR lpUnicodeCharStr, int cchUnicodeChar, LPWSTR lpNameprepCharStr, int cchNameprepChar)');
# my $ret = $IdnToNameprepUnicode->Call($dwFlags, $lpUnicodeCharStr, $cchUnicodeChar, $lpNameprepCharStr, $cchNameprepChar);
# dwFlags : DWORD -> DWORD
# lpUnicodeCharStr : LPCWSTR -> LPCWSTR
# cchUnicodeChar : INT -> int
# lpNameprepCharStr : LPWSTR optional, out -> LPWSTR
# cchNameprepChar : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目