Win32 API 日本語リファレンス
ホームDevices.AllJoyn › alljoyn_busattachment_joinsession

alljoyn_busattachment_joinsession

関数
指定ホストのセッションポートに同期的に参加する。
DLLMSAJApi.dll呼出規約winapi

シグネチャ

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

QStatus alljoyn_busattachment_joinsession(
    alljoyn_busattachment bus,
    LPCSTR sessionHost,
    WORD sessionPort,
    alljoyn_sessionlistener listener,
    DWORD* sessionId,
    alljoyn_sessionopts opts
);

パラメーター

名前方向説明
busalljoyn_busattachmentin操作対象のバスアタッチメントハンドル。AllJoyn接続を表す。
sessionHostLPCSTRin参加先セッションをホストするバス名。ASCII文字列で指定する。
sessionPortWORDin接続先セッションのポート番号。ホストがバインドした値を指定する。
listeneralljoyn_sessionlistenerinセッションイベントを受け取るリスナハンドル。NULL可。
sessionIdDWORD*inout[出力]確立したセッションIDを受け取るポインタ。
optsalljoyn_sessionoptsin要求するセッションオプションのハンドル。トラフィック種別等を指定する。

戻り値の型: QStatus

各言語での呼び出し定義

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

QStatus alljoyn_busattachment_joinsession(
    alljoyn_busattachment bus,
    LPCSTR sessionHost,
    WORD sessionPort,
    alljoyn_sessionlistener listener,
    DWORD* sessionId,
    alljoyn_sessionopts opts
);
[DllImport("MSAJApi.dll", ExactSpelling = true)]
static extern int alljoyn_busattachment_joinsession(
    IntPtr bus,   // alljoyn_busattachment
    [MarshalAs(UnmanagedType.LPStr)] string sessionHost,   // LPCSTR
    ushort sessionPort,   // WORD
    IntPtr listener,   // alljoyn_sessionlistener
    ref uint sessionId,   // DWORD* in/out
    IntPtr opts   // alljoyn_sessionopts
);
<DllImport("MSAJApi.dll", ExactSpelling:=True)>
Public Shared Function alljoyn_busattachment_joinsession(
    bus As IntPtr,   ' alljoyn_busattachment
    <MarshalAs(UnmanagedType.LPStr)> sessionHost As String,   ' LPCSTR
    sessionPort As UShort,   ' WORD
    listener As IntPtr,   ' alljoyn_sessionlistener
    ByRef sessionId As UInteger,   ' DWORD* in/out
    opts As IntPtr   ' alljoyn_sessionopts
) As Integer
End Function
' bus : alljoyn_busattachment
' sessionHost : LPCSTR
' sessionPort : WORD
' listener : alljoyn_sessionlistener
' sessionId : DWORD* in/out
' opts : alljoyn_sessionopts
Declare PtrSafe Function alljoyn_busattachment_joinsession Lib "msajapi" ( _
    ByVal bus As LongPtr, _
    ByVal sessionHost As String, _
    ByVal sessionPort As Integer, _
    ByVal listener As LongPtr, _
    ByRef sessionId As Long, _
    ByVal opts As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

alljoyn_busattachment_joinsession = ctypes.windll.msajapi.alljoyn_busattachment_joinsession
alljoyn_busattachment_joinsession.restype = ctypes.c_int
alljoyn_busattachment_joinsession.argtypes = [
    ctypes.c_ssize_t,  # bus : alljoyn_busattachment
    wintypes.LPCSTR,  # sessionHost : LPCSTR
    ctypes.c_ushort,  # sessionPort : WORD
    ctypes.c_ssize_t,  # listener : alljoyn_sessionlistener
    ctypes.POINTER(wintypes.DWORD),  # sessionId : DWORD* in/out
    ctypes.c_ssize_t,  # opts : alljoyn_sessionopts
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MSAJApi.dll')
alljoyn_busattachment_joinsession = Fiddle::Function.new(
  lib['alljoyn_busattachment_joinsession'],
  [
    Fiddle::TYPE_INTPTR_T,  # bus : alljoyn_busattachment
    Fiddle::TYPE_VOIDP,  # sessionHost : LPCSTR
    -Fiddle::TYPE_SHORT,  # sessionPort : WORD
    Fiddle::TYPE_INTPTR_T,  # listener : alljoyn_sessionlistener
    Fiddle::TYPE_VOIDP,  # sessionId : DWORD* in/out
    Fiddle::TYPE_INTPTR_T,  # opts : alljoyn_sessionopts
  ],
  Fiddle::TYPE_INT)
#[link(name = "msajapi")]
extern "system" {
    fn alljoyn_busattachment_joinsession(
        bus: isize,  // alljoyn_busattachment
        sessionHost: *const u8,  // LPCSTR
        sessionPort: u16,  // WORD
        listener: isize,  // alljoyn_sessionlistener
        sessionId: *mut u32,  // DWORD* in/out
        opts: isize  // alljoyn_sessionopts
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MSAJApi.dll")]
public static extern int alljoyn_busattachment_joinsession(IntPtr bus, [MarshalAs(UnmanagedType.LPStr)] string sessionHost, ushort sessionPort, IntPtr listener, ref uint sessionId, IntPtr opts);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MSAJApi_alljoyn_busattachment_joinsession' -Namespace Win32 -PassThru
# $api::alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts)
#uselib "MSAJApi.dll"
#func global alljoyn_busattachment_joinsession "alljoyn_busattachment_joinsession" sptr, sptr, sptr, sptr, sptr, sptr
; alljoyn_busattachment_joinsession bus, sessionHost, sessionPort, listener, varptr(sessionId), opts   ; 戻り値は stat
; bus : alljoyn_busattachment -> "sptr"
; sessionHost : LPCSTR -> "sptr"
; sessionPort : WORD -> "sptr"
; listener : alljoyn_sessionlistener -> "sptr"
; sessionId : DWORD* in/out -> "sptr"
; opts : alljoyn_sessionopts -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "MSAJApi.dll"
#cfunc global alljoyn_busattachment_joinsession "alljoyn_busattachment_joinsession" sptr, str, int, sptr, var, sptr
; res = alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts)
; bus : alljoyn_busattachment -> "sptr"
; sessionHost : LPCSTR -> "str"
; sessionPort : WORD -> "int"
; listener : alljoyn_sessionlistener -> "sptr"
; sessionId : DWORD* in/out -> "var"
; opts : alljoyn_sessionopts -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; QStatus alljoyn_busattachment_joinsession(alljoyn_busattachment bus, LPCSTR sessionHost, WORD sessionPort, alljoyn_sessionlistener listener, DWORD* sessionId, alljoyn_sessionopts opts)
#uselib "MSAJApi.dll"
#cfunc global alljoyn_busattachment_joinsession "alljoyn_busattachment_joinsession" intptr, str, int, intptr, var, intptr
; res = alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts)
; bus : alljoyn_busattachment -> "intptr"
; sessionHost : LPCSTR -> "str"
; sessionPort : WORD -> "int"
; listener : alljoyn_sessionlistener -> "intptr"
; sessionId : DWORD* in/out -> "var"
; opts : alljoyn_sessionopts -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msajapi = windows.NewLazySystemDLL("MSAJApi.dll")
	procalljoyn_busattachment_joinsession = msajapi.NewProc("alljoyn_busattachment_joinsession")
)

// bus (alljoyn_busattachment), sessionHost (LPCSTR), sessionPort (WORD), listener (alljoyn_sessionlistener), sessionId (DWORD* in/out), opts (alljoyn_sessionopts)
r1, _, err := procalljoyn_busattachment_joinsession.Call(
	uintptr(bus),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(sessionHost))),
	uintptr(sessionPort),
	uintptr(listener),
	uintptr(sessionId),
	uintptr(opts),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // QStatus
