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

PfCreateInterface

関数
パケットフィルタリング用のインターフェイスを作成する。
DLLIPHLPAPI.dll呼出規約winapi

シグネチャ

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

DWORD PfCreateInterface(
    DWORD dwName,
    PFFORWARD_ACTION inAction,
    PFFORWARD_ACTION outAction,
    BOOL bUseLog,
    BOOL bMustBeUnique,
    void** ppInterface
);

パラメーター

名前方向説明
dwNameDWORDinインターフェースを識別するための名前(数値ID)。
inActionPFFORWARD_ACTIONin受信パケットに対する既定の転送アクション(PF_ACTION_FORWARD/PF_ACTION_DROP)。
outActionPFFORWARD_ACTIONin送信パケットに対する既定の転送アクション(PF_ACTION_FORWARD/PF_ACTION_DROP)。
bUseLogBOOLinTRUEでパケットフィルタリングのログ記録を有効にする。
bMustBeUniqueBOOLinTRUEの場合、同名インターフェースが既存ならエラーとする。
ppInterfacevoid**inout作成されたフィルタインターフェースのハンドルを受け取る出力ポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

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

PfCreateInterface = ctypes.windll.iphlpapi.PfCreateInterface
PfCreateInterface.restype = wintypes.DWORD
PfCreateInterface.argtypes = [
    wintypes.DWORD,  # dwName : DWORD
    ctypes.c_int,  # inAction : PFFORWARD_ACTION
    ctypes.c_int,  # outAction : PFFORWARD_ACTION
    wintypes.BOOL,  # bUseLog : BOOL
    wintypes.BOOL,  # bMustBeUnique : BOOL
    ctypes.c_void_p,  # ppInterface : void** in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procPfCreateInterface = iphlpapi.NewProc("PfCreateInterface")
)

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

extern "iphlpapi" fn PfCreateInterface(
    dwName: u32, // DWORD
    inAction: i32, // PFFORWARD_ACTION
    outAction: i32, // PFFORWARD_ACTION
    bUseLog: i32, // BOOL
    bMustBeUnique: i32, // BOOL
    ppInterface: ?*anyopaque // void** in/out
) callconv(std.os.windows.WINAPI) u32;
proc PfCreateInterface(
    dwName: uint32,  # DWORD
    inAction: int32,  # PFFORWARD_ACTION
    outAction: int32,  # PFFORWARD_ACTION
    bUseLog: int32,  # BOOL
    bMustBeUnique: int32,  # BOOL
    ppInterface: pointer  # void** in/out
): uint32 {.importc: "PfCreateInterface", stdcall, dynlib: "IPHLPAPI.dll".}
pragma(lib, "iphlpapi");
extern(Windows)
uint PfCreateInterface(
    uint dwName,   // DWORD
    int inAction,   // PFFORWARD_ACTION
    int outAction,   // PFFORWARD_ACTION
    int bUseLog,   // BOOL
    int bMustBeUnique,   // BOOL
    void** ppInterface   // void** in/out
);
ccall((:PfCreateInterface, "IPHLPAPI.dll"), stdcall, UInt32,
      (UInt32, Int32, Int32, Int32, Int32, Ptr{Cvoid}),
      dwName, inAction, outAction, bUseLog, bMustBeUnique, ppInterface)
# dwName : DWORD -> UInt32
# inAction : PFFORWARD_ACTION -> Int32
# outAction : PFFORWARD_ACTION -> Int32
# bUseLog : BOOL -> Int32
# bMustBeUnique : BOOL -> Int32
# ppInterface : void** in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t PfCreateInterface(
    uint32_t dwName,
    int32_t inAction,
    int32_t outAction,
    int32_t bUseLog,
    int32_t bMustBeUnique,
    void** ppInterface);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.PfCreateInterface(dwName, inAction, outAction, bUseLog, bMustBeUnique, ppInterface)
-- dwName : DWORD
-- inAction : PFFORWARD_ACTION
-- outAction : PFFORWARD_ACTION
-- bUseLog : BOOL
-- bMustBeUnique : BOOL
-- ppInterface : void** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const PfCreateInterface = lib.func('__stdcall', 'PfCreateInterface', 'uint32_t', ['uint32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'void *']);
// PfCreateInterface(dwName, inAction, outAction, bUseLog, bMustBeUnique, ppInterface)
// dwName : DWORD -> 'uint32_t'
// inAction : PFFORWARD_ACTION -> 'int32_t'
// outAction : PFFORWARD_ACTION -> 'int32_t'
// bUseLog : BOOL -> 'int32_t'
// bMustBeUnique : BOOL -> 'int32_t'
// ppInterface : void** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("IPHLPAPI.dll", {
  PfCreateInterface: { parameters: ["u32", "i32", "i32", "i32", "i32", "pointer"], result: "u32" },
});
// lib.symbols.PfCreateInterface(dwName, inAction, outAction, bUseLog, bMustBeUnique, ppInterface)
// dwName : DWORD -> "u32"
// inAction : PFFORWARD_ACTION -> "i32"
// outAction : PFFORWARD_ACTION -> "i32"
// bUseLog : BOOL -> "i32"
// bMustBeUnique : BOOL -> "i32"
// ppInterface : void** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t PfCreateInterface(
    uint32_t dwName,
    int32_t inAction,
    int32_t outAction,
    int32_t bUseLog,
    int32_t bMustBeUnique,
    void** ppInterface);
