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

WTSVirtualChannelOpen

関数
指定セッションの仮想チャネルを開く。
DLLWTSAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

HANDLE WTSVirtualChannelOpen(
    HANDLE hServer,   // optional
    DWORD SessionId,
    LPSTR pVirtualName
);

パラメーター

名前方向
hServerHANDLEoptional
SessionIdDWORDin
pVirtualNameLPSTRin

戻り値の型: HANDLE

各言語での呼び出し定義

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

HANDLE WTSVirtualChannelOpen(
    HANDLE hServer,   // optional
    DWORD SessionId,
    LPSTR pVirtualName
);
[DllImport("WTSAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr WTSVirtualChannelOpen(
    IntPtr hServer,   // HANDLE optional
    uint SessionId,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string pVirtualName   // LPSTR
);
<DllImport("WTSAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSVirtualChannelOpen(
    hServer As IntPtr,   ' HANDLE optional
    SessionId As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> pVirtualName As String   ' LPSTR
) As IntPtr
End Function
' hServer : HANDLE optional
' SessionId : DWORD
' pVirtualName : LPSTR
Declare PtrSafe Function WTSVirtualChannelOpen Lib "wtsapi32" ( _
    ByVal hServer As LongPtr, _
    ByVal SessionId As Long, _
    ByVal pVirtualName As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WTSVirtualChannelOpen = ctypes.windll.wtsapi32.WTSVirtualChannelOpen
WTSVirtualChannelOpen.restype = ctypes.c_void_p
WTSVirtualChannelOpen.argtypes = [
    wintypes.HANDLE,  # hServer : HANDLE optional
    wintypes.DWORD,  # SessionId : DWORD
    wintypes.LPCSTR,  # pVirtualName : LPSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WTSAPI32.dll')
WTSVirtualChannelOpen = Fiddle::Function.new(
  lib['WTSVirtualChannelOpen'],
  [
    Fiddle::TYPE_VOIDP,  # hServer : HANDLE optional
    -Fiddle::TYPE_INT,  # SessionId : DWORD
    Fiddle::TYPE_VOIDP,  # pVirtualName : LPSTR
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "wtsapi32")]
extern "system" {
    fn WTSVirtualChannelOpen(
        hServer: *mut core::ffi::c_void,  // HANDLE optional
        SessionId: u32,  // DWORD
        pVirtualName: *mut u8  // LPSTR
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WTSAPI32.dll", SetLastError = true)]
public static extern IntPtr WTSVirtualChannelOpen(IntPtr hServer, uint SessionId, [MarshalAs(UnmanagedType.LPStr)] string pVirtualName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSVirtualChannelOpen' -Namespace Win32 -PassThru
# $api::WTSVirtualChannelOpen(hServer, SessionId, pVirtualName)
#uselib "WTSAPI32.dll"
#func global WTSVirtualChannelOpen "WTSVirtualChannelOpen" sptr, sptr, sptr
; WTSVirtualChannelOpen hServer, SessionId, pVirtualName   ; 戻り値は stat
; hServer : HANDLE optional -> "sptr"
; SessionId : DWORD -> "sptr"
; pVirtualName : LPSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WTSAPI32.dll"
#cfunc global WTSVirtualChannelOpen "WTSVirtualChannelOpen" sptr, int, str
; res = WTSVirtualChannelOpen(hServer, SessionId, pVirtualName)
; hServer : HANDLE optional -> "sptr"
; SessionId : DWORD -> "int"
; pVirtualName : LPSTR -> "str"
; HANDLE WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
#uselib "WTSAPI32.dll"
#cfunc global WTSVirtualChannelOpen "WTSVirtualChannelOpen" intptr, int, str
; res = WTSVirtualChannelOpen(hServer, SessionId, pVirtualName)
; hServer : HANDLE optional -> "intptr"
; SessionId : DWORD -> "int"
; pVirtualName : LPSTR -> "str"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
	procWTSVirtualChannelOpen = wtsapi32.NewProc("WTSVirtualChannelOpen")
)

// hServer (HANDLE optional), SessionId (DWORD), pVirtualName (LPSTR)
r1, _, err := procWTSVirtualChannelOpen.Call(
	uintptr(hServer),
	uintptr(SessionId),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pVirtualName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function WTSVirtualChannelOpen(
  hServer: THandle;   // HANDLE optional
  SessionId: DWORD;   // DWORD
  pVirtualName: PAnsiChar   // LPSTR
): THandle; stdcall;
  external 'WTSAPI32.dll' name 'WTSVirtualChannelOpen';
result := DllCall("WTSAPI32\WTSVirtualChannelOpen"
    , "Ptr", hServer   ; HANDLE optional
    , "UInt", SessionId   ; DWORD
    , "AStr", pVirtualName   ; LPSTR
    , "Ptr")   ; return: HANDLE
●WTSVirtualChannelOpen(hServer, SessionId, pVirtualName) = DLL("WTSAPI32.dll", "void* WTSVirtualChannelOpen(void*, dword, char*)")
# 呼び出し: WTSVirtualChannelOpen(hServer, SessionId, pVirtualName)
# hServer : HANDLE optional -> "void*"
# SessionId : DWORD -> "dword"
# pVirtualName : LPSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。