Win32 API 日本語リファレンス
ホームSystem.HostComputeNetwork › HcnQueryEndpointStats

HcnQueryEndpointStats

関数
エンドポイントの統計情報を照会して取得する。
DLLcomputenetwork.dll呼出規約winapi

シグネチャ

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

HRESULT HcnQueryEndpointStats(
    void* Endpoint,
    LPCWSTR Query,
    LPWSTR* Stats,
    LPWSTR* ErrorRecord   // optional
);

パラメーター

名前方向説明
Endpointvoid*in統計を照会する対象のエンドポイントハンドル。
QueryLPCWSTRin取得する統計項目を指定するJSON形式のクエリ文字列。
StatsLPWSTR*out統計結果をJSON文字列で受け取るポインタ。要解放。
ErrorRecordLPWSTR*outoptional失敗時にエラー詳細のJSON文字列を受け取るポインタ。不要ならNULL可、要解放。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT HcnQueryEndpointStats(
    void* Endpoint,
    LPCWSTR Query,
    LPWSTR* Stats,
    LPWSTR* ErrorRecord   // optional
);
[DllImport("computenetwork.dll", ExactSpelling = true)]
static extern int HcnQueryEndpointStats(
    IntPtr Endpoint,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string Query,   // LPCWSTR
    IntPtr Stats,   // LPWSTR* out
    IntPtr ErrorRecord   // LPWSTR* optional, out
);
<DllImport("computenetwork.dll", ExactSpelling:=True)>
Public Shared Function HcnQueryEndpointStats(
    Endpoint As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> Query As String,   ' LPCWSTR
    Stats As IntPtr,   ' LPWSTR* out
    ErrorRecord As IntPtr   ' LPWSTR* optional, out
) As Integer
End Function
' Endpoint : void*
' Query : LPCWSTR
' Stats : LPWSTR* out
' ErrorRecord : LPWSTR* optional, out
Declare PtrSafe Function HcnQueryEndpointStats Lib "computenetwork" ( _
    ByVal Endpoint As LongPtr, _
    ByVal Query As LongPtr, _
    ByVal Stats As LongPtr, _
    ByVal ErrorRecord As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HcnQueryEndpointStats = ctypes.windll.computenetwork.HcnQueryEndpointStats
HcnQueryEndpointStats.restype = ctypes.c_int
HcnQueryEndpointStats.argtypes = [
    ctypes.POINTER(None),  # Endpoint : void*
    wintypes.LPCWSTR,  # Query : LPCWSTR
    ctypes.c_void_p,  # Stats : LPWSTR* out
    ctypes.c_void_p,  # ErrorRecord : LPWSTR* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('computenetwork.dll')
HcnQueryEndpointStats = Fiddle::Function.new(
  lib['HcnQueryEndpointStats'],
  [
    Fiddle::TYPE_VOIDP,  # Endpoint : void*
    Fiddle::TYPE_VOIDP,  # Query : LPCWSTR
    Fiddle::TYPE_VOIDP,  # Stats : LPWSTR* out
    Fiddle::TYPE_VOIDP,  # ErrorRecord : LPWSTR* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "computenetwork")]
extern "system" {
    fn HcnQueryEndpointStats(
        Endpoint: *mut (),  // void*
        Query: *const u16,  // LPCWSTR
        Stats: *mut *mut u16,  // LPWSTR* out
        ErrorRecord: *mut *mut u16  // LPWSTR* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("computenetwork.dll")]
public static extern int HcnQueryEndpointStats(IntPtr Endpoint, [MarshalAs(UnmanagedType.LPWStr)] string Query, IntPtr Stats, IntPtr ErrorRecord);
"@
$api = Add-Type -MemberDefinition $sig -Name 'computenetwork_HcnQueryEndpointStats' -Namespace Win32 -PassThru
# $api::HcnQueryEndpointStats(Endpoint, Query, Stats, ErrorRecord)
#uselib "computenetwork.dll"
#func global HcnQueryEndpointStats "HcnQueryEndpointStats" sptr, sptr, sptr, sptr
; HcnQueryEndpointStats Endpoint, Query, varptr(Stats), varptr(ErrorRecord)   ; 戻り値は stat
; Endpoint : void* -> "sptr"
; Query : LPCWSTR -> "sptr"
; Stats : LPWSTR* out -> "sptr"
; ErrorRecord : LPWSTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "computenetwork.dll"
#cfunc global HcnQueryEndpointStats "HcnQueryEndpointStats" sptr, wstr, var, var
; res = HcnQueryEndpointStats(Endpoint, Query, Stats, ErrorRecord)
; Endpoint : void* -> "sptr"
; Query : LPCWSTR -> "wstr"
; Stats : LPWSTR* out -> "var"
; ErrorRecord : LPWSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT HcnQueryEndpointStats(void* Endpoint, LPCWSTR Query, LPWSTR* Stats, LPWSTR* ErrorRecord)
#uselib "computenetwork.dll"
#cfunc global HcnQueryEndpointStats "HcnQueryEndpointStats" intptr, wstr, var, var
; res = HcnQueryEndpointStats(Endpoint, Query, Stats, ErrorRecord)
; Endpoint : void* -> "intptr"
; Query : LPCWSTR -> "wstr"
; Stats : LPWSTR* out -> "var"
; ErrorRecord : LPWSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	computenetwork = windows.NewLazySystemDLL("computenetwork.dll")
	procHcnQueryEndpointStats = computenetwork.NewProc("HcnQueryEndpointStats")
)

// Endpoint (void*), Query (LPCWSTR), Stats (LPWSTR* out), ErrorRecord (LPWSTR* optional, out)
r1, _, err := procHcnQueryEndpointStats.Call(
	uintptr(Endpoint),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Query))),
	uintptr(Stats),
	uintptr(ErrorRecord),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function HcnQueryEndpointStats(
  Endpoint: Pointer;   // void*
  Query: PWideChar;   // LPCWSTR
  Stats: PPWideChar;   // LPWSTR* out
  ErrorRecord: PPWideChar   // LPWSTR* optional, out
): Integer; stdcall;
  external 'computenetwork.dll' name 'HcnQueryEndpointStats';
result := DllCall("computenetwork\HcnQueryEndpointStats"
    , "Ptr", Endpoint   ; void*
    , "WStr", Query   ; LPCWSTR
    , "Ptr", Stats   ; LPWSTR* out
    , "Ptr", ErrorRecord   ; LPWSTR* optional, out
    , "Int")   ; return: HRESULT
●HcnQueryEndpointStats(Endpoint, Query, Stats, ErrorRecord) = DLL("computenetwork.dll", "int HcnQueryEndpointStats(void*, char*, void*, void*)")
# 呼び出し: HcnQueryEndpointStats(Endpoint, Query, Stats, ErrorRecord)
# Endpoint : void* -> "void*"
# Query : LPCWSTR -> "char*"
# Stats : LPWSTR* out -> "void*"
# ErrorRecord : LPWSTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef HcnQueryEndpointStatsNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
typedef HcnQueryEndpointStatsDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
final HcnQueryEndpointStats = DynamicLibrary.open('computenetwork.dll')
    .lookupFunction<HcnQueryEndpointStatsNative, HcnQueryEndpointStatsDart>('HcnQueryEndpointStats');
// Endpoint : void* -> Pointer<Void>
// Query : LPCWSTR -> Pointer<Utf16>
// Stats : LPWSTR* out -> Pointer<Pointer<Utf16>>
// ErrorRecord : LPWSTR* optional, out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function HcnQueryEndpointStats(
  Endpoint: Pointer;   // void*
  Query: PWideChar;   // LPCWSTR
  Stats: PPWideChar;   // LPWSTR* out
  ErrorRecord: PPWideChar   // LPWSTR* optional, out
): Integer; stdcall;
  external 'computenetwork.dll' name 'HcnQueryEndpointStats';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "HcnQueryEndpointStats"
  c_HcnQueryEndpointStats :: Ptr () -> CWString -> Ptr CWString -> Ptr CWString -> IO Int32
-- Endpoint : void* -> Ptr ()
-- Query : LPCWSTR -> CWString
-- Stats : LPWSTR* out -> Ptr CWString
-- ErrorRecord : LPWSTR* optional, out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let hcnqueryendpointstats =
  foreign "HcnQueryEndpointStats"
    ((ptr void) @-> (ptr uint16_t) @-> (ptr (ptr uint16_t)) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* Endpoint : void* -> (ptr void) *)
(* Query : LPCWSTR -> (ptr uint16_t) *)
(* Stats : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* ErrorRecord : LPWSTR* optional, out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library computenetwork (t "computenetwork.dll"))
(cffi:use-foreign-library computenetwork)

(cffi:defcfun ("HcnQueryEndpointStats" hcn-query-endpoint-stats :convention :stdcall) :int32
  (endpoint :pointer)   ; void*
  (query (:string :encoding :utf-16le))   ; LPCWSTR
  (stats :pointer)   ; LPWSTR* out
  (error-record :pointer))   ; LPWSTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $HcnQueryEndpointStats = Win32::API::More->new('computenetwork',
    'int HcnQueryEndpointStats(LPVOID Endpoint, LPCWSTR Query, LPVOID Stats, LPVOID ErrorRecord)');
# my $ret = $HcnQueryEndpointStats->Call($Endpoint, $Query, $Stats, $ErrorRecord);
# Endpoint : void* -> LPVOID
# Query : LPCWSTR -> LPCWSTR
# Stats : LPWSTR* out -> LPVOID
# ErrorRecord : LPWSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。