C, "IPHLPAPI.dll");
// $ffi->PfCreateInterface(dwName, inAction, outAction, bUseLog, bMustBeUnique, ppInterface);
// dwName : DWORD
// inAction : PFFORWARD_ACTION
// outAction : PFFORWARD_ACTION
// bUseLog : BOOL
// bMustBeUnique : BOOL
// ppInterface : void** 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 PfCreateInterface(
        int dwName,   // DWORD
        int inAction,   // PFFORWARD_ACTION
        int outAction,   // PFFORWARD_ACTION
        boolean bUseLog,   // BOOL
        boolean bMustBeUnique,   // BOOL
        Pointer ppInterface   // void** in/out
    );
}
@[Link("iphlpapi")]
lib LibIPHLPAPI
  fun PfCreateInterface = PfCreateInterface(
    dwName : UInt32,   # DWORD
    inAction : Int32,   # PFFORWARD_ACTION
    outAction : Int32,   # PFFORWARD_ACTION
    bUseLog : Int32,   # BOOL
    bMustBeUnique : Int32,   # BOOL
    ppInterface : Void**   # void** 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 PfCreateInterfaceNative = Uint32 Function(Uint32, Int32, Int32, Int32, Int32, Pointer<Void>);
typedef PfCreateInterfaceDart = int Function(int, int, int, int, int, Pointer<Void>);
final PfCreateInterface = DynamicLibrary.open('IPHLPAPI.dll')
    .lookupFunction<PfCreateInterfaceNative, PfCreateInterfaceDart>('PfCreateInterface');
// dwName : DWORD -> Uint32
// inAction : PFFORWARD_ACTION -> Int32
// outAction : PFFORWARD_ACTION -> Int32
// bUseLog : BOOL -> Int32
// bMustBeUnique : BOOL -> Int32
// ppInterface : void** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PfCreateInterface(
  dwName: DWORD;   // DWORD
  inAction: Integer;   // PFFORWARD_ACTION
  outAction: Integer;   // PFFORWARD_ACTION
  bUseLog: BOOL;   // BOOL
  bMustBeUnique: BOOL;   // BOOL
  ppInterface: Pointer   // void** in/out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'PfCreateInterface';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PfCreateInterface"
  c_PfCreateInterface :: Word32 -> Int32 -> Int32 -> CInt -> CInt -> Ptr () -> IO Word32
-- dwName : DWORD -> Word32
-- inAction : PFFORWARD_ACTION -> Int32
-- outAction : PFFORWARD_ACTION -> Int32
-- bUseLog : BOOL -> CInt
-- bMustBeUnique : BOOL -> CInt
-- ppInterface : void** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pfcreateinterface =
  foreign "PfCreateInterface"
    (uint32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> (ptr void) @-> returning uint32_t)
(* dwName : DWORD -> uint32_t *)
(* inAction : PFFORWARD_ACTION -> int32_t *)
(* outAction : PFFORWARD_ACTION -> int32_t *)
(* bUseLog : BOOL -> int32_t *)
(* bMustBeUnique : BOOL -> int32_t *)
(* ppInterface : void** in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)

(cffi:defcfun ("PfCreateInterface" pf-create-interface :convention :stdcall) :uint32
  (dw-name :uint32)   ; DWORD
  (in-action :int32)   ; PFFORWARD_ACTION
  (out-action :int32)   ; PFFORWARD_ACTION
  (b-use-log :int32)   ; BOOL
  (b-must-be-unique :int32)   ; BOOL
  (pp-interface :pointer))   ; void** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PfCreateInterface = Win32::API::More->new('IPHLPAPI',
    'DWORD PfCreateInterface(DWORD dwName, int inAction, int outAction, BOOL bUseLog, BOOL bMustBeUnique, LPVOID ppInterface)');
# my $ret = $PfCreateInterface->Call($dwName, $inAction, $outAction, $bUseLog, $bMustBeUnique, $ppInterface);
# dwName : DWORD -> DWORD
# inAction : PFFORWARD_ACTION -> int
# outAction : PFFORWARD_ACTION -> int
# bUseLog : BOOL -> BOOL
# bMustBeUnique : BOOL -> BOOL
# ppInterface : void** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型