ホーム › NetworkManagement.P2P › PeerDistServerPublishStream
PeerDistServerPublishStream
関数サーバー側でコンテンツストリームの公開を開始する。
シグネチャ
// PeerDist.dll
#include <windows.h>
DWORD PeerDistServerPublishStream(
INT_PTR hPeerDist,
DWORD cbContentIdentifier,
BYTE* pContentIdentifier,
ULONGLONG cbContentLength,
PEERDIST_PUBLICATION_OPTIONS* pPublishOptions, // optional
HANDLE hCompletionPort, // optional
UINT_PTR ulCompletionKey, // optional
INT_PTR* phStream
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hPeerDist | INT_PTR | in | 対象のPeerDistセッションのハンドル。 |
| cbContentIdentifier | DWORD | in | pContentIdentifierが指すコンテンツ識別子のバイト数。 |
| pContentIdentifier | BYTE* | in | 公開するコンテンツを一意に識別するバイト列へのポインタ。 |
| cbContentLength | ULONGLONG | in | 公開するコンテンツの総バイト数(64ビット)。 |
| pPublishOptions | PEERDIST_PUBLICATION_OPTIONS* | inoptional | 公開オプションを格納した構造体へのポインタ。NULL可で既定値となる。 |
| hCompletionPort | HANDLE | inoptional | 非同期完了通知を受け取る完了ポートのハンドル。 |
| ulCompletionKey | UINT_PTR | inoptional | 完了パケットに関連付ける完了キー。 |
| phStream | INT_PTR* | out | 公開ストリームのハンドルを受け取るポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// PeerDist.dll
#include <windows.h>
DWORD PeerDistServerPublishStream(
INT_PTR hPeerDist,
DWORD cbContentIdentifier,
BYTE* pContentIdentifier,
ULONGLONG cbContentLength,
PEERDIST_PUBLICATION_OPTIONS* pPublishOptions, // optional
HANDLE hCompletionPort, // optional
UINT_PTR ulCompletionKey, // optional
INT_PTR* phStream
);[DllImport("PeerDist.dll", ExactSpelling = true)]
static extern uint PeerDistServerPublishStream(
IntPtr hPeerDist, // INT_PTR
uint cbContentIdentifier, // DWORD
IntPtr pContentIdentifier, // BYTE*
ulong cbContentLength, // ULONGLONG
IntPtr pPublishOptions, // PEERDIST_PUBLICATION_OPTIONS* optional
IntPtr hCompletionPort, // HANDLE optional
UIntPtr ulCompletionKey, // UINT_PTR optional
out IntPtr phStream // INT_PTR* out
);<DllImport("PeerDist.dll", ExactSpelling:=True)>
Public Shared Function PeerDistServerPublishStream(
hPeerDist As IntPtr, ' INT_PTR
cbContentIdentifier As UInteger, ' DWORD
pContentIdentifier As IntPtr, ' BYTE*
cbContentLength As ULong, ' ULONGLONG
pPublishOptions As IntPtr, ' PEERDIST_PUBLICATION_OPTIONS* optional
hCompletionPort As IntPtr, ' HANDLE optional
ulCompletionKey As UIntPtr, ' UINT_PTR optional
<Out> ByRef phStream As IntPtr ' INT_PTR* out
) As UInteger
End Function' hPeerDist : INT_PTR
' cbContentIdentifier : DWORD
' pContentIdentifier : BYTE*
' cbContentLength : ULONGLONG
' pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional
' hCompletionPort : HANDLE optional
' ulCompletionKey : UINT_PTR optional
' phStream : INT_PTR* out
Declare PtrSafe Function PeerDistServerPublishStream Lib "peerdist" ( _
ByVal hPeerDist As LongPtr, _
ByVal cbContentIdentifier As Long, _
ByVal pContentIdentifier As LongPtr, _
ByVal cbContentLength As LongLong, _
ByVal pPublishOptions As LongPtr, _
ByVal hCompletionPort As LongPtr, _
ByVal ulCompletionKey As LongPtr, _
ByRef phStream As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PeerDistServerPublishStream = ctypes.windll.peerdist.PeerDistServerPublishStream
PeerDistServerPublishStream.restype = wintypes.DWORD
PeerDistServerPublishStream.argtypes = [
ctypes.c_ssize_t, # hPeerDist : INT_PTR
wintypes.DWORD, # cbContentIdentifier : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pContentIdentifier : BYTE*
ctypes.c_ulonglong, # cbContentLength : ULONGLONG
ctypes.c_void_p, # pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional
wintypes.HANDLE, # hCompletionPort : HANDLE optional
ctypes.c_size_t, # ulCompletionKey : UINT_PTR optional
ctypes.POINTER(ctypes.c_ssize_t), # phStream : INT_PTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('PeerDist.dll')
PeerDistServerPublishStream = Fiddle::Function.new(
lib['PeerDistServerPublishStream'],
[
Fiddle::TYPE_INTPTR_T, # hPeerDist : INT_PTR
-Fiddle::TYPE_INT, # cbContentIdentifier : DWORD
Fiddle::TYPE_VOIDP, # pContentIdentifier : BYTE*
-Fiddle::TYPE_LONG_LONG, # cbContentLength : ULONGLONG
Fiddle::TYPE_VOIDP, # pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional
Fiddle::TYPE_VOIDP, # hCompletionPort : HANDLE optional
Fiddle::TYPE_UINTPTR_T, # ulCompletionKey : UINT_PTR optional
Fiddle::TYPE_VOIDP, # phStream : INT_PTR* out
],
-Fiddle::TYPE_INT)#[link(name = "peerdist")]
extern "system" {
fn PeerDistServerPublishStream(
hPeerDist: isize, // INT_PTR
cbContentIdentifier: u32, // DWORD
pContentIdentifier: *mut u8, // BYTE*
cbContentLength: u64, // ULONGLONG
pPublishOptions: *mut PEERDIST_PUBLICATION_OPTIONS, // PEERDIST_PUBLICATION_OPTIONS* optional
hCompletionPort: *mut core::ffi::c_void, // HANDLE optional
ulCompletionKey: usize, // UINT_PTR optional
phStream: *mut isize // INT_PTR* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("PeerDist.dll")]
public static extern uint PeerDistServerPublishStream(IntPtr hPeerDist, uint cbContentIdentifier, IntPtr pContentIdentifier, ulong cbContentLength, IntPtr pPublishOptions, IntPtr hCompletionPort, UIntPtr ulCompletionKey, out IntPtr phStream);
"@
$api = Add-Type -MemberDefinition $sig -Name 'PeerDist_PeerDistServerPublishStream' -Namespace Win32 -PassThru
# $api::PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream)#uselib "PeerDist.dll"
#func global PeerDistServerPublishStream "PeerDistServerPublishStream" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; PeerDistServerPublishStream hPeerDist, cbContentIdentifier, varptr(pContentIdentifier), cbContentLength, varptr(pPublishOptions), hCompletionPort, ulCompletionKey, varptr(phStream) ; 戻り値は stat
; hPeerDist : INT_PTR -> "sptr"
; cbContentIdentifier : DWORD -> "sptr"
; pContentIdentifier : BYTE* -> "sptr"
; cbContentLength : ULONGLONG -> "sptr"
; pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> "sptr"
; hCompletionPort : HANDLE optional -> "sptr"
; ulCompletionKey : UINT_PTR optional -> "sptr"
; phStream : INT_PTR* out -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "PeerDist.dll" #cfunc global PeerDistServerPublishStream "PeerDistServerPublishStream" sptr, int, var, int64, var, sptr, sptr, var ; res = PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream) ; hPeerDist : INT_PTR -> "sptr" ; cbContentIdentifier : DWORD -> "int" ; pContentIdentifier : BYTE* -> "var" ; cbContentLength : ULONGLONG -> "int64" ; pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> "var" ; hCompletionPort : HANDLE optional -> "sptr" ; ulCompletionKey : UINT_PTR optional -> "sptr" ; phStream : INT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。#uselib "PeerDist.dll" #cfunc global PeerDistServerPublishStream "PeerDistServerPublishStream" sptr, int, sptr, int64, sptr, sptr, sptr, sptr ; res = PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, varptr(pContentIdentifier), cbContentLength, varptr(pPublishOptions), hCompletionPort, ulCompletionKey, varptr(phStream)) ; hPeerDist : INT_PTR -> "sptr" ; cbContentIdentifier : DWORD -> "int" ; pContentIdentifier : BYTE* -> "sptr" ; cbContentLength : ULONGLONG -> "int64" ; pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> "sptr" ; hCompletionPort : HANDLE optional -> "sptr" ; ulCompletionKey : UINT_PTR optional -> "sptr" ; phStream : INT_PTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; DWORD PeerDistServerPublishStream(INT_PTR hPeerDist, DWORD cbContentIdentifier, BYTE* pContentIdentifier, ULONGLONG cbContentLength, PEERDIST_PUBLICATION_OPTIONS* pPublishOptions, HANDLE hCompletionPort, UINT_PTR ulCompletionKey, INT_PTR* phStream) #uselib "PeerDist.dll" #cfunc global PeerDistServerPublishStream "PeerDistServerPublishStream" intptr, int, var, int64, var, intptr, intptr, var ; res = PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream) ; hPeerDist : INT_PTR -> "intptr" ; cbContentIdentifier : DWORD -> "int" ; pContentIdentifier : BYTE* -> "var" ; cbContentLength : ULONGLONG -> "int64" ; pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> "var" ; hCompletionPort : HANDLE optional -> "intptr" ; ulCompletionKey : UINT_PTR optional -> "intptr" ; phStream : INT_PTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD PeerDistServerPublishStream(INT_PTR hPeerDist, DWORD cbContentIdentifier, BYTE* pContentIdentifier, ULONGLONG cbContentLength, PEERDIST_PUBLICATION_OPTIONS* pPublishOptions, HANDLE hCompletionPort, UINT_PTR ulCompletionKey, INT_PTR* phStream) #uselib "PeerDist.dll" #cfunc global PeerDistServerPublishStream "PeerDistServerPublishStream" intptr, int, intptr, int64, intptr, intptr, intptr, intptr ; res = PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, varptr(pContentIdentifier), cbContentLength, varptr(pPublishOptions), hCompletionPort, ulCompletionKey, varptr(phStream)) ; hPeerDist : INT_PTR -> "intptr" ; cbContentIdentifier : DWORD -> "int" ; pContentIdentifier : BYTE* -> "intptr" ; cbContentLength : ULONGLONG -> "int64" ; pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> "intptr" ; hCompletionPort : HANDLE optional -> "intptr" ; ulCompletionKey : UINT_PTR optional -> "intptr" ; phStream : INT_PTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
peerdist = windows.NewLazySystemDLL("PeerDist.dll")
procPeerDistServerPublishStream = peerdist.NewProc("PeerDistServerPublishStream")
)
// hPeerDist (INT_PTR), cbContentIdentifier (DWORD), pContentIdentifier (BYTE*), cbContentLength (ULONGLONG), pPublishOptions (PEERDIST_PUBLICATION_OPTIONS* optional), hCompletionPort (HANDLE optional), ulCompletionKey (UINT_PTR optional), phStream (INT_PTR* out)
r1, _, err := procPeerDistServerPublishStream.Call(
uintptr(hPeerDist),
uintptr(cbContentIdentifier),
uintptr(pContentIdentifier),
uintptr(cbContentLength),
uintptr(pPublishOptions),
uintptr(hCompletionPort),
uintptr(ulCompletionKey),
uintptr(phStream),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PeerDistServerPublishStream(
hPeerDist: NativeInt; // INT_PTR
cbContentIdentifier: DWORD; // DWORD
pContentIdentifier: Pointer; // BYTE*
cbContentLength: UInt64; // ULONGLONG
pPublishOptions: Pointer; // PEERDIST_PUBLICATION_OPTIONS* optional
hCompletionPort: THandle; // HANDLE optional
ulCompletionKey: NativeUInt; // UINT_PTR optional
phStream: Pointer // INT_PTR* out
): DWORD; stdcall;
external 'PeerDist.dll' name 'PeerDistServerPublishStream';result := DllCall("PeerDist\PeerDistServerPublishStream"
, "Ptr", hPeerDist ; INT_PTR
, "UInt", cbContentIdentifier ; DWORD
, "Ptr", pContentIdentifier ; BYTE*
, "Int64", cbContentLength ; ULONGLONG
, "Ptr", pPublishOptions ; PEERDIST_PUBLICATION_OPTIONS* optional
, "Ptr", hCompletionPort ; HANDLE optional
, "UPtr", ulCompletionKey ; UINT_PTR optional
, "Ptr", phStream ; INT_PTR* out
, "UInt") ; return: DWORD●PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream) = DLL("PeerDist.dll", "dword PeerDistServerPublishStream(int, dword, void*, qword, void*, void*, int, void*)")
# 呼び出し: PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream)
# hPeerDist : INT_PTR -> "int"
# cbContentIdentifier : DWORD -> "dword"
# pContentIdentifier : BYTE* -> "void*"
# cbContentLength : ULONGLONG -> "qword"
# pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> "void*"
# hCompletionPort : HANDLE optional -> "void*"
# ulCompletionKey : UINT_PTR optional -> "int"
# phStream : INT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "peerdist" fn PeerDistServerPublishStream(
hPeerDist: isize, // INT_PTR
cbContentIdentifier: u32, // DWORD
pContentIdentifier: [*c]u8, // BYTE*
cbContentLength: u64, // ULONGLONG
pPublishOptions: [*c]PEERDIST_PUBLICATION_OPTIONS, // PEERDIST_PUBLICATION_OPTIONS* optional
hCompletionPort: ?*anyopaque, // HANDLE optional
ulCompletionKey: usize, // UINT_PTR optional
phStream: [*c]isize // INT_PTR* out
) callconv(std.os.windows.WINAPI) u32;proc PeerDistServerPublishStream(
hPeerDist: int, # INT_PTR
cbContentIdentifier: uint32, # DWORD
pContentIdentifier: ptr uint8, # BYTE*
cbContentLength: uint64, # ULONGLONG
pPublishOptions: ptr PEERDIST_PUBLICATION_OPTIONS, # PEERDIST_PUBLICATION_OPTIONS* optional
hCompletionPort: pointer, # HANDLE optional
ulCompletionKey: uint, # UINT_PTR optional
phStream: ptr int # INT_PTR* out
): uint32 {.importc: "PeerDistServerPublishStream", stdcall, dynlib: "PeerDist.dll".}pragma(lib, "peerdist");
extern(Windows)
uint PeerDistServerPublishStream(
ptrdiff_t hPeerDist, // INT_PTR
uint cbContentIdentifier, // DWORD
ubyte* pContentIdentifier, // BYTE*
ulong cbContentLength, // ULONGLONG
PEERDIST_PUBLICATION_OPTIONS* pPublishOptions, // PEERDIST_PUBLICATION_OPTIONS* optional
void* hCompletionPort, // HANDLE optional
size_t ulCompletionKey, // UINT_PTR optional
ptrdiff_t* phStream // INT_PTR* out
);ccall((:PeerDistServerPublishStream, "PeerDist.dll"), stdcall, UInt32,
(Int, UInt32, Ptr{UInt8}, UInt64, Ptr{PEERDIST_PUBLICATION_OPTIONS}, Ptr{Cvoid}, Csize_t, Ptr{Int}),
hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream)
# hPeerDist : INT_PTR -> Int
# cbContentIdentifier : DWORD -> UInt32
# pContentIdentifier : BYTE* -> Ptr{UInt8}
# cbContentLength : ULONGLONG -> UInt64
# pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> Ptr{PEERDIST_PUBLICATION_OPTIONS}
# hCompletionPort : HANDLE optional -> Ptr{Cvoid}
# ulCompletionKey : UINT_PTR optional -> Csize_t
# phStream : INT_PTR* out -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PeerDistServerPublishStream(
intptr_t hPeerDist,
uint32_t cbContentIdentifier,
uint8_t* pContentIdentifier,
uint64_t cbContentLength,
void* pPublishOptions,
void* hCompletionPort,
uintptr_t ulCompletionKey,
intptr_t* phStream);
]]
local peerdist = ffi.load("peerdist")
-- peerdist.PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream)
-- hPeerDist : INT_PTR
-- cbContentIdentifier : DWORD
-- pContentIdentifier : BYTE*
-- cbContentLength : ULONGLONG
-- pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional
-- hCompletionPort : HANDLE optional
-- ulCompletionKey : UINT_PTR optional
-- phStream : INT_PTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('PeerDist.dll');
const PeerDistServerPublishStream = lib.func('__stdcall', 'PeerDistServerPublishStream', 'uint32_t', ['intptr_t', 'uint32_t', 'uint8_t *', 'uint64_t', 'void *', 'void *', 'uintptr_t', 'intptr_t *']);
// PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream)
// hPeerDist : INT_PTR -> 'intptr_t'
// cbContentIdentifier : DWORD -> 'uint32_t'
// pContentIdentifier : BYTE* -> 'uint8_t *'
// cbContentLength : ULONGLONG -> 'uint64_t'
// pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> 'void *'
// hCompletionPort : HANDLE optional -> 'void *'
// ulCompletionKey : UINT_PTR optional -> 'uintptr_t'
// phStream : INT_PTR* out -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("PeerDist.dll", {
PeerDistServerPublishStream: { parameters: ["isize", "u32", "pointer", "u64", "pointer", "pointer", "usize", "pointer"], result: "u32" },
});
// lib.symbols.PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream)
// hPeerDist : INT_PTR -> "isize"
// cbContentIdentifier : DWORD -> "u32"
// pContentIdentifier : BYTE* -> "pointer"
// cbContentLength : ULONGLONG -> "u64"
// pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> "pointer"
// hCompletionPort : HANDLE optional -> "pointer"
// ulCompletionKey : UINT_PTR optional -> "usize"
// phStream : INT_PTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PeerDistServerPublishStream(
intptr_t hPeerDist,
uint32_t cbContentIdentifier,
uint8_t* pContentIdentifier,
uint64_t cbContentLength,
void* pPublishOptions,
void* hCompletionPort,
size_t ulCompletionKey,
intptr_t* phStream);
C, "PeerDist.dll");
// $ffi->PeerDistServerPublishStream(hPeerDist, cbContentIdentifier, pContentIdentifier, cbContentLength, pPublishOptions, hCompletionPort, ulCompletionKey, phStream);
// hPeerDist : INT_PTR
// cbContentIdentifier : DWORD
// pContentIdentifier : BYTE*
// cbContentLength : ULONGLONG
// pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional
// hCompletionPort : HANDLE optional
// ulCompletionKey : UINT_PTR optional
// phStream : INT_PTR* 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 Peerdist extends StdCallLibrary {
Peerdist INSTANCE = Native.load("peerdist", Peerdist.class);
int PeerDistServerPublishStream(
long hPeerDist, // INT_PTR
int cbContentIdentifier, // DWORD
byte[] pContentIdentifier, // BYTE*
long cbContentLength, // ULONGLONG
Pointer pPublishOptions, // PEERDIST_PUBLICATION_OPTIONS* optional
Pointer hCompletionPort, // HANDLE optional
long ulCompletionKey, // UINT_PTR optional
LongByReference phStream // INT_PTR* out
);
}@[Link("peerdist")]
lib LibPeerDist
fun PeerDistServerPublishStream = PeerDistServerPublishStream(
hPeerDist : LibC::SSizeT, # INT_PTR
cbContentIdentifier : UInt32, # DWORD
pContentIdentifier : UInt8*, # BYTE*
cbContentLength : UInt64, # ULONGLONG
pPublishOptions : PEERDIST_PUBLICATION_OPTIONS*, # PEERDIST_PUBLICATION_OPTIONS* optional
hCompletionPort : Void*, # HANDLE optional
ulCompletionKey : LibC::SizeT, # UINT_PTR optional
phStream : LibC::SSizeT* # INT_PTR* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PeerDistServerPublishStreamNative = Uint32 Function(IntPtr, Uint32, Pointer<Uint8>, Uint64, Pointer<Void>, Pointer<Void>, UintPtr, Pointer<IntPtr>);
typedef PeerDistServerPublishStreamDart = int Function(int, int, Pointer<Uint8>, int, Pointer<Void>, Pointer<Void>, int, Pointer<IntPtr>);
final PeerDistServerPublishStream = DynamicLibrary.open('PeerDist.dll')
.lookupFunction<PeerDistServerPublishStreamNative, PeerDistServerPublishStreamDart>('PeerDistServerPublishStream');
// hPeerDist : INT_PTR -> IntPtr
// cbContentIdentifier : DWORD -> Uint32
// pContentIdentifier : BYTE* -> Pointer<Uint8>
// cbContentLength : ULONGLONG -> Uint64
// pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> Pointer<Void>
// hCompletionPort : HANDLE optional -> Pointer<Void>
// ulCompletionKey : UINT_PTR optional -> UintPtr
// phStream : INT_PTR* out -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PeerDistServerPublishStream(
hPeerDist: NativeInt; // INT_PTR
cbContentIdentifier: DWORD; // DWORD
pContentIdentifier: Pointer; // BYTE*
cbContentLength: UInt64; // ULONGLONG
pPublishOptions: Pointer; // PEERDIST_PUBLICATION_OPTIONS* optional
hCompletionPort: THandle; // HANDLE optional
ulCompletionKey: NativeUInt; // UINT_PTR optional
phStream: Pointer // INT_PTR* out
): DWORD; stdcall;
external 'PeerDist.dll' name 'PeerDistServerPublishStream';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PeerDistServerPublishStream"
c_PeerDistServerPublishStream :: CIntPtr -> Word32 -> Ptr Word8 -> Word64 -> Ptr () -> Ptr () -> CUIntPtr -> Ptr CIntPtr -> IO Word32
-- hPeerDist : INT_PTR -> CIntPtr
-- cbContentIdentifier : DWORD -> Word32
-- pContentIdentifier : BYTE* -> Ptr Word8
-- cbContentLength : ULONGLONG -> Word64
-- pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> Ptr ()
-- hCompletionPort : HANDLE optional -> Ptr ()
-- ulCompletionKey : UINT_PTR optional -> CUIntPtr
-- phStream : INT_PTR* out -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let peerdistserverpublishstream =
foreign "PeerDistServerPublishStream"
(intptr_t @-> uint32_t @-> (ptr uint8_t) @-> uint64_t @-> (ptr void) @-> (ptr void) @-> size_t @-> (ptr intptr_t) @-> returning uint32_t)
(* hPeerDist : INT_PTR -> intptr_t *)
(* cbContentIdentifier : DWORD -> uint32_t *)
(* pContentIdentifier : BYTE* -> (ptr uint8_t) *)
(* cbContentLength : ULONGLONG -> uint64_t *)
(* pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> (ptr void) *)
(* hCompletionPort : HANDLE optional -> (ptr void) *)
(* ulCompletionKey : UINT_PTR optional -> size_t *)
(* phStream : INT_PTR* out -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library peerdist (t "PeerDist.dll"))
(cffi:use-foreign-library peerdist)
(cffi:defcfun ("PeerDistServerPublishStream" peer-dist-server-publish-stream :convention :stdcall) :uint32
(h-peer-dist :int64) ; INT_PTR
(cb-content-identifier :uint32) ; DWORD
(p-content-identifier :pointer) ; BYTE*
(cb-content-length :uint64) ; ULONGLONG
(p-publish-options :pointer) ; PEERDIST_PUBLICATION_OPTIONS* optional
(h-completion-port :pointer) ; HANDLE optional
(ul-completion-key :uint64) ; UINT_PTR optional
(ph-stream :pointer)) ; INT_PTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PeerDistServerPublishStream = Win32::API::More->new('PeerDist',
'DWORD PeerDistServerPublishStream(LPARAM hPeerDist, DWORD cbContentIdentifier, LPVOID pContentIdentifier, UINT64 cbContentLength, LPVOID pPublishOptions, HANDLE hCompletionPort, WPARAM ulCompletionKey, LPVOID phStream)');
# my $ret = $PeerDistServerPublishStream->Call($hPeerDist, $cbContentIdentifier, $pContentIdentifier, $cbContentLength, $pPublishOptions, $hCompletionPort, $ulCompletionKey, $phStream);
# hPeerDist : INT_PTR -> LPARAM
# cbContentIdentifier : DWORD -> DWORD
# pContentIdentifier : BYTE* -> LPVOID
# cbContentLength : ULONGLONG -> UINT64
# pPublishOptions : PEERDIST_PUBLICATION_OPTIONS* optional -> LPVOID
# hCompletionPort : HANDLE optional -> HANDLE
# ulCompletionKey : UINT_PTR optional -> WPARAM
# phStream : INT_PTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。