function alljoyn_busattachment_joinsession(
  bus: NativeInt;   // alljoyn_busattachment
  sessionHost: PAnsiChar;   // LPCSTR
  sessionPort: Word;   // WORD
  listener: NativeInt;   // alljoyn_sessionlistener
  sessionId: Pointer;   // DWORD* in/out
  opts: NativeInt   // alljoyn_sessionopts
): Integer; stdcall;
  external 'MSAJApi.dll' name 'alljoyn_busattachment_joinsession';
result := DllCall("MSAJApi\alljoyn_busattachment_joinsession"
    , "Ptr", bus   ; alljoyn_busattachment
    , "AStr", sessionHost   ; LPCSTR
    , "UShort", sessionPort   ; WORD
    , "Ptr", listener   ; alljoyn_sessionlistener
    , "Ptr", sessionId   ; DWORD* in/out
    , "Ptr", opts   ; alljoyn_sessionopts
    , "Int")   ; return: QStatus
●alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts) = DLL("MSAJApi.dll", "int alljoyn_busattachment_joinsession(int, char*, int, int, void*, int)")
# 呼び出し: alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts)
# bus : alljoyn_busattachment -> "int"
# sessionHost : LPCSTR -> "char*"
# sessionPort : WORD -> "int"
# listener : alljoyn_sessionlistener -> "int"
# sessionId : DWORD* in/out -> "void*"
# opts : alljoyn_sessionopts -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "msajapi" fn alljoyn_busattachment_joinsession(
    bus: isize, // alljoyn_busattachment
    sessionHost: [*c]const u8, // LPCSTR
    sessionPort: u16, // WORD
    listener: isize, // alljoyn_sessionlistener
    sessionId: [*c]u32, // DWORD* in/out
    opts: isize // alljoyn_sessionopts
) callconv(std.os.windows.WINAPI) i32;
proc alljoyn_busattachment_joinsession(
    bus: int,  # alljoyn_busattachment
    sessionHost: cstring,  # LPCSTR
    sessionPort: uint16,  # WORD
    listener: int,  # alljoyn_sessionlistener
    sessionId: ptr uint32,  # DWORD* in/out
    opts: int  # alljoyn_sessionopts
): int32 {.importc: "alljoyn_busattachment_joinsession", stdcall, dynlib: "MSAJApi.dll".}
pragma(lib, "msajapi");
extern(Windows)
int alljoyn_busattachment_joinsession(
    ptrdiff_t bus,   // alljoyn_busattachment
    const(char)* sessionHost,   // LPCSTR
    ushort sessionPort,   // WORD
    ptrdiff_t listener,   // alljoyn_sessionlistener
    uint* sessionId,   // DWORD* in/out
    ptrdiff_t opts   // alljoyn_sessionopts
);
ccall((:alljoyn_busattachment_joinsession, "MSAJApi.dll"), stdcall, Int32,
      (Int, Cstring, UInt16, Int, Ptr{UInt32}, Int),
      bus, sessionHost, sessionPort, listener, sessionId, opts)
