ホーム › Storage.IscsiDisc › AddIScsiConnectionW
AddIScsiConnectionW
関数既存のiSCSIセッションに新しい接続を追加する。
シグネチャ
// ISCSIDSC.dll (Unicode / -W)
#include <windows.h>
DWORD AddIScsiConnectionW(
ISCSI_UNIQUE_SESSION_ID* UniqueSessionId,
void* Reserved,
DWORD InitiatorPortNumber,
ISCSI_TARGET_PORTALW* TargetPortal,
ULONGLONG SecurityFlags,
ISCSI_LOGIN_OPTIONS* LoginOptions,
DWORD KeySize,
LPSTR Key, // optional
ISCSI_UNIQUE_SESSION_ID* ConnectionId
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| UniqueSessionId | ISCSI_UNIQUE_SESSION_ID* | inout | 接続を追加する対象セッションを識別するISCSI_UNIQUE_SESSION_IDへのポインタ。 |
| Reserved | void* | inout | 予約済み。NULLを指定する必要がある。 |
| InitiatorPortNumber | DWORD | in | 使用するイニシエーターのポート番号を指定する。 |
| TargetPortal | ISCSI_TARGET_PORTALW* | inout | 接続先ターゲットポータルを指定するISCSI_TARGET_PORTALWへのポインタ。 |
| SecurityFlags | ULONGLONG | in | IPsecなどのセキュリティ動作を制御するフラグ。 |
| LoginOptions | ISCSI_LOGIN_OPTIONS* | inout | 認証方式などのログインオプションISCSI_LOGIN_OPTIONSへのポインタ。 |
| KeySize | DWORD | in | Keyが指すCHAP共有シークレットのサイズをバイト単位で指定する。 |
| Key | LPSTR | inoptional | CHAP認証に用いる共有シークレットキーを指す。NULL可。 |
| ConnectionId | ISCSI_UNIQUE_SESSION_ID* | inout | 新規作成された接続を識別するIDを受け取るポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// ISCSIDSC.dll (Unicode / -W)
#include <windows.h>
DWORD AddIScsiConnectionW(
ISCSI_UNIQUE_SESSION_ID* UniqueSessionId,
void* Reserved,
DWORD InitiatorPortNumber,
ISCSI_TARGET_PORTALW* TargetPortal,
ULONGLONG SecurityFlags,
ISCSI_LOGIN_OPTIONS* LoginOptions,
DWORD KeySize,
LPSTR Key, // optional
ISCSI_UNIQUE_SESSION_ID* ConnectionId
);[DllImport("ISCSIDSC.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint AddIScsiConnectionW(
IntPtr UniqueSessionId, // ISCSI_UNIQUE_SESSION_ID* in/out
IntPtr Reserved, // void* in/out
uint InitiatorPortNumber, // DWORD
IntPtr TargetPortal, // ISCSI_TARGET_PORTALW* in/out
ulong SecurityFlags, // ULONGLONG
IntPtr LoginOptions, // ISCSI_LOGIN_OPTIONS* in/out
uint KeySize, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string Key, // LPSTR optional
IntPtr ConnectionId // ISCSI_UNIQUE_SESSION_ID* in/out
);<DllImport("ISCSIDSC.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function AddIScsiConnectionW(
UniqueSessionId As IntPtr, ' ISCSI_UNIQUE_SESSION_ID* in/out
Reserved As IntPtr, ' void* in/out
InitiatorPortNumber As UInteger, ' DWORD
TargetPortal As IntPtr, ' ISCSI_TARGET_PORTALW* in/out
SecurityFlags As ULong, ' ULONGLONG
LoginOptions As IntPtr, ' ISCSI_LOGIN_OPTIONS* in/out
KeySize As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> Key As String, ' LPSTR optional
ConnectionId As IntPtr ' ISCSI_UNIQUE_SESSION_ID* in/out
) As UInteger
End Function' UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out
' Reserved : void* in/out
' InitiatorPortNumber : DWORD
' TargetPortal : ISCSI_TARGET_PORTALW* in/out
' SecurityFlags : ULONGLONG
' LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
' KeySize : DWORD
' Key : LPSTR optional
' ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out
Declare PtrSafe Function AddIScsiConnectionW Lib "iscsidsc" ( _
ByVal UniqueSessionId As LongPtr, _
ByVal Reserved As LongPtr, _
ByVal InitiatorPortNumber As Long, _
ByVal TargetPortal As LongPtr, _
ByVal SecurityFlags As LongLong, _
ByVal LoginOptions As LongPtr, _
ByVal KeySize As Long, _
ByVal Key As String, _
ByVal ConnectionId As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
AddIScsiConnectionW = ctypes.windll.iscsidsc.AddIScsiConnectionW
AddIScsiConnectionW.restype = wintypes.DWORD
AddIScsiConnectionW.argtypes = [
ctypes.c_void_p, # UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out
ctypes.POINTER(None), # Reserved : void* in/out
wintypes.DWORD, # InitiatorPortNumber : DWORD
ctypes.c_void_p, # TargetPortal : ISCSI_TARGET_PORTALW* in/out
ctypes.c_ulonglong, # SecurityFlags : ULONGLONG
ctypes.c_void_p, # LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
wintypes.DWORD, # KeySize : DWORD
wintypes.LPCSTR, # Key : LPSTR optional
ctypes.c_void_p, # ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ISCSIDSC.dll')
AddIScsiConnectionW = Fiddle::Function.new(
lib['AddIScsiConnectionW'],
[
Fiddle::TYPE_VOIDP, # UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out
Fiddle::TYPE_VOIDP, # Reserved : void* in/out
-Fiddle::TYPE_INT, # InitiatorPortNumber : DWORD
Fiddle::TYPE_VOIDP, # TargetPortal : ISCSI_TARGET_PORTALW* in/out
-Fiddle::TYPE_LONG_LONG, # SecurityFlags : ULONGLONG
Fiddle::TYPE_VOIDP, # LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
-Fiddle::TYPE_INT, # KeySize : DWORD
Fiddle::TYPE_VOIDP, # Key : LPSTR optional
Fiddle::TYPE_VOIDP, # ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "iscsidsc")]
extern "system" {
fn AddIScsiConnectionW(
UniqueSessionId: *mut ISCSI_UNIQUE_SESSION_ID, // ISCSI_UNIQUE_SESSION_ID* in/out
Reserved: *mut (), // void* in/out
InitiatorPortNumber: u32, // DWORD
TargetPortal: *mut ISCSI_TARGET_PORTALW, // ISCSI_TARGET_PORTALW* in/out
SecurityFlags: u64, // ULONGLONG
LoginOptions: *mut ISCSI_LOGIN_OPTIONS, // ISCSI_LOGIN_OPTIONS* in/out
KeySize: u32, // DWORD
Key: *mut u8, // LPSTR optional
ConnectionId: *mut ISCSI_UNIQUE_SESSION_ID // ISCSI_UNIQUE_SESSION_ID* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ISCSIDSC.dll", CharSet = CharSet.Unicode)]
public static extern uint AddIScsiConnectionW(IntPtr UniqueSessionId, IntPtr Reserved, uint InitiatorPortNumber, IntPtr TargetPortal, ulong SecurityFlags, IntPtr LoginOptions, uint KeySize, [MarshalAs(UnmanagedType.LPStr)] string Key, IntPtr ConnectionId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ISCSIDSC_AddIScsiConnectionW' -Namespace Win32 -PassThru
# $api::AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId)#uselib "ISCSIDSC.dll"
#func global AddIScsiConnectionW "AddIScsiConnectionW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; AddIScsiConnectionW varptr(UniqueSessionId), Reserved, InitiatorPortNumber, varptr(TargetPortal), SecurityFlags, varptr(LoginOptions), KeySize, Key, varptr(ConnectionId) ; 戻り値は stat
; UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "wptr"
; Reserved : void* in/out -> "wptr"
; InitiatorPortNumber : DWORD -> "wptr"
; TargetPortal : ISCSI_TARGET_PORTALW* in/out -> "wptr"
; SecurityFlags : ULONGLONG -> "wptr"
; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "wptr"
; KeySize : DWORD -> "wptr"
; Key : LPSTR optional -> "wptr"
; ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "wptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ISCSIDSC.dll" #cfunc global AddIScsiConnectionW "AddIScsiConnectionW" var, sptr, int, var, int64, var, int, str, var ; res = AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId) ; UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "var" ; Reserved : void* in/out -> "sptr" ; InitiatorPortNumber : DWORD -> "int" ; TargetPortal : ISCSI_TARGET_PORTALW* in/out -> "var" ; SecurityFlags : ULONGLONG -> "int64" ; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "var" ; KeySize : DWORD -> "int" ; Key : LPSTR optional -> "str" ; ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。#uselib "ISCSIDSC.dll" #cfunc global AddIScsiConnectionW "AddIScsiConnectionW" sptr, sptr, int, sptr, int64, sptr, int, str, sptr ; res = AddIScsiConnectionW(varptr(UniqueSessionId), Reserved, InitiatorPortNumber, varptr(TargetPortal), SecurityFlags, varptr(LoginOptions), KeySize, Key, varptr(ConnectionId)) ; UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "sptr" ; Reserved : void* in/out -> "sptr" ; InitiatorPortNumber : DWORD -> "int" ; TargetPortal : ISCSI_TARGET_PORTALW* in/out -> "sptr" ; SecurityFlags : ULONGLONG -> "int64" ; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "sptr" ; KeySize : DWORD -> "int" ; Key : LPSTR optional -> "str" ; ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。 ; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; DWORD AddIScsiConnectionW(ISCSI_UNIQUE_SESSION_ID* UniqueSessionId, void* Reserved, DWORD InitiatorPortNumber, ISCSI_TARGET_PORTALW* TargetPortal, ULONGLONG SecurityFlags, ISCSI_LOGIN_OPTIONS* LoginOptions, DWORD KeySize, LPSTR Key, ISCSI_UNIQUE_SESSION_ID* ConnectionId) #uselib "ISCSIDSC.dll" #cfunc global AddIScsiConnectionW "AddIScsiConnectionW" var, intptr, int, var, int64, var, int, str, var ; res = AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId) ; UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "var" ; Reserved : void* in/out -> "intptr" ; InitiatorPortNumber : DWORD -> "int" ; TargetPortal : ISCSI_TARGET_PORTALW* in/out -> "var" ; SecurityFlags : ULONGLONG -> "int64" ; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "var" ; KeySize : DWORD -> "int" ; Key : LPSTR optional -> "str" ; ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD AddIScsiConnectionW(ISCSI_UNIQUE_SESSION_ID* UniqueSessionId, void* Reserved, DWORD InitiatorPortNumber, ISCSI_TARGET_PORTALW* TargetPortal, ULONGLONG SecurityFlags, ISCSI_LOGIN_OPTIONS* LoginOptions, DWORD KeySize, LPSTR Key, ISCSI_UNIQUE_SESSION_ID* ConnectionId) #uselib "ISCSIDSC.dll" #cfunc global AddIScsiConnectionW "AddIScsiConnectionW" intptr, intptr, int, intptr, int64, intptr, int, str, intptr ; res = AddIScsiConnectionW(varptr(UniqueSessionId), Reserved, InitiatorPortNumber, varptr(TargetPortal), SecurityFlags, varptr(LoginOptions), KeySize, Key, varptr(ConnectionId)) ; UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "intptr" ; Reserved : void* in/out -> "intptr" ; InitiatorPortNumber : DWORD -> "int" ; TargetPortal : ISCSI_TARGET_PORTALW* in/out -> "intptr" ; SecurityFlags : ULONGLONG -> "int64" ; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "intptr" ; KeySize : DWORD -> "int" ; Key : LPSTR optional -> "str" ; ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iscsidsc = windows.NewLazySystemDLL("ISCSIDSC.dll")
procAddIScsiConnectionW = iscsidsc.NewProc("AddIScsiConnectionW")
)
// UniqueSessionId (ISCSI_UNIQUE_SESSION_ID* in/out), Reserved (void* in/out), InitiatorPortNumber (DWORD), TargetPortal (ISCSI_TARGET_PORTALW* in/out), SecurityFlags (ULONGLONG), LoginOptions (ISCSI_LOGIN_OPTIONS* in/out), KeySize (DWORD), Key (LPSTR optional), ConnectionId (ISCSI_UNIQUE_SESSION_ID* in/out)
r1, _, err := procAddIScsiConnectionW.Call(
uintptr(UniqueSessionId),
uintptr(Reserved),
uintptr(InitiatorPortNumber),
uintptr(TargetPortal),
uintptr(SecurityFlags),
uintptr(LoginOptions),
uintptr(KeySize),
uintptr(unsafe.Pointer(windows.BytePtrFromString(Key))),
uintptr(ConnectionId),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction AddIScsiConnectionW(
UniqueSessionId: Pointer; // ISCSI_UNIQUE_SESSION_ID* in/out
Reserved: Pointer; // void* in/out
InitiatorPortNumber: DWORD; // DWORD
TargetPortal: Pointer; // ISCSI_TARGET_PORTALW* in/out
SecurityFlags: UInt64; // ULONGLONG
LoginOptions: Pointer; // ISCSI_LOGIN_OPTIONS* in/out
KeySize: DWORD; // DWORD
Key: PAnsiChar; // LPSTR optional
ConnectionId: Pointer // ISCSI_UNIQUE_SESSION_ID* in/out
): DWORD; stdcall;
external 'ISCSIDSC.dll' name 'AddIScsiConnectionW';result := DllCall("ISCSIDSC\AddIScsiConnectionW"
, "Ptr", UniqueSessionId ; ISCSI_UNIQUE_SESSION_ID* in/out
, "Ptr", Reserved ; void* in/out
, "UInt", InitiatorPortNumber ; DWORD
, "Ptr", TargetPortal ; ISCSI_TARGET_PORTALW* in/out
, "Int64", SecurityFlags ; ULONGLONG
, "Ptr", LoginOptions ; ISCSI_LOGIN_OPTIONS* in/out
, "UInt", KeySize ; DWORD
, "AStr", Key ; LPSTR optional
, "Ptr", ConnectionId ; ISCSI_UNIQUE_SESSION_ID* in/out
, "UInt") ; return: DWORD●AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId) = DLL("ISCSIDSC.dll", "dword AddIScsiConnectionW(void*, void*, dword, void*, qword, void*, dword, char*, void*)")
# 呼び出し: AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId)
# UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "void*"
# Reserved : void* in/out -> "void*"
# InitiatorPortNumber : DWORD -> "dword"
# TargetPortal : ISCSI_TARGET_PORTALW* in/out -> "void*"
# SecurityFlags : ULONGLONG -> "qword"
# LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "void*"
# KeySize : DWORD -> "dword"
# Key : LPSTR optional -> "char*"
# ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "iscsidsc" fn AddIScsiConnectionW(
UniqueSessionId: [*c]ISCSI_UNIQUE_SESSION_ID, // ISCSI_UNIQUE_SESSION_ID* in/out
Reserved: ?*anyopaque, // void* in/out
InitiatorPortNumber: u32, // DWORD
TargetPortal: [*c]ISCSI_TARGET_PORTALW, // ISCSI_TARGET_PORTALW* in/out
SecurityFlags: u64, // ULONGLONG
LoginOptions: [*c]ISCSI_LOGIN_OPTIONS, // ISCSI_LOGIN_OPTIONS* in/out
KeySize: u32, // DWORD
Key: [*c]const u8, // LPSTR optional
ConnectionId: [*c]ISCSI_UNIQUE_SESSION_ID // ISCSI_UNIQUE_SESSION_ID* in/out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc AddIScsiConnectionW(
UniqueSessionId: ptr ISCSI_UNIQUE_SESSION_ID, # ISCSI_UNIQUE_SESSION_ID* in/out
Reserved: pointer, # void* in/out
InitiatorPortNumber: uint32, # DWORD
TargetPortal: ptr ISCSI_TARGET_PORTALW, # ISCSI_TARGET_PORTALW* in/out
SecurityFlags: uint64, # ULONGLONG
LoginOptions: ptr ISCSI_LOGIN_OPTIONS, # ISCSI_LOGIN_OPTIONS* in/out
KeySize: uint32, # DWORD
Key: cstring, # LPSTR optional
ConnectionId: ptr ISCSI_UNIQUE_SESSION_ID # ISCSI_UNIQUE_SESSION_ID* in/out
): uint32 {.importc: "AddIScsiConnectionW", stdcall, dynlib: "ISCSIDSC.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "iscsidsc");
extern(Windows)
uint AddIScsiConnectionW(
ISCSI_UNIQUE_SESSION_ID* UniqueSessionId, // ISCSI_UNIQUE_SESSION_ID* in/out
void* Reserved, // void* in/out
uint InitiatorPortNumber, // DWORD
ISCSI_TARGET_PORTALW* TargetPortal, // ISCSI_TARGET_PORTALW* in/out
ulong SecurityFlags, // ULONGLONG
ISCSI_LOGIN_OPTIONS* LoginOptions, // ISCSI_LOGIN_OPTIONS* in/out
uint KeySize, // DWORD
const(char)* Key, // LPSTR optional
ISCSI_UNIQUE_SESSION_ID* ConnectionId // ISCSI_UNIQUE_SESSION_ID* in/out
);ccall((:AddIScsiConnectionW, "ISCSIDSC.dll"), stdcall, UInt32,
(Ptr{ISCSI_UNIQUE_SESSION_ID}, Ptr{Cvoid}, UInt32, Ptr{ISCSI_TARGET_PORTALW}, UInt64, Ptr{ISCSI_LOGIN_OPTIONS}, UInt32, Cstring, Ptr{ISCSI_UNIQUE_SESSION_ID}),
UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId)
# UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> Ptr{ISCSI_UNIQUE_SESSION_ID}
# Reserved : void* in/out -> Ptr{Cvoid}
# InitiatorPortNumber : DWORD -> UInt32
# TargetPortal : ISCSI_TARGET_PORTALW* in/out -> Ptr{ISCSI_TARGET_PORTALW}
# SecurityFlags : ULONGLONG -> UInt64
# LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> Ptr{ISCSI_LOGIN_OPTIONS}
# KeySize : DWORD -> UInt32
# Key : LPSTR optional -> Cstring
# ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> Ptr{ISCSI_UNIQUE_SESSION_ID}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t AddIScsiConnectionW(
void* UniqueSessionId,
void* Reserved,
uint32_t InitiatorPortNumber,
void* TargetPortal,
uint64_t SecurityFlags,
void* LoginOptions,
uint32_t KeySize,
const char* Key,
void* ConnectionId);
]]
local iscsidsc = ffi.load("iscsidsc")
-- iscsidsc.AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId)
-- UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out
-- Reserved : void* in/out
-- InitiatorPortNumber : DWORD
-- TargetPortal : ISCSI_TARGET_PORTALW* in/out
-- SecurityFlags : ULONGLONG
-- LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
-- KeySize : DWORD
-- Key : LPSTR optional
-- ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ISCSIDSC.dll');
const AddIScsiConnectionW = lib.func('__stdcall', 'AddIScsiConnectionW', 'uint32_t', ['void *', 'void *', 'uint32_t', 'void *', 'uint64_t', 'void *', 'uint32_t', 'str', 'void *']);
// AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId)
// UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> 'void *'
// Reserved : void* in/out -> 'void *'
// InitiatorPortNumber : DWORD -> 'uint32_t'
// TargetPortal : ISCSI_TARGET_PORTALW* in/out -> 'void *'
// SecurityFlags : ULONGLONG -> 'uint64_t'
// LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> 'void *'
// KeySize : DWORD -> 'uint32_t'
// Key : LPSTR optional -> 'str'
// ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ISCSIDSC.dll", {
AddIScsiConnectionW: { parameters: ["pointer", "pointer", "u32", "pointer", "u64", "pointer", "u32", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId)
// UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "pointer"
// Reserved : void* in/out -> "pointer"
// InitiatorPortNumber : DWORD -> "u32"
// TargetPortal : ISCSI_TARGET_PORTALW* in/out -> "pointer"
// SecurityFlags : ULONGLONG -> "u64"
// LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "pointer"
// KeySize : DWORD -> "u32"
// Key : LPSTR optional -> "buffer"
// ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t AddIScsiConnectionW(
void* UniqueSessionId,
void* Reserved,
uint32_t InitiatorPortNumber,
void* TargetPortal,
uint64_t SecurityFlags,
void* LoginOptions,
uint32_t KeySize,
const char* Key,
void* ConnectionId);
C, "ISCSIDSC.dll");
// $ffi->AddIScsiConnectionW(UniqueSessionId, Reserved, InitiatorPortNumber, TargetPortal, SecurityFlags, LoginOptions, KeySize, Key, ConnectionId);
// UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out
// Reserved : void* in/out
// InitiatorPortNumber : DWORD
// TargetPortal : ISCSI_TARGET_PORTALW* in/out
// SecurityFlags : ULONGLONG
// LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
// KeySize : DWORD
// Key : LPSTR optional
// ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/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 Iscsidsc extends StdCallLibrary {
Iscsidsc INSTANCE = Native.load("iscsidsc", Iscsidsc.class, W32APIOptions.UNICODE_OPTIONS);
int AddIScsiConnectionW(
Pointer UniqueSessionId, // ISCSI_UNIQUE_SESSION_ID* in/out
Pointer Reserved, // void* in/out
int InitiatorPortNumber, // DWORD
Pointer TargetPortal, // ISCSI_TARGET_PORTALW* in/out
long SecurityFlags, // ULONGLONG
Pointer LoginOptions, // ISCSI_LOGIN_OPTIONS* in/out
int KeySize, // DWORD
String Key, // LPSTR optional
Pointer ConnectionId // ISCSI_UNIQUE_SESSION_ID* in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("iscsidsc")]
lib LibISCSIDSC
fun AddIScsiConnectionW = AddIScsiConnectionW(
UniqueSessionId : ISCSI_UNIQUE_SESSION_ID*, # ISCSI_UNIQUE_SESSION_ID* in/out
Reserved : Void*, # void* in/out
InitiatorPortNumber : UInt32, # DWORD
TargetPortal : ISCSI_TARGET_PORTALW*, # ISCSI_TARGET_PORTALW* in/out
SecurityFlags : UInt64, # ULONGLONG
LoginOptions : ISCSI_LOGIN_OPTIONS*, # ISCSI_LOGIN_OPTIONS* in/out
KeySize : UInt32, # DWORD
Key : UInt8*, # LPSTR optional
ConnectionId : ISCSI_UNIQUE_SESSION_ID* # ISCSI_UNIQUE_SESSION_ID* in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef AddIScsiConnectionWNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Uint32, Pointer<Void>, Uint64, Pointer<Void>, Uint32, Pointer<Utf8>, Pointer<Void>);
typedef AddIScsiConnectionWDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Void>, int, Pointer<Void>, int, Pointer<Utf8>, Pointer<Void>);
final AddIScsiConnectionW = DynamicLibrary.open('ISCSIDSC.dll')
.lookupFunction<AddIScsiConnectionWNative, AddIScsiConnectionWDart>('AddIScsiConnectionW');
// UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> Pointer<Void>
// Reserved : void* in/out -> Pointer<Void>
// InitiatorPortNumber : DWORD -> Uint32
// TargetPortal : ISCSI_TARGET_PORTALW* in/out -> Pointer<Void>
// SecurityFlags : ULONGLONG -> Uint64
// LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> Pointer<Void>
// KeySize : DWORD -> Uint32
// Key : LPSTR optional -> Pointer<Utf8>
// ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function AddIScsiConnectionW(
UniqueSessionId: Pointer; // ISCSI_UNIQUE_SESSION_ID* in/out
Reserved: Pointer; // void* in/out
InitiatorPortNumber: DWORD; // DWORD
TargetPortal: Pointer; // ISCSI_TARGET_PORTALW* in/out
SecurityFlags: UInt64; // ULONGLONG
LoginOptions: Pointer; // ISCSI_LOGIN_OPTIONS* in/out
KeySize: DWORD; // DWORD
Key: PAnsiChar; // LPSTR optional
ConnectionId: Pointer // ISCSI_UNIQUE_SESSION_ID* in/out
): DWORD; stdcall;
external 'ISCSIDSC.dll' name 'AddIScsiConnectionW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "AddIScsiConnectionW"
c_AddIScsiConnectionW :: Ptr () -> Ptr () -> Word32 -> Ptr () -> Word64 -> Ptr () -> Word32 -> CString -> Ptr () -> IO Word32
-- UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> Ptr ()
-- Reserved : void* in/out -> Ptr ()
-- InitiatorPortNumber : DWORD -> Word32
-- TargetPortal : ISCSI_TARGET_PORTALW* in/out -> Ptr ()
-- SecurityFlags : ULONGLONG -> Word64
-- LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> Ptr ()
-- KeySize : DWORD -> Word32
-- Key : LPSTR optional -> CString
-- ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let addiscsiconnectionw =
foreign "AddIScsiConnectionW"
((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr void) @-> uint64_t @-> (ptr void) @-> uint32_t @-> string @-> (ptr void) @-> returning uint32_t)
(* UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> (ptr void) *)
(* Reserved : void* in/out -> (ptr void) *)
(* InitiatorPortNumber : DWORD -> uint32_t *)
(* TargetPortal : ISCSI_TARGET_PORTALW* in/out -> (ptr void) *)
(* SecurityFlags : ULONGLONG -> uint64_t *)
(* LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> (ptr void) *)
(* KeySize : DWORD -> uint32_t *)
(* Key : LPSTR optional -> string *)
(* ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iscsidsc (t "ISCSIDSC.dll"))
(cffi:use-foreign-library iscsidsc)
(cffi:defcfun ("AddIScsiConnectionW" add-iscsi-connection-w :convention :stdcall) :uint32
(unique-session-id :pointer) ; ISCSI_UNIQUE_SESSION_ID* in/out
(reserved :pointer) ; void* in/out
(initiator-port-number :uint32) ; DWORD
(target-portal :pointer) ; ISCSI_TARGET_PORTALW* in/out
(security-flags :uint64) ; ULONGLONG
(login-options :pointer) ; ISCSI_LOGIN_OPTIONS* in/out
(key-size :uint32) ; DWORD
(key :string) ; LPSTR optional
(connection-id :pointer)) ; ISCSI_UNIQUE_SESSION_ID* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $AddIScsiConnectionW = Win32::API::More->new('ISCSIDSC',
'DWORD AddIScsiConnectionW(LPVOID UniqueSessionId, LPVOID Reserved, DWORD InitiatorPortNumber, LPVOID TargetPortal, UINT64 SecurityFlags, LPVOID LoginOptions, DWORD KeySize, LPCSTR Key, LPVOID ConnectionId)');
# my $ret = $AddIScsiConnectionW->Call($UniqueSessionId, $Reserved, $InitiatorPortNumber, $TargetPortal, $SecurityFlags, $LoginOptions, $KeySize, $Key, $ConnectionId);
# UniqueSessionId : ISCSI_UNIQUE_SESSION_ID* in/out -> LPVOID
# Reserved : void* in/out -> LPVOID
# InitiatorPortNumber : DWORD -> DWORD
# TargetPortal : ISCSI_TARGET_PORTALW* in/out -> LPVOID
# SecurityFlags : ULONGLONG -> UINT64
# LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> LPVOID
# KeySize : DWORD -> DWORD
# Key : LPSTR optional -> LPCSTR
# ConnectionId : ISCSI_UNIQUE_SESSION_ID* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f AddIScsiConnectionA (ANSI版) — 既存のiSCSIセッションに新しい接続を追加する(ANSI版)。