ホーム › System.RemoteManagement › WSManCreateSession
WSManCreateSession
関数リモート管理用のWS-Manセッションを作成する。
シグネチャ
// WsmSvc.dll
#include <windows.h>
DWORD WSManCreateSession(
WSMAN_API_HANDLE apiHandle,
LPCWSTR connection, // optional
DWORD flags,
WSMAN_AUTHENTICATION_CREDENTIALS* serverAuthenticationCredentials, // optional
WSMAN_PROXY_INFO* proxyInfo, // optional
WSMAN_SESSION_HANDLE* session
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| apiHandle | WSMAN_API_HANDLE | in | WSManInitialize で取得したAPIハンドル。 |
| connection | LPCWSTR | inoptional | 接続先サーバーのURLまたは名前を示す文字列。NULL でローカル接続となる。 |
| flags | DWORD | in | セッション作成動作を制御するフラグ。 |
| serverAuthenticationCredentials | WSMAN_AUTHENTICATION_CREDENTIALS* | inoptional | サーバー認証に使用する資格情報構造体へのポインター。NULL 可。 |
| proxyInfo | WSMAN_PROXY_INFO* | inoptional | プロキシ設定を指定する構造体へのポインター。NULL 可。 |
| session | WSMAN_SESSION_HANDLE* | out | 作成されたセッションハンドルを受け取るポインター。 |
戻り値の型: DWORD
各言語での呼び出し定義
// WsmSvc.dll
#include <windows.h>
DWORD WSManCreateSession(
WSMAN_API_HANDLE apiHandle,
LPCWSTR connection, // optional
DWORD flags,
WSMAN_AUTHENTICATION_CREDENTIALS* serverAuthenticationCredentials, // optional
WSMAN_PROXY_INFO* proxyInfo, // optional
WSMAN_SESSION_HANDLE* session
);[DllImport("WsmSvc.dll", ExactSpelling = true)]
static extern uint WSManCreateSession(
IntPtr apiHandle, // WSMAN_API_HANDLE
[MarshalAs(UnmanagedType.LPWStr)] string connection, // LPCWSTR optional
uint flags, // DWORD
IntPtr serverAuthenticationCredentials, // WSMAN_AUTHENTICATION_CREDENTIALS* optional
IntPtr proxyInfo, // WSMAN_PROXY_INFO* optional
out IntPtr session // WSMAN_SESSION_HANDLE* out
);<DllImport("WsmSvc.dll", ExactSpelling:=True)>
Public Shared Function WSManCreateSession(
apiHandle As IntPtr, ' WSMAN_API_HANDLE
<MarshalAs(UnmanagedType.LPWStr)> connection As String, ' LPCWSTR optional
flags As UInteger, ' DWORD
serverAuthenticationCredentials As IntPtr, ' WSMAN_AUTHENTICATION_CREDENTIALS* optional
proxyInfo As IntPtr, ' WSMAN_PROXY_INFO* optional
<Out> ByRef session As IntPtr ' WSMAN_SESSION_HANDLE* out
) As UInteger
End Function' apiHandle : WSMAN_API_HANDLE
' connection : LPCWSTR optional
' flags : DWORD
' serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional
' proxyInfo : WSMAN_PROXY_INFO* optional
' session : WSMAN_SESSION_HANDLE* out
Declare PtrSafe Function WSManCreateSession Lib "wsmsvc" ( _
ByVal apiHandle As LongPtr, _
ByVal connection As LongPtr, _
ByVal flags As Long, _
ByVal serverAuthenticationCredentials As LongPtr, _
ByVal proxyInfo As LongPtr, _
ByRef session As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSManCreateSession = ctypes.windll.wsmsvc.WSManCreateSession
WSManCreateSession.restype = wintypes.DWORD
WSManCreateSession.argtypes = [
ctypes.c_ssize_t, # apiHandle : WSMAN_API_HANDLE
wintypes.LPCWSTR, # connection : LPCWSTR optional
wintypes.DWORD, # flags : DWORD
ctypes.c_void_p, # serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional
ctypes.c_void_p, # proxyInfo : WSMAN_PROXY_INFO* optional
ctypes.c_void_p, # session : WSMAN_SESSION_HANDLE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WsmSvc.dll')
WSManCreateSession = Fiddle::Function.new(
lib['WSManCreateSession'],
[
Fiddle::TYPE_INTPTR_T, # apiHandle : WSMAN_API_HANDLE
Fiddle::TYPE_VOIDP, # connection : LPCWSTR optional
-Fiddle::TYPE_INT, # flags : DWORD
Fiddle::TYPE_VOIDP, # serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional
Fiddle::TYPE_VOIDP, # proxyInfo : WSMAN_PROXY_INFO* optional
Fiddle::TYPE_VOIDP, # session : WSMAN_SESSION_HANDLE* out
],
-Fiddle::TYPE_INT)#[link(name = "wsmsvc")]
extern "system" {
fn WSManCreateSession(
apiHandle: isize, // WSMAN_API_HANDLE
connection: *const u16, // LPCWSTR optional
flags: u32, // DWORD
serverAuthenticationCredentials: *mut WSMAN_AUTHENTICATION_CREDENTIALS, // WSMAN_AUTHENTICATION_CREDENTIALS* optional
proxyInfo: *mut WSMAN_PROXY_INFO, // WSMAN_PROXY_INFO* optional
session: *mut isize // WSMAN_SESSION_HANDLE* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WsmSvc.dll")]
public static extern uint WSManCreateSession(IntPtr apiHandle, [MarshalAs(UnmanagedType.LPWStr)] string connection, uint flags, IntPtr serverAuthenticationCredentials, IntPtr proxyInfo, out IntPtr session);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WsmSvc_WSManCreateSession' -Namespace Win32 -PassThru
# $api::WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session)#uselib "WsmSvc.dll"
#func global WSManCreateSession "WSManCreateSession" sptr, sptr, sptr, sptr, sptr, sptr
; WSManCreateSession apiHandle, connection, flags, varptr(serverAuthenticationCredentials), varptr(proxyInfo), varptr(session) ; 戻り値は stat
; apiHandle : WSMAN_API_HANDLE -> "sptr"
; connection : LPCWSTR optional -> "sptr"
; flags : DWORD -> "sptr"
; serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> "sptr"
; proxyInfo : WSMAN_PROXY_INFO* optional -> "sptr"
; session : WSMAN_SESSION_HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WsmSvc.dll" #cfunc global WSManCreateSession "WSManCreateSession" sptr, wstr, int, var, var, var ; res = WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session) ; apiHandle : WSMAN_API_HANDLE -> "sptr" ; connection : LPCWSTR optional -> "wstr" ; flags : DWORD -> "int" ; serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> "var" ; proxyInfo : WSMAN_PROXY_INFO* optional -> "var" ; session : WSMAN_SESSION_HANDLE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WsmSvc.dll" #cfunc global WSManCreateSession "WSManCreateSession" sptr, wstr, int, sptr, sptr, sptr ; res = WSManCreateSession(apiHandle, connection, flags, varptr(serverAuthenticationCredentials), varptr(proxyInfo), varptr(session)) ; apiHandle : WSMAN_API_HANDLE -> "sptr" ; connection : LPCWSTR optional -> "wstr" ; flags : DWORD -> "int" ; serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> "sptr" ; proxyInfo : WSMAN_PROXY_INFO* optional -> "sptr" ; session : WSMAN_SESSION_HANDLE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD WSManCreateSession(WSMAN_API_HANDLE apiHandle, LPCWSTR connection, DWORD flags, WSMAN_AUTHENTICATION_CREDENTIALS* serverAuthenticationCredentials, WSMAN_PROXY_INFO* proxyInfo, WSMAN_SESSION_HANDLE* session) #uselib "WsmSvc.dll" #cfunc global WSManCreateSession "WSManCreateSession" intptr, wstr, int, var, var, var ; res = WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session) ; apiHandle : WSMAN_API_HANDLE -> "intptr" ; connection : LPCWSTR optional -> "wstr" ; flags : DWORD -> "int" ; serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> "var" ; proxyInfo : WSMAN_PROXY_INFO* optional -> "var" ; session : WSMAN_SESSION_HANDLE* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD WSManCreateSession(WSMAN_API_HANDLE apiHandle, LPCWSTR connection, DWORD flags, WSMAN_AUTHENTICATION_CREDENTIALS* serverAuthenticationCredentials, WSMAN_PROXY_INFO* proxyInfo, WSMAN_SESSION_HANDLE* session) #uselib "WsmSvc.dll" #cfunc global WSManCreateSession "WSManCreateSession" intptr, wstr, int, intptr, intptr, intptr ; res = WSManCreateSession(apiHandle, connection, flags, varptr(serverAuthenticationCredentials), varptr(proxyInfo), varptr(session)) ; apiHandle : WSMAN_API_HANDLE -> "intptr" ; connection : LPCWSTR optional -> "wstr" ; flags : DWORD -> "int" ; serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> "intptr" ; proxyInfo : WSMAN_PROXY_INFO* optional -> "intptr" ; session : WSMAN_SESSION_HANDLE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wsmsvc = windows.NewLazySystemDLL("WsmSvc.dll")
procWSManCreateSession = wsmsvc.NewProc("WSManCreateSession")
)
// apiHandle (WSMAN_API_HANDLE), connection (LPCWSTR optional), flags (DWORD), serverAuthenticationCredentials (WSMAN_AUTHENTICATION_CREDENTIALS* optional), proxyInfo (WSMAN_PROXY_INFO* optional), session (WSMAN_SESSION_HANDLE* out)
r1, _, err := procWSManCreateSession.Call(
uintptr(apiHandle),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(connection))),
uintptr(flags),
uintptr(serverAuthenticationCredentials),
uintptr(proxyInfo),
uintptr(session),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction WSManCreateSession(
apiHandle: NativeInt; // WSMAN_API_HANDLE
connection: PWideChar; // LPCWSTR optional
flags: DWORD; // DWORD
serverAuthenticationCredentials: Pointer; // WSMAN_AUTHENTICATION_CREDENTIALS* optional
proxyInfo: Pointer; // WSMAN_PROXY_INFO* optional
session: Pointer // WSMAN_SESSION_HANDLE* out
): DWORD; stdcall;
external 'WsmSvc.dll' name 'WSManCreateSession';result := DllCall("WsmSvc\WSManCreateSession"
, "Ptr", apiHandle ; WSMAN_API_HANDLE
, "WStr", connection ; LPCWSTR optional
, "UInt", flags ; DWORD
, "Ptr", serverAuthenticationCredentials ; WSMAN_AUTHENTICATION_CREDENTIALS* optional
, "Ptr", proxyInfo ; WSMAN_PROXY_INFO* optional
, "Ptr", session ; WSMAN_SESSION_HANDLE* out
, "UInt") ; return: DWORD●WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session) = DLL("WsmSvc.dll", "dword WSManCreateSession(int, char*, dword, void*, void*, void*)")
# 呼び出し: WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session)
# apiHandle : WSMAN_API_HANDLE -> "int"
# connection : LPCWSTR optional -> "char*"
# flags : DWORD -> "dword"
# serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> "void*"
# proxyInfo : WSMAN_PROXY_INFO* optional -> "void*"
# session : WSMAN_SESSION_HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "wsmsvc" fn WSManCreateSession(
apiHandle: isize, // WSMAN_API_HANDLE
connection: [*c]const u16, // LPCWSTR optional
flags: u32, // DWORD
serverAuthenticationCredentials: [*c]WSMAN_AUTHENTICATION_CREDENTIALS, // WSMAN_AUTHENTICATION_CREDENTIALS* optional
proxyInfo: [*c]WSMAN_PROXY_INFO, // WSMAN_PROXY_INFO* optional
session: [*c]isize // WSMAN_SESSION_HANDLE* out
) callconv(std.os.windows.WINAPI) u32;proc WSManCreateSession(
apiHandle: int, # WSMAN_API_HANDLE
connection: WideCString, # LPCWSTR optional
flags: uint32, # DWORD
serverAuthenticationCredentials: ptr WSMAN_AUTHENTICATION_CREDENTIALS, # WSMAN_AUTHENTICATION_CREDENTIALS* optional
proxyInfo: ptr WSMAN_PROXY_INFO, # WSMAN_PROXY_INFO* optional
session: ptr int # WSMAN_SESSION_HANDLE* out
): uint32 {.importc: "WSManCreateSession", stdcall, dynlib: "WsmSvc.dll".}pragma(lib, "wsmsvc");
extern(Windows)
uint WSManCreateSession(
ptrdiff_t apiHandle, // WSMAN_API_HANDLE
const(wchar)* connection, // LPCWSTR optional
uint flags, // DWORD
WSMAN_AUTHENTICATION_CREDENTIALS* serverAuthenticationCredentials, // WSMAN_AUTHENTICATION_CREDENTIALS* optional
WSMAN_PROXY_INFO* proxyInfo, // WSMAN_PROXY_INFO* optional
ptrdiff_t* session // WSMAN_SESSION_HANDLE* out
);ccall((:WSManCreateSession, "WsmSvc.dll"), stdcall, UInt32,
(Int, Cwstring, UInt32, Ptr{WSMAN_AUTHENTICATION_CREDENTIALS}, Ptr{WSMAN_PROXY_INFO}, Ptr{Int}),
apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session)
# apiHandle : WSMAN_API_HANDLE -> Int
# connection : LPCWSTR optional -> Cwstring
# flags : DWORD -> UInt32
# serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> Ptr{WSMAN_AUTHENTICATION_CREDENTIALS}
# proxyInfo : WSMAN_PROXY_INFO* optional -> Ptr{WSMAN_PROXY_INFO}
# session : WSMAN_SESSION_HANDLE* out -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t WSManCreateSession(
intptr_t apiHandle,
const uint16_t* connection,
uint32_t flags,
void* serverAuthenticationCredentials,
void* proxyInfo,
intptr_t* session);
]]
local wsmsvc = ffi.load("wsmsvc")
-- wsmsvc.WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session)
-- apiHandle : WSMAN_API_HANDLE
-- connection : LPCWSTR optional
-- flags : DWORD
-- serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional
-- proxyInfo : WSMAN_PROXY_INFO* optional
-- session : WSMAN_SESSION_HANDLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WsmSvc.dll');
const WSManCreateSession = lib.func('__stdcall', 'WSManCreateSession', 'uint32_t', ['intptr_t', 'str16', 'uint32_t', 'void *', 'void *', 'intptr_t *']);
// WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session)
// apiHandle : WSMAN_API_HANDLE -> 'intptr_t'
// connection : LPCWSTR optional -> 'str16'
// flags : DWORD -> 'uint32_t'
// serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> 'void *'
// proxyInfo : WSMAN_PROXY_INFO* optional -> 'void *'
// session : WSMAN_SESSION_HANDLE* out -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WsmSvc.dll", {
WSManCreateSession: { parameters: ["isize", "buffer", "u32", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session)
// apiHandle : WSMAN_API_HANDLE -> "isize"
// connection : LPCWSTR optional -> "buffer"
// flags : DWORD -> "u32"
// serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> "pointer"
// proxyInfo : WSMAN_PROXY_INFO* optional -> "pointer"
// session : WSMAN_SESSION_HANDLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t WSManCreateSession(
intptr_t apiHandle,
const uint16_t* connection,
uint32_t flags,
void* serverAuthenticationCredentials,
void* proxyInfo,
intptr_t* session);
C, "WsmSvc.dll");
// $ffi->WSManCreateSession(apiHandle, connection, flags, serverAuthenticationCredentials, proxyInfo, session);
// apiHandle : WSMAN_API_HANDLE
// connection : LPCWSTR optional
// flags : DWORD
// serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional
// proxyInfo : WSMAN_PROXY_INFO* optional
// session : WSMAN_SESSION_HANDLE* 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 Wsmsvc extends StdCallLibrary {
Wsmsvc INSTANCE = Native.load("wsmsvc", Wsmsvc.class);
int WSManCreateSession(
long apiHandle, // WSMAN_API_HANDLE
WString connection, // LPCWSTR optional
int flags, // DWORD
Pointer serverAuthenticationCredentials, // WSMAN_AUTHENTICATION_CREDENTIALS* optional
Pointer proxyInfo, // WSMAN_PROXY_INFO* optional
LongByReference session // WSMAN_SESSION_HANDLE* out
);
}@[Link("wsmsvc")]
lib LibWsmSvc
fun WSManCreateSession = WSManCreateSession(
apiHandle : LibC::SSizeT, # WSMAN_API_HANDLE
connection : UInt16*, # LPCWSTR optional
flags : UInt32, # DWORD
serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS*, # WSMAN_AUTHENTICATION_CREDENTIALS* optional
proxyInfo : WSMAN_PROXY_INFO*, # WSMAN_PROXY_INFO* optional
session : LibC::SSizeT* # WSMAN_SESSION_HANDLE* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WSManCreateSessionNative = Uint32 Function(IntPtr, Pointer<Utf16>, Uint32, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
typedef WSManCreateSessionDart = int Function(int, Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
final WSManCreateSession = DynamicLibrary.open('WsmSvc.dll')
.lookupFunction<WSManCreateSessionNative, WSManCreateSessionDart>('WSManCreateSession');
// apiHandle : WSMAN_API_HANDLE -> IntPtr
// connection : LPCWSTR optional -> Pointer<Utf16>
// flags : DWORD -> Uint32
// serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> Pointer<Void>
// proxyInfo : WSMAN_PROXY_INFO* optional -> Pointer<Void>
// session : WSMAN_SESSION_HANDLE* out -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WSManCreateSession(
apiHandle: NativeInt; // WSMAN_API_HANDLE
connection: PWideChar; // LPCWSTR optional
flags: DWORD; // DWORD
serverAuthenticationCredentials: Pointer; // WSMAN_AUTHENTICATION_CREDENTIALS* optional
proxyInfo: Pointer; // WSMAN_PROXY_INFO* optional
session: Pointer // WSMAN_SESSION_HANDLE* out
): DWORD; stdcall;
external 'WsmSvc.dll' name 'WSManCreateSession';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WSManCreateSession"
c_WSManCreateSession :: CIntPtr -> CWString -> Word32 -> Ptr () -> Ptr () -> Ptr CIntPtr -> IO Word32
-- apiHandle : WSMAN_API_HANDLE -> CIntPtr
-- connection : LPCWSTR optional -> CWString
-- flags : DWORD -> Word32
-- serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> Ptr ()
-- proxyInfo : WSMAN_PROXY_INFO* optional -> Ptr ()
-- session : WSMAN_SESSION_HANDLE* out -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wsmancreatesession =
foreign "WSManCreateSession"
(intptr_t @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr intptr_t) @-> returning uint32_t)
(* apiHandle : WSMAN_API_HANDLE -> intptr_t *)
(* connection : LPCWSTR optional -> (ptr uint16_t) *)
(* flags : DWORD -> uint32_t *)
(* serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> (ptr void) *)
(* proxyInfo : WSMAN_PROXY_INFO* optional -> (ptr void) *)
(* session : WSMAN_SESSION_HANDLE* out -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wsmsvc (t "WsmSvc.dll"))
(cffi:use-foreign-library wsmsvc)
(cffi:defcfun ("WSManCreateSession" wsman-create-session :convention :stdcall) :uint32
(api-handle :int64) ; WSMAN_API_HANDLE
(connection (:string :encoding :utf-16le)) ; LPCWSTR optional
(flags :uint32) ; DWORD
(server-authentication-credentials :pointer) ; WSMAN_AUTHENTICATION_CREDENTIALS* optional
(proxy-info :pointer) ; WSMAN_PROXY_INFO* optional
(session :pointer)) ; WSMAN_SESSION_HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WSManCreateSession = Win32::API::More->new('WsmSvc',
'DWORD WSManCreateSession(LPARAM apiHandle, LPCWSTR connection, DWORD flags, LPVOID serverAuthenticationCredentials, LPVOID proxyInfo, LPVOID session)');
# my $ret = $WSManCreateSession->Call($apiHandle, $connection, $flags, $serverAuthenticationCredentials, $proxyInfo, $session);
# apiHandle : WSMAN_API_HANDLE -> LPARAM
# connection : LPCWSTR optional -> LPCWSTR
# flags : DWORD -> DWORD
# serverAuthenticationCredentials : WSMAN_AUTHENTICATION_CREDENTIALS* optional -> LPVOID
# proxyInfo : WSMAN_PROXY_INFO* optional -> LPVOID
# session : WSMAN_SESSION_HANDLE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。