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