ホーム › Networking.WinSock › ntohl
ntohl
関数32ビット値をネットワーク順からホストバイト順へ変換する。
シグネチャ
// WS2_32.dll
#include <windows.h>
DWORD ntohl(
DWORD netlong
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| netlong | DWORD | in |
戻り値の型: DWORD
各言語での呼び出し定義
// WS2_32.dll
#include <windows.h>
DWORD ntohl(
DWORD netlong
);[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern uint ntohl(
uint netlong // DWORD
);<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ntohl(
netlong As UInteger ' DWORD
) As UInteger
End Function' netlong : DWORD
Declare PtrSafe Function ntohl Lib "ws2_32" ( _
ByVal netlong As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ntohl = ctypes.windll.ws2_32.ntohl
ntohl.restype = wintypes.DWORD
ntohl.argtypes = [
wintypes.DWORD, # netlong : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
ntohl = Fiddle::Function.new(
lib['ntohl'],
[
-Fiddle::TYPE_INT, # netlong : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "ws2_32")]
extern "system" {
fn ntohl(
netlong: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern uint ntohl(uint netlong);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_ntohl' -Namespace Win32 -PassThru
# $api::ntohl(netlong)#uselib "WS2_32.dll"
#func global ntohl "ntohl" sptr
; ntohl netlong ; 戻り値は stat
; netlong : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WS2_32.dll"
#cfunc global ntohl "ntohl" int
; res = ntohl(netlong)
; netlong : DWORD -> "int"; DWORD ntohl(DWORD netlong)
#uselib "WS2_32.dll"
#cfunc global ntohl "ntohl" int
; res = ntohl(netlong)
; netlong : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procntohl = ws2_32.NewProc("ntohl")
)
// netlong (DWORD)
r1, _, err := procntohl.Call(
uintptr(netlong),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction ntohl(
netlong: DWORD // DWORD
): DWORD; stdcall;
external 'WS2_32.dll' name 'ntohl';result := DllCall("WS2_32\ntohl"
, "UInt", netlong ; DWORD
, "UInt") ; return: DWORD●ntohl(netlong) = DLL("WS2_32.dll", "dword ntohl(dword)")
# 呼び出し: ntohl(netlong)
# netlong : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。