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

WFDOpenLegacySession

関数
レガシーデバイスとのWi-Fi Directセッションを開く。
DLLwlanapi.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD WFDOpenLegacySession(
    HANDLE hClientHandle,
    BYTE** pLegacyMacAddress,
    HANDLE* phSessionHandle,
    GUID* pGuidSessionInterface
);

パラメーター

名前方向説明
hClientHandleHANDLEinWFDOpenHandleで取得したWFDクライアントハンドル。
pLegacyMacAddressBYTE**inレガシークライアントのMACアドレス(6バイト)を指すポインターへのポインター。
phSessionHandleHANDLE*out開かれたレガシーセッションのハンドルを受け取る出力先。
pGuidSessionInterfaceGUID*outセッションに対応するネットワークインターフェースのGUIDを受け取る出力先。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD WFDOpenLegacySession(
    HANDLE hClientHandle,
    BYTE** pLegacyMacAddress,
    HANDLE* phSessionHandle,
    GUID* pGuidSessionInterface
);
[DllImport("wlanapi.dll", ExactSpelling = true)]
static extern uint WFDOpenLegacySession(
    IntPtr hClientHandle,   // HANDLE
    IntPtr pLegacyMacAddress,   // BYTE**
    IntPtr phSessionHandle,   // HANDLE* out
    out Guid pGuidSessionInterface   // GUID* out
);
<DllImport("wlanapi.dll", ExactSpelling:=True)>
Public Shared Function WFDOpenLegacySession(
    hClientHandle As IntPtr,   ' HANDLE
    pLegacyMacAddress As IntPtr,   ' BYTE**
    phSessionHandle As IntPtr,   ' HANDLE* out
    <Out> ByRef pGuidSessionInterface As Guid   ' GUID* out
) As UInteger
End Function
' hClientHandle : HANDLE
' pLegacyMacAddress : BYTE**
' phSessionHandle : HANDLE* out
' pGuidSessionInterface : GUID* out
Declare PtrSafe Function WFDOpenLegacySession Lib "wlanapi" ( _
    ByVal hClientHandle As LongPtr, _
    ByVal pLegacyMacAddress As LongPtr, _
    ByVal phSessionHandle As LongPtr, _
    ByVal pGuidSessionInterface As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WFDOpenLegacySession = ctypes.windll.wlanapi.WFDOpenLegacySession
WFDOpenLegacySession.restype = wintypes.DWORD
WFDOpenLegacySession.argtypes = [
    wintypes.HANDLE,  # hClientHandle : HANDLE
    ctypes.c_void_p,  # pLegacyMacAddress : BYTE**
    ctypes.c_void_p,  # phSessionHandle : HANDLE* out
    ctypes.c_void_p,  # pGuidSessionInterface : GUID* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	wlanapi = windows.NewLazySystemDLL("wlanapi.dll")
	procWFDOpenLegacySession = wlanapi.NewProc("WFDOpenLegacySession")
)

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

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

typedef WFDOpenLegacySessionNative = Uint32 Function(Pointer<Void>, Pointer<Uint8>, Pointer<Void>, Pointer<Void>);
typedef WFDOpenLegacySessionDart = int Function(Pointer<Void>, Pointer<Uint8>, Pointer<Void>, Pointer<Void>);
final WFDOpenLegacySession = DynamicLibrary.open('wlanapi.dll')
    .lookupFunction<WFDOpenLegacySessionNative, WFDOpenLegacySessionDart>('WFDOpenLegacySession');
// hClientHandle : HANDLE -> Pointer<Void>
// pLegacyMacAddress : BYTE** -> Pointer<Uint8>
// phSessionHandle : HANDLE* out -> Pointer<Void>
// pGuidSessionInterface : GUID* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WFDOpenLegacySession(
  hClientHandle: THandle;   // HANDLE
  pLegacyMacAddress: Pointer;   // BYTE**
  phSessionHandle: Pointer;   // HANDLE* out
  pGuidSessionInterface: PGUID   // GUID* out
): DWORD; stdcall;
  external 'wlanapi.dll' name 'WFDOpenLegacySession';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WFDOpenLegacySession"
  c_WFDOpenLegacySession :: Ptr () -> Ptr Word8 -> Ptr () -> Ptr () -> IO Word32
-- hClientHandle : HANDLE -> Ptr ()
-- pLegacyMacAddress : BYTE** -> Ptr Word8
-- phSessionHandle : HANDLE* out -> Ptr ()
-- pGuidSessionInterface : GUID* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wfdopenlegacysession =
  foreign "WFDOpenLegacySession"
    ((ptr void) @-> (ptr uint8_t) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* hClientHandle : HANDLE -> (ptr void) *)
(* pLegacyMacAddress : BYTE** -> (ptr uint8_t) *)
(* phSessionHandle : HANDLE* out -> (ptr void) *)
(* pGuidSessionInterface : GUID* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wlanapi (t "wlanapi.dll"))
(cffi:use-foreign-library wlanapi)

(cffi:defcfun ("WFDOpenLegacySession" wfdopen-legacy-session :convention :stdcall) :uint32
  (h-client-handle :pointer)   ; HANDLE
  (p-legacy-mac-address :pointer)   ; BYTE**
  (ph-session-handle :pointer)   ; HANDLE* out
  (p-guid-session-interface :pointer))   ; GUID* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WFDOpenLegacySession = Win32::API::More->new('wlanapi',
    'DWORD WFDOpenLegacySession(HANDLE hClientHandle, LPVOID pLegacyMacAddress, HANDLE phSessionHandle, LPVOID pGuidSessionInterface)');
# my $ret = $WFDOpenLegacySession->Call($hClientHandle, $pLegacyMacAddress, $phSessionHandle, $pGuidSessionInterface);
# hClientHandle : HANDLE -> HANDLE
# pLegacyMacAddress : BYTE** -> LPVOID
# phSessionHandle : HANDLE* out -> HANDLE
# pGuidSessionInterface : GUID* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。