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