ホーム › System.HostComputeNetwork › HcnQueryNetworkProperties
HcnQueryNetworkProperties
関数ネットワークのプロパティを照会して取得する。
シグネチャ
// computenetwork.dll
#include <windows.h>
HRESULT HcnQueryNetworkProperties(
void* Network,
LPCWSTR Query,
LPWSTR* Properties,
LPWSTR* ErrorRecord // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Network | void* | in | プロパティを取得する対象ネットワークのハンドル。 |
| Query | LPCWSTR | in | 取得するプロパティを指定するJSON形式のクエリ文字列。 |
| Properties | LPWSTR* | out | 取得結果をJSONで受け取る文字列ポインタ。解放が必要である。 |
| ErrorRecord | LPWSTR* | outoptional | 失敗時のエラー詳細をJSONで受け取る文字列ポインタ。NULL可。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// computenetwork.dll
#include <windows.h>
HRESULT HcnQueryNetworkProperties(
void* Network,
LPCWSTR Query,
LPWSTR* Properties,
LPWSTR* ErrorRecord // optional
);[DllImport("computenetwork.dll", ExactSpelling = true)]
static extern int HcnQueryNetworkProperties(
IntPtr Network, // void*
[MarshalAs(UnmanagedType.LPWStr)] string Query, // LPCWSTR
IntPtr Properties, // LPWSTR* out
IntPtr ErrorRecord // LPWSTR* optional, out
);<DllImport("computenetwork.dll", ExactSpelling:=True)>
Public Shared Function HcnQueryNetworkProperties(
Network As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPWStr)> Query As String, ' LPCWSTR
Properties As IntPtr, ' LPWSTR* out
ErrorRecord As IntPtr ' LPWSTR* optional, out
) As Integer
End Function' Network : void*
' Query : LPCWSTR
' Properties : LPWSTR* out
' ErrorRecord : LPWSTR* optional, out
Declare PtrSafe Function HcnQueryNetworkProperties Lib "computenetwork" ( _
ByVal Network As LongPtr, _
ByVal Query As LongPtr, _
ByVal Properties 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
HcnQueryNetworkProperties = ctypes.windll.computenetwork.HcnQueryNetworkProperties
HcnQueryNetworkProperties.restype = ctypes.c_int
HcnQueryNetworkProperties.argtypes = [
ctypes.POINTER(None), # Network : void*
wintypes.LPCWSTR, # Query : LPCWSTR
ctypes.c_void_p, # Properties : LPWSTR* out
ctypes.c_void_p, # ErrorRecord : LPWSTR* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('computenetwork.dll')
HcnQueryNetworkProperties = Fiddle::Function.new(
lib['HcnQueryNetworkProperties'],
[
Fiddle::TYPE_VOIDP, # Network : void*
Fiddle::TYPE_VOIDP, # Query : LPCWSTR
Fiddle::TYPE_VOIDP, # Properties : LPWSTR* out
Fiddle::TYPE_VOIDP, # ErrorRecord : LPWSTR* optional, out
],
Fiddle::TYPE_INT)#[link(name = "computenetwork")]
extern "system" {
fn HcnQueryNetworkProperties(
Network: *mut (), // void*
Query: *const u16, // LPCWSTR
Properties: *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 HcnQueryNetworkProperties(IntPtr Network, [MarshalAs(UnmanagedType.LPWStr)] string Query, IntPtr Properties, IntPtr ErrorRecord);
"@
$api = Add-Type -MemberDefinition $sig -Name 'computenetwork_HcnQueryNetworkProperties' -Namespace Win32 -PassThru
# $api::HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord)#uselib "computenetwork.dll"
#func global HcnQueryNetworkProperties "HcnQueryNetworkProperties" sptr, sptr, sptr, sptr
; HcnQueryNetworkProperties Network, Query, varptr(Properties), varptr(ErrorRecord) ; 戻り値は stat
; Network : void* -> "sptr"
; Query : LPCWSTR -> "sptr"
; Properties : LPWSTR* out -> "sptr"
; ErrorRecord : LPWSTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "computenetwork.dll" #cfunc global HcnQueryNetworkProperties "HcnQueryNetworkProperties" sptr, wstr, var, var ; res = HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord) ; Network : void* -> "sptr" ; Query : LPCWSTR -> "wstr" ; Properties : LPWSTR* out -> "var" ; ErrorRecord : LPWSTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "computenetwork.dll" #cfunc global HcnQueryNetworkProperties "HcnQueryNetworkProperties" sptr, wstr, sptr, sptr ; res = HcnQueryNetworkProperties(Network, Query, varptr(Properties), varptr(ErrorRecord)) ; Network : void* -> "sptr" ; Query : LPCWSTR -> "wstr" ; Properties : LPWSTR* out -> "sptr" ; ErrorRecord : LPWSTR* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT HcnQueryNetworkProperties(void* Network, LPCWSTR Query, LPWSTR* Properties, LPWSTR* ErrorRecord) #uselib "computenetwork.dll" #cfunc global HcnQueryNetworkProperties "HcnQueryNetworkProperties" intptr, wstr, var, var ; res = HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord) ; Network : void* -> "intptr" ; Query : LPCWSTR -> "wstr" ; Properties : LPWSTR* out -> "var" ; ErrorRecord : LPWSTR* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT HcnQueryNetworkProperties(void* Network, LPCWSTR Query, LPWSTR* Properties, LPWSTR* ErrorRecord) #uselib "computenetwork.dll" #cfunc global HcnQueryNetworkProperties "HcnQueryNetworkProperties" intptr, wstr, intptr, intptr ; res = HcnQueryNetworkProperties(Network, Query, varptr(Properties), varptr(ErrorRecord)) ; Network : void* -> "intptr" ; Query : LPCWSTR -> "wstr" ; Properties : LPWSTR* out -> "intptr" ; ErrorRecord : LPWSTR* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
computenetwork = windows.NewLazySystemDLL("computenetwork.dll")
procHcnQueryNetworkProperties = computenetwork.NewProc("HcnQueryNetworkProperties")
)
// Network (void*), Query (LPCWSTR), Properties (LPWSTR* out), ErrorRecord (LPWSTR* optional, out)
r1, _, err := procHcnQueryNetworkProperties.Call(
uintptr(Network),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Query))),
uintptr(Properties),
uintptr(ErrorRecord),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction HcnQueryNetworkProperties(
Network: Pointer; // void*
Query: PWideChar; // LPCWSTR
Properties: PPWideChar; // LPWSTR* out
ErrorRecord: PPWideChar // LPWSTR* optional, out
): Integer; stdcall;
external 'computenetwork.dll' name 'HcnQueryNetworkProperties';result := DllCall("computenetwork\HcnQueryNetworkProperties"
, "Ptr", Network ; void*
, "WStr", Query ; LPCWSTR
, "Ptr", Properties ; LPWSTR* out
, "Ptr", ErrorRecord ; LPWSTR* optional, out
, "Int") ; return: HRESULT●HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord) = DLL("computenetwork.dll", "int HcnQueryNetworkProperties(void*, char*, void*, void*)")
# 呼び出し: HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord)
# Network : void* -> "void*"
# Query : LPCWSTR -> "char*"
# Properties : LPWSTR* out -> "void*"
# ErrorRecord : LPWSTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "computenetwork" fn HcnQueryNetworkProperties(
Network: ?*anyopaque, // void*
Query: [*c]const u16, // LPCWSTR
Properties: [*c][*c]u16, // LPWSTR* out
ErrorRecord: [*c][*c]u16 // LPWSTR* optional, out
) callconv(std.os.windows.WINAPI) i32;proc HcnQueryNetworkProperties(
Network: pointer, # void*
Query: WideCString, # LPCWSTR
Properties: ptr WideCString, # LPWSTR* out
ErrorRecord: ptr WideCString # LPWSTR* optional, out
): int32 {.importc: "HcnQueryNetworkProperties", stdcall, dynlib: "computenetwork.dll".}pragma(lib, "computenetwork");
extern(Windows)
int HcnQueryNetworkProperties(
void* Network, // void*
const(wchar)* Query, // LPCWSTR
wchar** Properties, // LPWSTR* out
wchar** ErrorRecord // LPWSTR* optional, out
);ccall((:HcnQueryNetworkProperties, "computenetwork.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Ptr{Ptr{UInt16}}, Ptr{Ptr{UInt16}}),
Network, Query, Properties, ErrorRecord)
# Network : void* -> Ptr{Cvoid}
# Query : LPCWSTR -> Cwstring
# Properties : LPWSTR* out -> Ptr{Ptr{UInt16}}
# ErrorRecord : LPWSTR* optional, out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t HcnQueryNetworkProperties(
void* Network,
const uint16_t* Query,
uint16_t** Properties,
uint16_t** ErrorRecord);
]]
local computenetwork = ffi.load("computenetwork")
-- computenetwork.HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord)
-- Network : void*
-- Query : LPCWSTR
-- Properties : LPWSTR* out
-- ErrorRecord : LPWSTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('computenetwork.dll');
const HcnQueryNetworkProperties = lib.func('__stdcall', 'HcnQueryNetworkProperties', 'int32_t', ['void *', 'str16', 'void *', 'void *']);
// HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord)
// Network : void* -> 'void *'
// Query : LPCWSTR -> 'str16'
// Properties : LPWSTR* out -> 'void *'
// ErrorRecord : LPWSTR* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("computenetwork.dll", {
HcnQueryNetworkProperties: { parameters: ["pointer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord)
// Network : void* -> "pointer"
// Query : LPCWSTR -> "buffer"
// Properties : LPWSTR* out -> "pointer"
// ErrorRecord : LPWSTR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t HcnQueryNetworkProperties(
void* Network,
const uint16_t* Query,
uint16_t** Properties,
uint16_t** ErrorRecord);
C, "computenetwork.dll");
// $ffi->HcnQueryNetworkProperties(Network, Query, Properties, ErrorRecord);
// Network : void*
// Query : LPCWSTR
// Properties : 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 HcnQueryNetworkProperties(
Pointer Network, // void*
WString Query, // LPCWSTR
PointerByReference Properties, // LPWSTR* out
PointerByReference ErrorRecord // LPWSTR* optional, out
);
}@[Link("computenetwork")]
lib Libcomputenetwork
fun HcnQueryNetworkProperties = HcnQueryNetworkProperties(
Network : Void*, # void*
Query : UInt16*, # LPCWSTR
Properties : 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 HcnQueryNetworkPropertiesNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
typedef HcnQueryNetworkPropertiesDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Pointer<Utf16>>, Pointer<Pointer<Utf16>>);
final HcnQueryNetworkProperties = DynamicLibrary.open('computenetwork.dll')
.lookupFunction<HcnQueryNetworkPropertiesNative, HcnQueryNetworkPropertiesDart>('HcnQueryNetworkProperties');
// Network : void* -> Pointer<Void>
// Query : LPCWSTR -> Pointer<Utf16>
// Properties : LPWSTR* out -> Pointer<Pointer<Utf16>>
// ErrorRecord : LPWSTR* optional, out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function HcnQueryNetworkProperties(
Network: Pointer; // void*
Query: PWideChar; // LPCWSTR
Properties: PPWideChar; // LPWSTR* out
ErrorRecord: PPWideChar // LPWSTR* optional, out
): Integer; stdcall;
external 'computenetwork.dll' name 'HcnQueryNetworkProperties';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "HcnQueryNetworkProperties"
c_HcnQueryNetworkProperties :: Ptr () -> CWString -> Ptr CWString -> Ptr CWString -> IO Int32
-- Network : void* -> Ptr ()
-- Query : LPCWSTR -> CWString
-- Properties : LPWSTR* out -> Ptr CWString
-- ErrorRecord : LPWSTR* optional, out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let hcnquerynetworkproperties =
foreign "HcnQueryNetworkProperties"
((ptr void) @-> (ptr uint16_t) @-> (ptr (ptr uint16_t)) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* Network : void* -> (ptr void) *)
(* Query : LPCWSTR -> (ptr uint16_t) *)
(* Properties : 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 ("HcnQueryNetworkProperties" hcn-query-network-properties :convention :stdcall) :int32
(network :pointer) ; void*
(query (:string :encoding :utf-16le)) ; LPCWSTR
(properties :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 $HcnQueryNetworkProperties = Win32::API::More->new('computenetwork',
'int HcnQueryNetworkProperties(LPVOID Network, LPCWSTR Query, LPVOID Properties, LPVOID ErrorRecord)');
# my $ret = $HcnQueryNetworkProperties->Call($Network, $Query, $Properties, $ErrorRecord);
# Network : void* -> LPVOID
# Query : LPCWSTR -> LPCWSTR
# Properties : LPWSTR* out -> LPVOID
# ErrorRecord : LPWSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。