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

GetNamedPipeServerSessionId

関数
名前付きパイプサーバーのセッションIDを取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL GetNamedPipeServerSessionId(
    HANDLE Pipe,
    DWORD* ServerSessionId
);

パラメーター

名前方向
PipeHANDLEin
ServerSessionIdDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetNamedPipeServerSessionId(
    HANDLE Pipe,
    DWORD* ServerSessionId
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetNamedPipeServerSessionId(
    IntPtr Pipe,   // HANDLE
    out uint ServerSessionId   // DWORD* out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetNamedPipeServerSessionId(
    Pipe As IntPtr,   ' HANDLE
    <Out> ByRef ServerSessionId As UInteger   ' DWORD* out
) As Boolean
End Function
' Pipe : HANDLE
' ServerSessionId : DWORD* out
Declare PtrSafe Function GetNamedPipeServerSessionId Lib "kernel32" ( _
    ByVal Pipe As LongPtr, _
    ByRef ServerSessionId As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetNamedPipeServerSessionId = ctypes.windll.kernel32.GetNamedPipeServerSessionId
GetNamedPipeServerSessionId.restype = wintypes.BOOL
GetNamedPipeServerSessionId.argtypes = [
    wintypes.HANDLE,  # Pipe : HANDLE
    ctypes.POINTER(wintypes.DWORD),  # ServerSessionId : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetNamedPipeServerSessionId = kernel32.NewProc("GetNamedPipeServerSessionId")
)

// Pipe (HANDLE), ServerSessionId (DWORD* out)
r1, _, err := procGetNamedPipeServerSessionId.Call(
	uintptr(Pipe),
	uintptr(ServerSessionId),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetNamedPipeServerSessionId(
  Pipe: THandle;   // HANDLE
  ServerSessionId: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'GetNamedPipeServerSessionId';
result := DllCall("KERNEL32\GetNamedPipeServerSessionId"
    , "Ptr", Pipe   ; HANDLE
    , "Ptr", ServerSessionId   ; DWORD* out
    , "Int")   ; return: BOOL
●GetNamedPipeServerSessionId(Pipe, ServerSessionId) = DLL("KERNEL32.dll", "bool GetNamedPipeServerSessionId(void*, void*)")
# 呼び出し: GetNamedPipeServerSessionId(Pipe, ServerSessionId)
# Pipe : HANDLE -> "void*"
# ServerSessionId : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。