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

PfAddGlobalFilterToInterface

関数
インターフェイスにグローバルパケットフィルタを追加する。
DLLIPHLPAPI.dll呼出規約winapi

シグネチャ

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

DWORD PfAddGlobalFilterToInterface(
    void* pInterface,
    GLOBAL_FILTER gfFilter
);

パラメーター

名前方向説明
pInterfacevoid*inoutグローバルフィルタを追加する対象インターフェースのハンドル。
gfFilterGLOBAL_FILTERin追加するグローバルフィルタ種別(GLOBAL_FILTER列挙値)。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD PfAddGlobalFilterToInterface(
    void* pInterface,
    GLOBAL_FILTER gfFilter
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint PfAddGlobalFilterToInterface(
    IntPtr pInterface,   // void* in/out
    int gfFilter   // GLOBAL_FILTER
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function PfAddGlobalFilterToInterface(
    pInterface As IntPtr,   ' void* in/out
    gfFilter As Integer   ' GLOBAL_FILTER
) As UInteger
End Function
' pInterface : void* in/out
' gfFilter : GLOBAL_FILTER
Declare PtrSafe Function PfAddGlobalFilterToInterface Lib "iphlpapi" ( _
    ByVal pInterface As LongPtr, _
    ByVal gfFilter As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PfAddGlobalFilterToInterface = ctypes.windll.iphlpapi.PfAddGlobalFilterToInterface
PfAddGlobalFilterToInterface.restype = wintypes.DWORD
PfAddGlobalFilterToInterface.argtypes = [
    ctypes.POINTER(None),  # pInterface : void* in/out
    ctypes.c_int,  # gfFilter : GLOBAL_FILTER
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
PfAddGlobalFilterToInterface = Fiddle::Function.new(
  lib['PfAddGlobalFilterToInterface'],
  [
    Fiddle::TYPE_VOIDP,  # pInterface : void* in/out
    Fiddle::TYPE_INT,  # gfFilter : GLOBAL_FILTER
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn PfAddGlobalFilterToInterface(
        pInterface: *mut (),  // void* in/out
        gfFilter: i32  // GLOBAL_FILTER
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint PfAddGlobalFilterToInterface(IntPtr pInterface, int gfFilter);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_PfAddGlobalFilterToInterface' -Namespace Win32 -PassThru
# $api::PfAddGlobalFilterToInterface(pInterface, gfFilter)
#uselib "IPHLPAPI.dll"
#func global PfAddGlobalFilterToInterface "PfAddGlobalFilterToInterface" sptr, sptr
; PfAddGlobalFilterToInterface pInterface, gfFilter   ; 戻り値は stat
; pInterface : void* in/out -> "sptr"
; gfFilter : GLOBAL_FILTER -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "IPHLPAPI.dll"
#cfunc global PfAddGlobalFilterToInterface "PfAddGlobalFilterToInterface" sptr, int
; res = PfAddGlobalFilterToInterface(pInterface, gfFilter)
; pInterface : void* in/out -> "sptr"
; gfFilter : GLOBAL_FILTER -> "int"
; DWORD PfAddGlobalFilterToInterface(void* pInterface, GLOBAL_FILTER gfFilter)
#uselib "IPHLPAPI.dll"
#cfunc global PfAddGlobalFilterToInterface "PfAddGlobalFilterToInterface" intptr, int
; res = PfAddGlobalFilterToInterface(pInterface, gfFilter)
; pInterface : void* in/out -> "intptr"
; gfFilter : GLOBAL_FILTER -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procPfAddGlobalFilterToInterface = iphlpapi.NewProc("PfAddGlobalFilterToInterface")
)

// pInterface (void* in/out), gfFilter (GLOBAL_FILTER)
r1, _, err := procPfAddGlobalFilterToInterface.Call(
	uintptr(pInterface),
	uintptr(gfFilter),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function PfAddGlobalFilterToInterface(
  pInterface: Pointer;   // void* in/out
  gfFilter: Integer   // GLOBAL_FILTER
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'PfAddGlobalFilterToInterface';
result := DllCall("IPHLPAPI\PfAddGlobalFilterToInterface"
    , "Ptr", pInterface   ; void* in/out
    , "Int", gfFilter   ; GLOBAL_FILTER
    , "UInt")   ; return: DWORD
●PfAddGlobalFilterToInterface(pInterface, gfFilter) = DLL("IPHLPAPI.dll", "dword PfAddGlobalFilterToInterface(void*, int)")
# 呼び出し: PfAddGlobalFilterToInterface(pInterface, gfFilter)
# pInterface : void* in/out -> "void*"
# gfFilter : GLOBAL_FILTER -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef PfAddGlobalFilterToInterfaceNative = Uint32 Function(Pointer<Void>, Int32);
typedef PfAddGlobalFilterToInterfaceDart = int Function(Pointer<Void>, int);
final PfAddGlobalFilterToInterface = DynamicLibrary.open('IPHLPAPI.dll')
    .lookupFunction<PfAddGlobalFilterToInterfaceNative, PfAddGlobalFilterToInterfaceDart>('PfAddGlobalFilterToInterface');
// pInterface : void* in/out -> Pointer<Void>
// gfFilter : GLOBAL_FILTER -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PfAddGlobalFilterToInterface(
  pInterface: Pointer;   // void* in/out
  gfFilter: Integer   // GLOBAL_FILTER
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'PfAddGlobalFilterToInterface';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PfAddGlobalFilterToInterface"
  c_PfAddGlobalFilterToInterface :: Ptr () -> Int32 -> IO Word32
-- pInterface : void* in/out -> Ptr ()
-- gfFilter : GLOBAL_FILTER -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pfaddglobalfiltertointerface =
  foreign "PfAddGlobalFilterToInterface"
    ((ptr void) @-> int32_t @-> returning uint32_t)
(* pInterface : void* in/out -> (ptr void) *)
(* gfFilter : GLOBAL_FILTER -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)

(cffi:defcfun ("PfAddGlobalFilterToInterface" pf-add-global-filter-to-interface :convention :stdcall) :uint32
  (p-interface :pointer)   ; void* in/out
  (gf-filter :int32))   ; GLOBAL_FILTER
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PfAddGlobalFilterToInterface = Win32::API::More->new('IPHLPAPI',
    'DWORD PfAddGlobalFilterToInterface(LPVOID pInterface, int gfFilter)');
# my $ret = $PfAddGlobalFilterToInterface->Call($pInterface, $gfFilter);
# pInterface : void* in/out -> LPVOID
# gfFilter : GLOBAL_FILTER -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型