# bus : alljoyn_busattachment -> Int
# sessionHost : LPCSTR -> Cstring
# sessionPort : WORD -> UInt16
# listener : alljoyn_sessionlistener -> Int
# sessionId : DWORD* in/out -> Ptr{UInt32}
# opts : alljoyn_sessionopts -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t alljoyn_busattachment_joinsession(
    intptr_t bus,
    const char* sessionHost,
    uint16_t sessionPort,
    intptr_t listener,
    uint32_t* sessionId,
    intptr_t opts);
]]
local msajapi = ffi.load("msajapi")
-- msajapi.alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts)
-- bus : alljoyn_busattachment
-- sessionHost : LPCSTR
-- sessionPort : WORD
-- listener : alljoyn_sessionlistener
-- sessionId : DWORD* in/out
-- opts : alljoyn_sessionopts
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('MSAJApi.dll');
const alljoyn_busattachment_joinsession = lib.func('__stdcall', 'alljoyn_busattachment_joinsession', 'int32_t', ['intptr_t', 'str', 'uint16_t', 'intptr_t', 'uint32_t *', 'intptr_t']);
// alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts)
// bus : alljoyn_busattachment -> 'intptr_t'
// sessionHost : LPCSTR -> 'str'
// sessionPort : WORD -> 'uint16_t'
// listener : alljoyn_sessionlistener -> 'intptr_t'
// sessionId : DWORD* in/out -> 'uint32_t *'
// opts : alljoyn_sessionopts -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MSAJApi.dll", {
  alljoyn_busattachment_joinsession: { parameters: ["isize", "buffer", "u16", "isize", "pointer", "isize"], result: "i32" },
});
// lib.symbols.alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts)
// bus : alljoyn_busattachment -> "isize"
// sessionHost : LPCSTR -> "buffer"
// sessionPort : WORD -> "u16"
// listener : alljoyn_sessionlistener -> "isize"
// sessionId : DWORD* in/out -> "pointer"
// opts : alljoyn_sessionopts -> "isize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t alljoyn_busattachment_joinsession(
    intptr_t bus,
    const char* sessionHost,
    uint16_t sessionPort,
    intptr_t listener,
    uint32_t* sessionId,
    intptr_t opts);
