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

HcnOpenEndpoint

関数
IDを指定して既存のエンドポイントを開く。
DLLcomputenetwork.dll呼出規約winapi

シグネチャ

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

HRESULT HcnOpenEndpoint(
    const GUID* Id,
    void** Endpoint,
    LPWSTR* ErrorRecord   // optional
);

パラメーター

名前方向説明
IdGUID*in開く既存エンドポイントを特定するGUIDへのポインタ。
Endpointvoid**out開いたエンドポイントのハンドルを受け取る出力ポインタ。
ErrorRecordLPWSTR*outoptional失敗時のエラー詳細をJSONで受け取る文字列ポインタ。NULL可。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT HcnOpenEndpoint(
    const GUID* Id,
    void** Endpoint,
    LPWSTR* ErrorRecord   // optional
);
[DllImport("computenetwork.dll", ExactSpelling = true)]
static extern int HcnOpenEndpoint(
    ref Guid Id,   // GUID*
    IntPtr Endpoint,   // void** out
    IntPtr ErrorRecord   // LPWSTR* optional, out
);
<DllImport("computenetwork.dll", ExactSpelling:=True)>
Public Shared Function HcnOpenEndpoint(
    ByRef Id As Guid,   ' GUID*
    Endpoint As IntPtr,   ' void** out
    ErrorRecord As IntPtr   ' LPWSTR* optional, out
) As Integer
End Function
' Id : GUID*
' Endpoint : void** out
' ErrorRecord : LPWSTR* optional, out
Declare PtrSafe Function HcnOpenEndpoint Lib "computenetwork" ( _
    ByVal Id As LongPtr, _
    ByVal Endpoint 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

HcnOpenEndpoint = ctypes.windll.computenetwork.HcnOpenEndpoint
HcnOpenEndpoint.restype = ctypes.c_int
HcnOpenEndpoint.argtypes = [
    ctypes.c_void_p,  # Id : GUID*
    ctypes.c_void_p,  # Endpoint : void** out
    ctypes.c_void_p,  # ErrorRecord : LPWSTR* optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('computenetwork.dll')
HcnOpenEndpoint = Fiddle::Function.new(
  lib['HcnOpenEndpoint'],
  [
    Fiddle::TYPE_VOIDP,  # Id : GUID*
    Fiddle::TYPE_VOIDP,  # Endpoint : void** out
    Fiddle::TYPE_VOIDP,  # ErrorRecord : LPWSTR* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "computenetwork")]
extern "system" {
    fn HcnOpenEndpoint(
        Id: *const GUID,  // GUID*
        Endpoint: *mut *mut (),  // void** 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 HcnOpenEndpoint(ref Guid Id, IntPtr Endpoint, IntPtr ErrorRecord);
"@
$api = Add-Type -MemberDefinition $sig -Name 'computenetwork_HcnOpenEndpoint' -Namespace Win32 -PassThru
# $api::HcnOpenEndpoint(Id, Endpoint, ErrorRecord)
#uselib "computenetwork.dll"
#func global HcnOpenEndpoint "HcnOpenEndpoint" sptr, sptr, sptr
; HcnOpenEndpoint varptr(Id), Endpoint, varptr(ErrorRecord)   ; 戻り値は stat
; Id : GUID* -> "sptr"
; Endpoint : void** out -> "sptr"
; ErrorRecord : LPWSTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "computenetwork.dll"
#cfunc global HcnOpenEndpoint "HcnOpenEndpoint" var, sptr, var
; res = HcnOpenEndpoint(Id, Endpoint, ErrorRecord)
; Id : GUID* -> "var"
; Endpoint : void** out -> "sptr"
; ErrorRecord : LPWSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT HcnOpenEndpoint(GUID* Id, void** Endpoint, LPWSTR* ErrorRecord)
#uselib "computenetwork.dll"
#cfunc global HcnOpenEndpoint "HcnOpenEndpoint" var, intptr, var
; res = HcnOpenEndpoint(Id, Endpoint, ErrorRecord)
; Id : GUID* -> "var"
; Endpoint : void** out -> "intptr"
; ErrorRecord : LPWSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	computenetwork = windows.NewLazySystemDLL("computenetwork.dll")
	procHcnOpenEndpoint = computenetwork.NewProc("HcnOpenEndpoint")
)

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

extern "computenetwork" fn HcnOpenEndpoint(
    Id: [*c]GUID, // GUID*
    Endpoint: ?*anyopaque, // void** out
    ErrorRecord: [*c][*c]u16 // LPWSTR* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc HcnOpenEndpoint(
    Id: ptr GUID,  # GUID*
    Endpoint: pointer,  # void** out
    ErrorRecord: ptr WideCString  # LPWSTR* optional, out
): int32 {.importc: "HcnOpenEndpoint", stdcall, dynlib: "computenetwork.dll".}
pragma(lib, "computenetwork");
extern(Windows)
int HcnOpenEndpoint(
    GUID* Id,   // GUID*
    void** Endpoint,   // void** out
    wchar** ErrorRecord   // LPWSTR* optional, out
);
ccall((:HcnOpenEndpoint, "computenetwork.dll"), stdcall, Int32,
      (Ptr{GUID}, Ptr{Cvoid}, Ptr{Ptr{UInt16}}),
      Id, Endpoint, ErrorRecord)
# Id : GUID* -> Ptr{GUID}
# Endpoint : void** out -> Ptr{Cvoid}
# ErrorRecord : LPWSTR* optional, out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t HcnOpenEndpoint(
    void* Id,
    void** Endpoint,
    uint16_t** ErrorRecord);
]]
local computenetwork = ffi.load("computenetwork")
-- computenetwork.HcnOpenEndpoint(Id, Endpoint, ErrorRecord)
-- Id : GUID*
-- Endpoint : void** out
-- ErrorRecord : LPWSTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('computenetwork.dll');
const HcnOpenEndpoint = lib.func('__stdcall', 'HcnOpenEndpoint', 'int32_t', ['void *', 'void *', 'void *']);
// HcnOpenEndpoint(Id, Endpoint, ErrorRecord)
// Id : GUID* -> 'void *'
// Endpoint : void** out -> 'void *'
// ErrorRecord : LPWSTR* optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("computenetwork.dll", {
  HcnOpenEndpoint: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.HcnOpenEndpoint(Id, Endpoint, ErrorRecord)
// Id : GUID* -> "pointer"
// Endpoint : void** out -> "pointer"
// ErrorRecord : LPWSTR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t HcnOpenEndpoint(
    void* Id,
    void** Endpoint,
    uint16_t** ErrorRecord);
C, "computenetwork.dll");
// $ffi->HcnOpenEndpoint(Id, Endpoint, ErrorRecord);
// Id : GUID*
// Endpoint : void** 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 HcnOpenEndpoint(
        Pointer Id,   // GUID*
        Pointer Endpoint,   // void** out
        PointerByReference ErrorRecord   // LPWSTR* optional, out
    );
}
@[Link("computenetwork")]
lib Libcomputenetwork
  fun HcnOpenEndpoint = HcnOpenEndpoint(
    Id : GUID*,   # GUID*
    Endpoint : Void**,   # void** 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 HcnOpenEndpointNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Pointer<Utf16>>);
typedef HcnOpenEndpointDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Pointer<Utf16>>);
final HcnOpenEndpoint = DynamicLibrary.open('computenetwork.dll')
    .lookupFunction<HcnOpenEndpointNative, HcnOpenEndpointDart>('HcnOpenEndpoint');
