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