C, "MSAJApi.dll");
// $ffi->alljoyn_busattachment_joinsession(bus, sessionHost, sessionPort, listener, sessionId, opts);
// bus : alljoyn_busattachment
// sessionHost : LPCSTR
// sessionPort : WORD
// listener : alljoyn_sessionlistener
// sessionId : DWORD* in/out
// opts : alljoyn_sessionopts
// 構造体/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 Msajapi extends StdCallLibrary {
    Msajapi INSTANCE = Native.load("msajapi", Msajapi.class);
    int alljoyn_busattachment_joinsession(
        long bus,   // alljoyn_busattachment
        String sessionHost,   // LPCSTR
        short sessionPort,   // WORD
        long listener,   // alljoyn_sessionlistener
        IntByReference sessionId,   // DWORD* in/out
        long opts   // alljoyn_sessionopts
    );
}
@[Link("msajapi")]
lib LibMSAJApi
  fun alljoyn_busattachment_joinsession = alljoyn_busattachment_joinsession(
    bus : LibC::SSizeT,   # alljoyn_busattachment
    sessionHost : UInt8*,   # LPCSTR
    sessionPort : UInt16,   # WORD
    listener : LibC::SSizeT,   # alljoyn_sessionlistener
    sessionId : UInt32*,   # DWORD* in/out
    opts : LibC::SSizeT   # alljoyn_sessionopts
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef alljoyn_busattachment_joinsessionNative = Int32 Function(IntPtr, Pointer<Utf8>, Uint16, IntPtr, Pointer<Uint32>, IntPtr);
typedef alljoyn_busattachment_joinsessionDart = int Function(int, Pointer<Utf8>, int, int, Pointer<Uint32>, int);
final alljoyn_busattachment_joinsession = DynamicLibrary.open('MSAJApi.dll')
    .lookupFunction<alljoyn_busattachment_joinsessionNative, alljoyn_busattachment_joinsessionDart>('alljoyn_busattachment_joinsession');
// bus : alljoyn_busattachment -> IntPtr
// sessionHost : LPCSTR -> Pointer<Utf8>
// sessionPort : WORD -> Uint16
// listener : alljoyn_sessionlistener -> IntPtr
// sessionId : DWORD* in/out -> Pointer<Uint32>
// opts : alljoyn_sessionopts -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function alljoyn_busattachment_joinsession(
  bus: NativeInt;   // alljoyn_busattachment
  sessionHost: PAnsiChar;   // LPCSTR
  sessionPort: Word;   // WORD
  listener: NativeInt;   // alljoyn_sessionlistener
  sessionId: Pointer;   // DWORD* in/out
  opts: NativeInt   // alljoyn_sessionopts
): Integer; stdcall;
  external 'MSAJApi.dll' name 'alljoyn_busattachment_joinsession';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "alljoyn_busattachment_joinsession"
  c_alljoyn_busattachment_joinsession :: CIntPtr -> CString -> Word16 -> CIntPtr -> Ptr Word32 -> CIntPtr -> IO Int32
-- bus : alljoyn_busattachment -> CIntPtr
-- sessionHost : LPCSTR -> CString
-- sessionPort : WORD -> Word16
-- listener : alljoyn_sessionlistener -> CIntPtr
-- sessionId : DWORD* in/out -> Ptr Word32
-- opts : alljoyn_sessionopts -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let alljoyn_busattachment_joinsession =
  foreign "alljoyn_busattachment_joinsession"
    (intptr_t @-> string @-> uint16_t @-> intptr_t @-> (ptr uint32_t) @-> intptr_t @-> returning int32_t)
(* bus : alljoyn_busattachment -> intptr_t *)
(* sessionHost : LPCSTR -> string *)
(* sessionPort : WORD -> uint16_t *)
(* listener : alljoyn_sessionlistener -> intptr_t *)
(* sessionId : DWORD* in/out -> (ptr uint32_t) *)
(* opts : alljoyn_sessionopts -> intptr_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library msajapi (t "MSAJApi.dll"))
(cffi:use-foreign-library msajapi)

(cffi:defcfun ("alljoyn_busattachment_joinsession" alljoyn-busattachment-joinsession :convention :stdcall) :int32
  (bus :int64)   ; alljoyn_busattachment
  (session-host :string)   ; LPCSTR
  (session-port :uint16)   ; WORD
  (listener :int64)   ; alljoyn_sessionlistener
  (session-id :pointer)   ; DWORD* in/out
  (opts :int64))   ; alljoyn_sessionopts
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $alljoyn_busattachment_joinsession = Win32::API::More->new('MSAJApi',
    'int alljoyn_busattachment_joinsession(LPARAM bus, LPCSTR sessionHost, WORD sessionPort, LPARAM listener, LPVOID sessionId, LPARAM opts)');
# my $ret = $alljoyn_busattachment_joinsession->Call($bus, $sessionHost, $sessionPort, $listener, $sessionId, $opts);
# bus : alljoyn_busattachment -> LPARAM
# sessionHost : LPCSTR -> LPCSTR
# sessionPort : WORD -> WORD
# listener : alljoyn_sessionlistener -> LPARAM
# sessionId : DWORD* in/out -> LPVOID
# opts : alljoyn_sessionopts -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型