ホーム › NetworkManagement.IpHelper › Icmp6CreateFile
Icmp6CreateFile
関数ICMPv6エコー要求送信用のハンドルを作成する。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
HANDLE Icmp6CreateFile(void);パラメーターなし。戻り値: HANDLE
公式ドキュメント
Icmp6CreateFile 関数は、IPv6 ICMP エコー要求を発行できるハンドルを開きます。
戻り値
Icmp6CreateFile 関数は、成功すると開いたハンドルを返します。失敗した場合、この関数は INVALID_HANDLE_VALUE を返します。拡張エラー情報を取得するには、 GetLastError 関数を呼び出します。
解説(Remarks)
Icmp6CreateFile 関数は、IPv6 ICMP エコー要求を発行できるハンドルを開きます。IPv6 ICMP エコー要求の送信には Icmp6SendEcho2 関数を使用します。IPv6 ICMP 応答の解析には Icmp6ParseReplies 関数を使用します。Icmp6CreateFile 関数で開いた ICMP ハンドルを閉じるには IcmpCloseHandle 関数を使用します。
IPv4 の場合は、IcmpCreateFile 関数を使用します。
IPv4 の場合は、IcmpCreateFile、IcmpSendEcho、IcmpSendEcho2、IcmpSendEcho2Ex、および IcmpParseReplies の各関数を使用します。
Iphlpapi.h ヘッダーファイルの include ディレクティブは、Icmpapi.h ヘッダーファイルよりも前に配置する必要があることに注意してください。
例
次の例では、IPv6 ICMP エコー要求を発行できるハンドルを開きます。
#include <windows.h>
#include <stdio.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#pragma comment(lib, "IPHLPAPI.lib")
void main()
{
HANDLE hIcmpFile;
hIcmpFile = Icmp6CreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE) {
printf("\tUnable to open handle.\n");
printf("Icmp6Createfile returned error: %ld\n", GetLastError() );
}
else
printf("\tHandle created.\n");
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
HANDLE Icmp6CreateFile(void);[DllImport("IPHLPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr Icmp6CreateFile();<DllImport("IPHLPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function Icmp6CreateFile() As IntPtr
End FunctionDeclare PtrSafe Function Icmp6CreateFile Lib "iphlpapi" () As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
Icmp6CreateFile = ctypes.windll.iphlpapi.Icmp6CreateFile
Icmp6CreateFile.restype = ctypes.c_void_p
Icmp6CreateFile.argtypes = []
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
Icmp6CreateFile = Fiddle::Function.new(
lib['Icmp6CreateFile'],
[],
Fiddle::TYPE_VOIDP)#[link(name = "iphlpapi")]
extern "system" {
fn Icmp6CreateFile() -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll", SetLastError = true)]
public static extern IntPtr Icmp6CreateFile();
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_Icmp6CreateFile' -Namespace Win32 -PassThru
# $api::Icmp6CreateFile()#uselib "IPHLPAPI.dll"
#func global Icmp6CreateFile "Icmp6CreateFile"
; Icmp6CreateFile ; 戻り値は stat
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "IPHLPAPI.dll"
#cfunc global Icmp6CreateFile "Icmp6CreateFile"
; res = Icmp6CreateFile(); HANDLE Icmp6CreateFile()
#uselib "IPHLPAPI.dll"
#cfunc global Icmp6CreateFile "Icmp6CreateFile"
; res = Icmp6CreateFile()import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procIcmp6CreateFile = iphlpapi.NewProc("Icmp6CreateFile")
)
r1, _, err := procIcmp6CreateFile.Call()
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction Icmp6CreateFile: THandle; stdcall;
external 'IPHLPAPI.dll' name 'Icmp6CreateFile';result := DllCall("IPHLPAPI\Icmp6CreateFile", "Ptr")●Icmp6CreateFile() = DLL("IPHLPAPI.dll", "void* Icmp6CreateFile()")
# 呼び出し: Icmp6CreateFile()
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iphlpapi" fn Icmp6CreateFile() callconv(std.os.windows.WINAPI) ?*anyopaque;proc Icmp6CreateFile(): pointer {.importc: "Icmp6CreateFile", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
void* Icmp6CreateFile();ccall((:Icmp6CreateFile, "IPHLPAPI.dll"), stdcall, Ptr{Cvoid},
(),
)
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* Icmp6CreateFile(void);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.Icmp6CreateFile()
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const Icmp6CreateFile = lib.func('__stdcall', 'Icmp6CreateFile', 'void *', []);
// Icmp6CreateFile()
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
Icmp6CreateFile: { parameters: [], result: "pointer" },
});
// lib.symbols.Icmp6CreateFile()
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* Icmp6CreateFile(void);
C, "IPHLPAPI.dll");
// $ffi->Icmp6CreateFile();
// 構造体/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);
Pointer Icmp6CreateFile();
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun Icmp6CreateFile = Icmp6CreateFile() : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef Icmp6CreateFileNative = Pointer<Void> Function();
typedef Icmp6CreateFileDart = Pointer<Void> Function();
final Icmp6CreateFile = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<Icmp6CreateFileNative, Icmp6CreateFileDart>('Icmp6CreateFile');
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function Icmp6CreateFile: THandle; stdcall;
external 'IPHLPAPI.dll' name 'Icmp6CreateFile';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "Icmp6CreateFile"
c_Icmp6CreateFile :: IO (Ptr ())
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let icmp6createfile =
foreign "Icmp6CreateFile"
(void @-> returning (ptr void))
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)
(cffi:defcfun ("Icmp6CreateFile" icmp6-create-file :convention :stdcall) :pointer)
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $Icmp6CreateFile = Win32::API::More->new('IPHLPAPI',
'HANDLE Icmp6CreateFile()');
# my $ret = $Icmp6CreateFile->Call();
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetLastError — 呼び出しスレッドの最終エラーコードを取得する。
- f Icmp6ParseReplies — ICMPv6エコー応答バッファを解析し応答数を返す。
- f Icmp6SendEcho2 — IPv6でICMPv6エコー要求を送信し応答を受信する。
- f IcmpCloseHandle — ICMPエコー要求用に開いたハンドルを閉じる。
- f IcmpCreateFile — ICMPエコー要求送信用のハンドルを作成する。
- f IcmpParseReplies — ICMPエコー応答バッファを解析し応答数を返す。
- f IcmpSendEcho2 — ICMPエコー要求を同期または非同期で送信する。
- f IcmpSendEcho2Ex — 送信元アドレスを指定してICMPエコー要求を送信する。