Win32 API 日本語リファレンス
ホームNetworkManagement.IpHelper › GetIpErrorString

GetIpErrorString

関数
IP Helper APIのエラーコードを説明文字列に変換する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// IPHLPAPI.dll
#include <windows.h>

DWORD GetIpErrorString(
    DWORD ErrorCode,
    LPWSTR Buffer,   // optional
    DWORD* Size
);

パラメーター

名前方向説明
ErrorCodeDWORDin取得対象のエラーコード。このパラメーターに指定できる値は、Ipexport.h ヘッダーファイルで定義されています。
BufferLPWSTRoutoptional関数が NO_ERROR を返した場合に、エラーコード文字列が格納されるバッファーへのポインター。
SizeDWORD*inoutBuffer パラメーターが指すバッファーの長さを文字数で指定する DWORD へのポインター。終端の null は含みません(すなわち、Buffer のサイズを文字数で表した値から 1 を引いた値)。

戻り値の型: DWORD

公式ドキュメント

GetIpErrorString 関数は、IP Helper のエラー文字列を取得します。

戻り値

成功した場合は NO_ERROR を返します。

関数が失敗した場合は、FormatMessage を使用して、返されたエラーに対応するメッセージ文字列を取得してください。

解説(Remarks)

GetIpErrorString 関数は、IP エラーコードに対応する IP Helper のエラー文字列を取得するために使用できます。ErrorCode パラメーターに渡す IP_STATUS エラーコードは、ICMP および ICMPv6 関数で使用される ICMP_ECHO_REPLYICMP_ECHO_REPLY32、および ICMPV6_ECHO_REPLY 構造体の Status メンバーで返されます。これらの構造体を使用する関数には、Icmp6ParseRepliesIcmp6SendEcho2IcmpParseRepliesIcmpSendEchoIcmpSendEcho2、および IcmpSendEcho2Ex があります。

GetIpErrorString 関数の構文は、Windows Vista 以降向けにリリースされた Microsoft Windows Software Development Kit (SDK) で若干変更されました。Buffer パラメーターのデータ型が PWCHAR から PWSTR に変更されています。

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

各言語での呼び出し定義

// 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // DWORD
function 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)。
const std = @import("std");

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

typedef GetIpErrorStringNative = Uint32 Function(Uint32, Pointer<Utf16>, Pointer<Uint32>);
typedef GetIpErrorStringDart = int Function(int, Pointer<Utf16>, Pointer<Uint32>);
final GetIpErrorString = DynamicLibrary.open('IPHLPAPI.dll')
    .lookupFunction<GetIpErrorStringNative, GetIpErrorStringDart>('GetIpErrorString');
// ErrorCode : DWORD -> Uint32
// Buffer : LPWSTR optional, out -> Pointer<Utf16>
// Size : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetIpErrorString(
  ErrorCode: DWORD;   // DWORD
  Buffer: PWideChar;   // LPWSTR optional, out
  Size: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'GetIpErrorString';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetIpErrorString"
  c_GetIpErrorString :: Word32 -> CWString -> Ptr Word32 -> IO Word32
-- ErrorCode : DWORD -> Word32
-- Buffer : LPWSTR optional, out -> CWString
-- Size : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getiperrorstring =
  foreign "GetIpErrorString"
    (uint32_t @-> (ptr uint16_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* ErrorCode : DWORD -> uint32_t *)
(* Buffer : LPWSTR optional, out -> (ptr uint16_t) *)
(* Size : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)

(cffi:defcfun ("GetIpErrorString" get-ip-error-string :convention :stdcall) :uint32
  (error-code :uint32)   ; DWORD
  (buffer :pointer)   ; LPWSTR optional, out
  (size :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetIpErrorString = Win32::API::More->new('IPHLPAPI',
    'DWORD GetIpErrorString(DWORD ErrorCode, LPWSTR Buffer, LPVOID Size)');
# my $ret = $GetIpErrorString->Call($ErrorCode, $Buffer, $Size);
# ErrorCode : DWORD -> DWORD
# Buffer : LPWSTR optional, out -> LPWSTR
# Size : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目