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

TcQueryInterface

関数
トラフィック制御インターフェイスのパラメータを問い合わせる。
DLLTRAFFIC.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD TcQueryInterface(
    HANDLE IfcHandle,
    GUID* pGuidParam,
    BOOLEAN NotifyChange,
    DWORD* pBufferSize,
    void* Buffer
);

パラメーター

名前方向説明
IfcHandleHANDLEin問い合わせ対象のインターフェイスハンドル。
pGuidParamGUID*in取得するパラメータの種類を識別するGUIDへのポインタ。
NotifyChangeBOOLEANinTRUEで該当パラメータの変化通知を要求する。
pBufferSizeDWORD*inout入力でBufferのバイト数、出力で必要/使用バイト数を格納するポインタ。
Buffervoid*out取得したパラメータ値を格納する出力バッファへのポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD TcQueryInterface(
    HANDLE IfcHandle,
    GUID* pGuidParam,
    BOOLEAN NotifyChange,
    DWORD* pBufferSize,
    void* Buffer
);
[DllImport("TRAFFIC.dll", ExactSpelling = true)]
static extern uint TcQueryInterface(
    IntPtr IfcHandle,   // HANDLE
    ref Guid pGuidParam,   // GUID*
    [MarshalAs(UnmanagedType.U1)] bool NotifyChange,   // BOOLEAN
    ref uint pBufferSize,   // DWORD* in/out
    IntPtr Buffer   // void* out
);
<DllImport("TRAFFIC.dll", ExactSpelling:=True)>
Public Shared Function TcQueryInterface(
    IfcHandle As IntPtr,   ' HANDLE
    ByRef pGuidParam As Guid,   ' GUID*
    <MarshalAs(UnmanagedType.U1)> NotifyChange As Boolean,   ' BOOLEAN
    ByRef pBufferSize As UInteger,   ' DWORD* in/out
    Buffer As IntPtr   ' void* out
) As UInteger
End Function
' IfcHandle : HANDLE
' pGuidParam : GUID*
' NotifyChange : BOOLEAN
' pBufferSize : DWORD* in/out
' Buffer : void* out
Declare PtrSafe Function TcQueryInterface Lib "traffic" ( _
    ByVal IfcHandle As LongPtr, _
    ByVal pGuidParam As LongPtr, _
    ByVal NotifyChange As Byte, _
    ByRef pBufferSize As Long, _
    ByVal Buffer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

TcQueryInterface = ctypes.windll.traffic.TcQueryInterface
TcQueryInterface.restype = wintypes.DWORD
TcQueryInterface.argtypes = [
    wintypes.HANDLE,  # IfcHandle : HANDLE
    ctypes.c_void_p,  # pGuidParam : GUID*
    wintypes.BOOLEAN,  # NotifyChange : BOOLEAN
    ctypes.POINTER(wintypes.DWORD),  # pBufferSize : DWORD* in/out
    ctypes.POINTER(None),  # Buffer : void* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('TRAFFIC.dll')
TcQueryInterface = Fiddle::Function.new(
  lib['TcQueryInterface'],
  [
    Fiddle::TYPE_VOIDP,  # IfcHandle : HANDLE
    Fiddle::TYPE_VOIDP,  # pGuidParam : GUID*
    Fiddle::TYPE_CHAR,  # NotifyChange : BOOLEAN
    Fiddle::TYPE_VOIDP,  # pBufferSize : DWORD* in/out
    Fiddle::TYPE_VOIDP,  # Buffer : void* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "traffic")]
extern "system" {
    fn TcQueryInterface(
        IfcHandle: *mut core::ffi::c_void,  // HANDLE
        pGuidParam: *mut GUID,  // GUID*
        NotifyChange: u8,  // BOOLEAN
        pBufferSize: *mut u32,  // DWORD* in/out
        Buffer: *mut ()  // void* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("TRAFFIC.dll")]
public static extern uint TcQueryInterface(IntPtr IfcHandle, ref Guid pGuidParam, [MarshalAs(UnmanagedType.U1)] bool NotifyChange, ref uint pBufferSize, IntPtr Buffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'TRAFFIC_TcQueryInterface' -Namespace Win32 -PassThru
# $api::TcQueryInterface(IfcHandle, pGuidParam, NotifyChange, pBufferSize, Buffer)
#uselib "TRAFFIC.dll"
#func global TcQueryInterface "TcQueryInterface" sptr, sptr, sptr, sptr, sptr
; TcQueryInterface IfcHandle, varptr(pGuidParam), NotifyChange, varptr(pBufferSize), Buffer   ; 戻り値は stat
; IfcHandle : HANDLE -> "sptr"
; pGuidParam : GUID* -> "sptr"
; NotifyChange : BOOLEAN -> "sptr"
; pBufferSize : DWORD* in/out -> "sptr"
; Buffer : void* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "TRAFFIC.dll"
#cfunc global TcQueryInterface "TcQueryInterface" sptr, var, int, var, sptr
; res = TcQueryInterface(IfcHandle, pGuidParam, NotifyChange, pBufferSize, Buffer)
; IfcHandle : HANDLE -> "sptr"
; pGuidParam : GUID* -> "var"
; NotifyChange : BOOLEAN -> "int"
; pBufferSize : DWORD* in/out -> "var"
; Buffer : void* out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD TcQueryInterface(HANDLE IfcHandle, GUID* pGuidParam, BOOLEAN NotifyChange, DWORD* pBufferSize, void* Buffer)
#uselib "TRAFFIC.dll"
#cfunc global TcQueryInterface "TcQueryInterface" intptr, var, int, var, intptr
; res = TcQueryInterface(IfcHandle, pGuidParam, NotifyChange, pBufferSize, Buffer)
; IfcHandle : HANDLE -> "intptr"
; pGuidParam : GUID* -> "var"
; NotifyChange : BOOLEAN -> "int"
; pBufferSize : DWORD* in/out -> "var"
; Buffer : void* out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	traffic = windows.NewLazySystemDLL("TRAFFIC.dll")
	procTcQueryInterface = traffic.NewProc("TcQueryInterface")
)

// IfcHandle (HANDLE), pGuidParam (GUID*), NotifyChange (BOOLEAN), pBufferSize (DWORD* in/out), Buffer (void* out)
r1, _, err := procTcQueryInterface.Call(
	uintptr(IfcHandle),
	uintptr(pGuidParam),
	uintptr(NotifyChange),
	uintptr(pBufferSize),
	uintptr(Buffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function TcQueryInterface(
  IfcHandle: THandle;   // HANDLE
  pGuidParam: PGUID;   // GUID*
  NotifyChange: ByteBool;   // BOOLEAN
  pBufferSize: Pointer;   // DWORD* in/out
  Buffer: Pointer   // void* out
): DWORD; stdcall;
  external 'TRAFFIC.dll' name 'TcQueryInterface';
result := DllCall("TRAFFIC\TcQueryInterface"
    , "Ptr", IfcHandle   ; HANDLE
    , "Ptr", pGuidParam   ; GUID*
    , "Char", NotifyChange   ; BOOLEAN
    , "Ptr", pBufferSize   ; DWORD* in/out
    , "Ptr", Buffer   ; void* out
    , "UInt")   ; return: DWORD
●TcQueryInterface(IfcHandle, pGuidParam, NotifyChange, pBufferSize, Buffer) = DLL("TRAFFIC.dll", "dword TcQueryInterface(void*, void*, byte, void*, void*)")
# 呼び出し: TcQueryInterface(IfcHandle, pGuidParam, NotifyChange, pBufferSize, Buffer)
# IfcHandle : HANDLE -> "void*"
# pGuidParam : GUID* -> "void*"
# NotifyChange : BOOLEAN -> "byte"
# pBufferSize : DWORD* in/out -> "void*"
# Buffer : void* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef TcQueryInterfaceNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Uint8, Pointer<Uint32>, Pointer<Void>);
typedef TcQueryInterfaceDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Uint32>, Pointer<Void>);
final TcQueryInterface = DynamicLibrary.open('TRAFFIC.dll')
    .lookupFunction<TcQueryInterfaceNative, TcQueryInterfaceDart>('TcQueryInterface');
// IfcHandle : HANDLE -> Pointer<Void>
// pGuidParam : GUID* -> Pointer<Void>
// NotifyChange : BOOLEAN -> Uint8
// pBufferSize : DWORD* in/out -> Pointer<Uint32>
// Buffer : void* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function TcQueryInterface(
  IfcHandle: THandle;   // HANDLE
  pGuidParam: PGUID;   // GUID*
  NotifyChange: ByteBool;   // BOOLEAN
  pBufferSize: Pointer;   // DWORD* in/out
  Buffer: Pointer   // void* out
): DWORD; stdcall;
  external 'TRAFFIC.dll' name 'TcQueryInterface';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "TcQueryInterface"
  c_TcQueryInterface :: Ptr () -> Ptr () -> Word8 -> Ptr Word32 -> Ptr () -> IO Word32
-- IfcHandle : HANDLE -> Ptr ()
-- pGuidParam : GUID* -> Ptr ()
-- NotifyChange : BOOLEAN -> Word8
-- pBufferSize : DWORD* in/out -> Ptr Word32
-- Buffer : void* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let tcqueryinterface =
  foreign "TcQueryInterface"
    ((ptr void) @-> (ptr void) @-> uint8_t @-> (ptr uint32_t) @-> (ptr void) @-> returning uint32_t)
(* IfcHandle : HANDLE -> (ptr void) *)
(* pGuidParam : GUID* -> (ptr void) *)
(* NotifyChange : BOOLEAN -> uint8_t *)
(* pBufferSize : DWORD* in/out -> (ptr uint32_t) *)
(* Buffer : void* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library traffic (t "TRAFFIC.dll"))
(cffi:use-foreign-library traffic)

(cffi:defcfun ("TcQueryInterface" tc-query-interface :convention :stdcall) :uint32
  (ifc-handle :pointer)   ; HANDLE
  (p-guid-param :pointer)   ; GUID*
  (notify-change :uint8)   ; BOOLEAN
  (p-buffer-size :pointer)   ; DWORD* in/out
  (buffer :pointer))   ; void* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $TcQueryInterface = Win32::API::More->new('TRAFFIC',
    'DWORD TcQueryInterface(HANDLE IfcHandle, LPVOID pGuidParam, BYTE NotifyChange, LPVOID pBufferSize, LPVOID Buffer)');
# my $ret = $TcQueryInterface->Call($IfcHandle, $pGuidParam, $NotifyChange, $pBufferSize, $Buffer);
# IfcHandle : HANDLE -> HANDLE
# pGuidParam : GUID* -> LPVOID
# NotifyChange : BOOLEAN -> BYTE
# pBufferSize : DWORD* in/out -> LPVOID
# Buffer : void* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。