// Id : GUID* -> Pointer<Void>
// Endpoint : void** out -> Pointer<Void>
// ErrorRecord : LPWSTR* optional, out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function HcnOpenEndpoint(
  Id: PGUID;   // GUID*
  Endpoint: Pointer;   // void** out
  ErrorRecord: PPWideChar   // LPWSTR* optional, out
): Integer; stdcall;
  external 'computenetwork.dll' name 'HcnOpenEndpoint';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let hcnopenendpoint =
  foreign "HcnOpenEndpoint"
    ((ptr void) @-> (ptr void) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* Id : GUID* -> (ptr void) *)
(* Endpoint : void** out -> (ptr void) *)
(* 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 ("HcnOpenEndpoint" hcn-open-endpoint :convention :stdcall) :int32
  (id :pointer)   ; GUID*
  (endpoint :pointer)   ; void** out
  (error-record :pointer))   ; LPWSTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $HcnOpenEndpoint = Win32::API::More->new('computenetwork',
    'int HcnOpenEndpoint(LPVOID Id, LPVOID Endpoint, LPVOID ErrorRecord)');
# my $ret = $HcnOpenEndpoint->Call($Id, $Endpoint, $ErrorRecord);
# Id : GUID* -> LPVOID
# Endpoint : void** out -> LPVOID
# ErrorRecord : LPWSTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。