ホーム › Storage.IscsiDisc › AddIScsiStaticTargetA
AddIScsiStaticTargetA
関数静的に構成するiSCSIターゲットを追加登録する(ANSI版)。
シグネチャ
// ISCSIDSC.dll (ANSI / -A)
#include <windows.h>
DWORD AddIScsiStaticTargetA(
LPSTR TargetName,
LPSTR TargetAlias, // optional
DWORD TargetFlags,
BOOLEAN Persist,
ISCSI_TARGET_MAPPINGA* Mappings,
ISCSI_LOGIN_OPTIONS* LoginOptions,
ISCSI_TARGET_PORTAL_GROUPA* PortalGroup
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| TargetName | LPSTR | in | 登録する静的iSCSIターゲットの名前を指す。 |
| TargetAlias | LPSTR | inoptional | ターゲットに付与する別名を指す。NULL可。 |
| TargetFlags | DWORD | in | ターゲットの動作を制御するフラグ。 |
| Persist | BOOLEAN | in | TRUEで再起動後も登録を保持するか示すBOOLEAN値。 |
| Mappings | ISCSI_TARGET_MAPPINGA* | inout | ターゲットLUNのマッピング情報ISCSI_TARGET_MAPPINGAへのポインタ。NULL可。 |
| LoginOptions | ISCSI_LOGIN_OPTIONS* | inout | 既定のログインオプションISCSI_LOGIN_OPTIONSへのポインタ。NULL可。 |
| PortalGroup | ISCSI_TARGET_PORTAL_GROUPA* | inout | ターゲットポータルグループISCSI_TARGET_PORTAL_GROUPAへのポインタ。 |
戻り値の型: DWORD
各言語での呼び出し定義
// ISCSIDSC.dll (ANSI / -A)
#include <windows.h>
DWORD AddIScsiStaticTargetA(
LPSTR TargetName,
LPSTR TargetAlias, // optional
DWORD TargetFlags,
BOOLEAN Persist,
ISCSI_TARGET_MAPPINGA* Mappings,
ISCSI_LOGIN_OPTIONS* LoginOptions,
ISCSI_TARGET_PORTAL_GROUPA* PortalGroup
);[DllImport("ISCSIDSC.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint AddIScsiStaticTargetA(
[MarshalAs(UnmanagedType.LPStr)] string TargetName, // LPSTR
[MarshalAs(UnmanagedType.LPStr)] string TargetAlias, // LPSTR optional
uint TargetFlags, // DWORD
[MarshalAs(UnmanagedType.U1)] bool Persist, // BOOLEAN
IntPtr Mappings, // ISCSI_TARGET_MAPPINGA* in/out
IntPtr LoginOptions, // ISCSI_LOGIN_OPTIONS* in/out
IntPtr PortalGroup // ISCSI_TARGET_PORTAL_GROUPA* in/out
);<DllImport("ISCSIDSC.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function AddIScsiStaticTargetA(
<MarshalAs(UnmanagedType.LPStr)> TargetName As String, ' LPSTR
<MarshalAs(UnmanagedType.LPStr)> TargetAlias As String, ' LPSTR optional
TargetFlags As UInteger, ' DWORD
<MarshalAs(UnmanagedType.U1)> Persist As Boolean, ' BOOLEAN
Mappings As IntPtr, ' ISCSI_TARGET_MAPPINGA* in/out
LoginOptions As IntPtr, ' ISCSI_LOGIN_OPTIONS* in/out
PortalGroup As IntPtr ' ISCSI_TARGET_PORTAL_GROUPA* in/out
) As UInteger
End Function' TargetName : LPSTR
' TargetAlias : LPSTR optional
' TargetFlags : DWORD
' Persist : BOOLEAN
' Mappings : ISCSI_TARGET_MAPPINGA* in/out
' LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
' PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out
Declare PtrSafe Function AddIScsiStaticTargetA Lib "iscsidsc" ( _
ByVal TargetName As String, _
ByVal TargetAlias As String, _
ByVal TargetFlags As Long, _
ByVal Persist As Byte, _
ByVal Mappings As LongPtr, _
ByVal LoginOptions As LongPtr, _
ByVal PortalGroup As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
AddIScsiStaticTargetA = ctypes.windll.iscsidsc.AddIScsiStaticTargetA
AddIScsiStaticTargetA.restype = wintypes.DWORD
AddIScsiStaticTargetA.argtypes = [
wintypes.LPCSTR, # TargetName : LPSTR
wintypes.LPCSTR, # TargetAlias : LPSTR optional
wintypes.DWORD, # TargetFlags : DWORD
wintypes.BOOLEAN, # Persist : BOOLEAN
ctypes.c_void_p, # Mappings : ISCSI_TARGET_MAPPINGA* in/out
ctypes.c_void_p, # LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
ctypes.c_void_p, # PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ISCSIDSC.dll')
AddIScsiStaticTargetA = Fiddle::Function.new(
lib['AddIScsiStaticTargetA'],
[
Fiddle::TYPE_VOIDP, # TargetName : LPSTR
Fiddle::TYPE_VOIDP, # TargetAlias : LPSTR optional
-Fiddle::TYPE_INT, # TargetFlags : DWORD
Fiddle::TYPE_CHAR, # Persist : BOOLEAN
Fiddle::TYPE_VOIDP, # Mappings : ISCSI_TARGET_MAPPINGA* in/out
Fiddle::TYPE_VOIDP, # LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
Fiddle::TYPE_VOIDP, # PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out
],
-Fiddle::TYPE_INT)#[link(name = "iscsidsc")]
extern "system" {
fn AddIScsiStaticTargetA(
TargetName: *mut u8, // LPSTR
TargetAlias: *mut u8, // LPSTR optional
TargetFlags: u32, // DWORD
Persist: u8, // BOOLEAN
Mappings: *mut ISCSI_TARGET_MAPPINGA, // ISCSI_TARGET_MAPPINGA* in/out
LoginOptions: *mut ISCSI_LOGIN_OPTIONS, // ISCSI_LOGIN_OPTIONS* in/out
PortalGroup: *mut ISCSI_TARGET_PORTAL_GROUPA // ISCSI_TARGET_PORTAL_GROUPA* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ISCSIDSC.dll", CharSet = CharSet.Ansi)]
public static extern uint AddIScsiStaticTargetA([MarshalAs(UnmanagedType.LPStr)] string TargetName, [MarshalAs(UnmanagedType.LPStr)] string TargetAlias, uint TargetFlags, [MarshalAs(UnmanagedType.U1)] bool Persist, IntPtr Mappings, IntPtr LoginOptions, IntPtr PortalGroup);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ISCSIDSC_AddIScsiStaticTargetA' -Namespace Win32 -PassThru
# $api::AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup)#uselib "ISCSIDSC.dll"
#func global AddIScsiStaticTargetA "AddIScsiStaticTargetA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; AddIScsiStaticTargetA TargetName, TargetAlias, TargetFlags, Persist, varptr(Mappings), varptr(LoginOptions), varptr(PortalGroup) ; 戻り値は stat
; TargetName : LPSTR -> "sptr"
; TargetAlias : LPSTR optional -> "sptr"
; TargetFlags : DWORD -> "sptr"
; Persist : BOOLEAN -> "sptr"
; Mappings : ISCSI_TARGET_MAPPINGA* in/out -> "sptr"
; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "sptr"
; PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ISCSIDSC.dll" #cfunc global AddIScsiStaticTargetA "AddIScsiStaticTargetA" str, str, int, int, var, var, var ; res = AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup) ; TargetName : LPSTR -> "str" ; TargetAlias : LPSTR optional -> "str" ; TargetFlags : DWORD -> "int" ; Persist : BOOLEAN -> "int" ; Mappings : ISCSI_TARGET_MAPPINGA* in/out -> "var" ; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "var" ; PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ISCSIDSC.dll" #cfunc global AddIScsiStaticTargetA "AddIScsiStaticTargetA" str, str, int, int, sptr, sptr, sptr ; res = AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, varptr(Mappings), varptr(LoginOptions), varptr(PortalGroup)) ; TargetName : LPSTR -> "str" ; TargetAlias : LPSTR optional -> "str" ; TargetFlags : DWORD -> "int" ; Persist : BOOLEAN -> "int" ; Mappings : ISCSI_TARGET_MAPPINGA* in/out -> "sptr" ; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "sptr" ; PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD AddIScsiStaticTargetA(LPSTR TargetName, LPSTR TargetAlias, DWORD TargetFlags, BOOLEAN Persist, ISCSI_TARGET_MAPPINGA* Mappings, ISCSI_LOGIN_OPTIONS* LoginOptions, ISCSI_TARGET_PORTAL_GROUPA* PortalGroup) #uselib "ISCSIDSC.dll" #cfunc global AddIScsiStaticTargetA "AddIScsiStaticTargetA" str, str, int, int, var, var, var ; res = AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup) ; TargetName : LPSTR -> "str" ; TargetAlias : LPSTR optional -> "str" ; TargetFlags : DWORD -> "int" ; Persist : BOOLEAN -> "int" ; Mappings : ISCSI_TARGET_MAPPINGA* in/out -> "var" ; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "var" ; PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD AddIScsiStaticTargetA(LPSTR TargetName, LPSTR TargetAlias, DWORD TargetFlags, BOOLEAN Persist, ISCSI_TARGET_MAPPINGA* Mappings, ISCSI_LOGIN_OPTIONS* LoginOptions, ISCSI_TARGET_PORTAL_GROUPA* PortalGroup) #uselib "ISCSIDSC.dll" #cfunc global AddIScsiStaticTargetA "AddIScsiStaticTargetA" str, str, int, int, intptr, intptr, intptr ; res = AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, varptr(Mappings), varptr(LoginOptions), varptr(PortalGroup)) ; TargetName : LPSTR -> "str" ; TargetAlias : LPSTR optional -> "str" ; TargetFlags : DWORD -> "int" ; Persist : BOOLEAN -> "int" ; Mappings : ISCSI_TARGET_MAPPINGA* in/out -> "intptr" ; LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "intptr" ; PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iscsidsc = windows.NewLazySystemDLL("ISCSIDSC.dll")
procAddIScsiStaticTargetA = iscsidsc.NewProc("AddIScsiStaticTargetA")
)
// TargetName (LPSTR), TargetAlias (LPSTR optional), TargetFlags (DWORD), Persist (BOOLEAN), Mappings (ISCSI_TARGET_MAPPINGA* in/out), LoginOptions (ISCSI_LOGIN_OPTIONS* in/out), PortalGroup (ISCSI_TARGET_PORTAL_GROUPA* in/out)
r1, _, err := procAddIScsiStaticTargetA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(TargetName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(TargetAlias))),
uintptr(TargetFlags),
uintptr(Persist),
uintptr(Mappings),
uintptr(LoginOptions),
uintptr(PortalGroup),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction AddIScsiStaticTargetA(
TargetName: PAnsiChar; // LPSTR
TargetAlias: PAnsiChar; // LPSTR optional
TargetFlags: DWORD; // DWORD
Persist: ByteBool; // BOOLEAN
Mappings: Pointer; // ISCSI_TARGET_MAPPINGA* in/out
LoginOptions: Pointer; // ISCSI_LOGIN_OPTIONS* in/out
PortalGroup: Pointer // ISCSI_TARGET_PORTAL_GROUPA* in/out
): DWORD; stdcall;
external 'ISCSIDSC.dll' name 'AddIScsiStaticTargetA';result := DllCall("ISCSIDSC\AddIScsiStaticTargetA"
, "AStr", TargetName ; LPSTR
, "AStr", TargetAlias ; LPSTR optional
, "UInt", TargetFlags ; DWORD
, "Char", Persist ; BOOLEAN
, "Ptr", Mappings ; ISCSI_TARGET_MAPPINGA* in/out
, "Ptr", LoginOptions ; ISCSI_LOGIN_OPTIONS* in/out
, "Ptr", PortalGroup ; ISCSI_TARGET_PORTAL_GROUPA* in/out
, "UInt") ; return: DWORD●AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup) = DLL("ISCSIDSC.dll", "dword AddIScsiStaticTargetA(char*, char*, dword, byte, void*, void*, void*)")
# 呼び出し: AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup)
# TargetName : LPSTR -> "char*"
# TargetAlias : LPSTR optional -> "char*"
# TargetFlags : DWORD -> "dword"
# Persist : BOOLEAN -> "byte"
# Mappings : ISCSI_TARGET_MAPPINGA* in/out -> "void*"
# LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "void*"
# PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iscsidsc" fn AddIScsiStaticTargetA(
TargetName: [*c]const u8, // LPSTR
TargetAlias: [*c]const u8, // LPSTR optional
TargetFlags: u32, // DWORD
Persist: u8, // BOOLEAN
Mappings: [*c]ISCSI_TARGET_MAPPINGA, // ISCSI_TARGET_MAPPINGA* in/out
LoginOptions: [*c]ISCSI_LOGIN_OPTIONS, // ISCSI_LOGIN_OPTIONS* in/out
PortalGroup: [*c]ISCSI_TARGET_PORTAL_GROUPA // ISCSI_TARGET_PORTAL_GROUPA* in/out
) callconv(std.os.windows.WINAPI) u32;proc AddIScsiStaticTargetA(
TargetName: cstring, # LPSTR
TargetAlias: cstring, # LPSTR optional
TargetFlags: uint32, # DWORD
Persist: uint8, # BOOLEAN
Mappings: ptr ISCSI_TARGET_MAPPINGA, # ISCSI_TARGET_MAPPINGA* in/out
LoginOptions: ptr ISCSI_LOGIN_OPTIONS, # ISCSI_LOGIN_OPTIONS* in/out
PortalGroup: ptr ISCSI_TARGET_PORTAL_GROUPA # ISCSI_TARGET_PORTAL_GROUPA* in/out
): uint32 {.importc: "AddIScsiStaticTargetA", stdcall, dynlib: "ISCSIDSC.dll".}pragma(lib, "iscsidsc");
extern(Windows)
uint AddIScsiStaticTargetA(
const(char)* TargetName, // LPSTR
const(char)* TargetAlias, // LPSTR optional
uint TargetFlags, // DWORD
ubyte Persist, // BOOLEAN
ISCSI_TARGET_MAPPINGA* Mappings, // ISCSI_TARGET_MAPPINGA* in/out
ISCSI_LOGIN_OPTIONS* LoginOptions, // ISCSI_LOGIN_OPTIONS* in/out
ISCSI_TARGET_PORTAL_GROUPA* PortalGroup // ISCSI_TARGET_PORTAL_GROUPA* in/out
);ccall((:AddIScsiStaticTargetA, "ISCSIDSC.dll"), stdcall, UInt32,
(Cstring, Cstring, UInt32, UInt8, Ptr{ISCSI_TARGET_MAPPINGA}, Ptr{ISCSI_LOGIN_OPTIONS}, Ptr{ISCSI_TARGET_PORTAL_GROUPA}),
TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup)
# TargetName : LPSTR -> Cstring
# TargetAlias : LPSTR optional -> Cstring
# TargetFlags : DWORD -> UInt32
# Persist : BOOLEAN -> UInt8
# Mappings : ISCSI_TARGET_MAPPINGA* in/out -> Ptr{ISCSI_TARGET_MAPPINGA}
# LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> Ptr{ISCSI_LOGIN_OPTIONS}
# PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> Ptr{ISCSI_TARGET_PORTAL_GROUPA}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t AddIScsiStaticTargetA(
const char* TargetName,
const char* TargetAlias,
uint32_t TargetFlags,
uint8_t Persist,
void* Mappings,
void* LoginOptions,
void* PortalGroup);
]]
local iscsidsc = ffi.load("iscsidsc")
-- iscsidsc.AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup)
-- TargetName : LPSTR
-- TargetAlias : LPSTR optional
-- TargetFlags : DWORD
-- Persist : BOOLEAN
-- Mappings : ISCSI_TARGET_MAPPINGA* in/out
-- LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
-- PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ISCSIDSC.dll');
const AddIScsiStaticTargetA = lib.func('__stdcall', 'AddIScsiStaticTargetA', 'uint32_t', ['str', 'str', 'uint32_t', 'uint8_t', 'void *', 'void *', 'void *']);
// AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup)
// TargetName : LPSTR -> 'str'
// TargetAlias : LPSTR optional -> 'str'
// TargetFlags : DWORD -> 'uint32_t'
// Persist : BOOLEAN -> 'uint8_t'
// Mappings : ISCSI_TARGET_MAPPINGA* in/out -> 'void *'
// LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> 'void *'
// PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ISCSIDSC.dll", {
AddIScsiStaticTargetA: { parameters: ["buffer", "buffer", "u32", "u8", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup)
// TargetName : LPSTR -> "buffer"
// TargetAlias : LPSTR optional -> "buffer"
// TargetFlags : DWORD -> "u32"
// Persist : BOOLEAN -> "u8"
// Mappings : ISCSI_TARGET_MAPPINGA* in/out -> "pointer"
// LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> "pointer"
// PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t AddIScsiStaticTargetA(
const char* TargetName,
const char* TargetAlias,
uint32_t TargetFlags,
uint8_t Persist,
void* Mappings,
void* LoginOptions,
void* PortalGroup);
C, "ISCSIDSC.dll");
// $ffi->AddIScsiStaticTargetA(TargetName, TargetAlias, TargetFlags, Persist, Mappings, LoginOptions, PortalGroup);
// TargetName : LPSTR
// TargetAlias : LPSTR optional
// TargetFlags : DWORD
// Persist : BOOLEAN
// Mappings : ISCSI_TARGET_MAPPINGA* in/out
// LoginOptions : ISCSI_LOGIN_OPTIONS* in/out
// PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* 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.ASCII_OPTIONS);
int AddIScsiStaticTargetA(
String TargetName, // LPSTR
String TargetAlias, // LPSTR optional
int TargetFlags, // DWORD
byte Persist, // BOOLEAN
Pointer Mappings, // ISCSI_TARGET_MAPPINGA* in/out
Pointer LoginOptions, // ISCSI_LOGIN_OPTIONS* in/out
Pointer PortalGroup // ISCSI_TARGET_PORTAL_GROUPA* in/out
);
}@[Link("iscsidsc")]
lib LibISCSIDSC
fun AddIScsiStaticTargetA = AddIScsiStaticTargetA(
TargetName : UInt8*, # LPSTR
TargetAlias : UInt8*, # LPSTR optional
TargetFlags : UInt32, # DWORD
Persist : UInt8, # BOOLEAN
Mappings : ISCSI_TARGET_MAPPINGA*, # ISCSI_TARGET_MAPPINGA* in/out
LoginOptions : ISCSI_LOGIN_OPTIONS*, # ISCSI_LOGIN_OPTIONS* in/out
PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* # ISCSI_TARGET_PORTAL_GROUPA* 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 AddIScsiStaticTargetANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Uint32, Uint8, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef AddIScsiStaticTargetADart = int Function(Pointer<Utf8>, Pointer<Utf8>, int, int, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final AddIScsiStaticTargetA = DynamicLibrary.open('ISCSIDSC.dll')
.lookupFunction<AddIScsiStaticTargetANative, AddIScsiStaticTargetADart>('AddIScsiStaticTargetA');
// TargetName : LPSTR -> Pointer<Utf8>
// TargetAlias : LPSTR optional -> Pointer<Utf8>
// TargetFlags : DWORD -> Uint32
// Persist : BOOLEAN -> Uint8
// Mappings : ISCSI_TARGET_MAPPINGA* in/out -> Pointer<Void>
// LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> Pointer<Void>
// PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function AddIScsiStaticTargetA(
TargetName: PAnsiChar; // LPSTR
TargetAlias: PAnsiChar; // LPSTR optional
TargetFlags: DWORD; // DWORD
Persist: ByteBool; // BOOLEAN
Mappings: Pointer; // ISCSI_TARGET_MAPPINGA* in/out
LoginOptions: Pointer; // ISCSI_LOGIN_OPTIONS* in/out
PortalGroup: Pointer // ISCSI_TARGET_PORTAL_GROUPA* in/out
): DWORD; stdcall;
external 'ISCSIDSC.dll' name 'AddIScsiStaticTargetA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "AddIScsiStaticTargetA"
c_AddIScsiStaticTargetA :: CString -> CString -> Word32 -> Word8 -> Ptr () -> Ptr () -> Ptr () -> IO Word32
-- TargetName : LPSTR -> CString
-- TargetAlias : LPSTR optional -> CString
-- TargetFlags : DWORD -> Word32
-- Persist : BOOLEAN -> Word8
-- Mappings : ISCSI_TARGET_MAPPINGA* in/out -> Ptr ()
-- LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> Ptr ()
-- PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let addiscsistatictargeta =
foreign "AddIScsiStaticTargetA"
(string @-> string @-> uint32_t @-> uint8_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* TargetName : LPSTR -> string *)
(* TargetAlias : LPSTR optional -> string *)
(* TargetFlags : DWORD -> uint32_t *)
(* Persist : BOOLEAN -> uint8_t *)
(* Mappings : ISCSI_TARGET_MAPPINGA* in/out -> (ptr void) *)
(* LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> (ptr void) *)
(* PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* 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 ("AddIScsiStaticTargetA" add-iscsi-static-target-a :convention :stdcall) :uint32
(target-name :string) ; LPSTR
(target-alias :string) ; LPSTR optional
(target-flags :uint32) ; DWORD
(persist :uint8) ; BOOLEAN
(mappings :pointer) ; ISCSI_TARGET_MAPPINGA* in/out
(login-options :pointer) ; ISCSI_LOGIN_OPTIONS* in/out
(portal-group :pointer)) ; ISCSI_TARGET_PORTAL_GROUPA* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $AddIScsiStaticTargetA = Win32::API::More->new('ISCSIDSC',
'DWORD AddIScsiStaticTargetA(LPCSTR TargetName, LPCSTR TargetAlias, DWORD TargetFlags, BYTE Persist, LPVOID Mappings, LPVOID LoginOptions, LPVOID PortalGroup)');
# my $ret = $AddIScsiStaticTargetA->Call($TargetName, $TargetAlias, $TargetFlags, $Persist, $Mappings, $LoginOptions, $PortalGroup);
# TargetName : LPSTR -> LPCSTR
# TargetAlias : LPSTR optional -> LPCSTR
# TargetFlags : DWORD -> DWORD
# Persist : BOOLEAN -> BYTE
# Mappings : ISCSI_TARGET_MAPPINGA* in/out -> LPVOID
# LoginOptions : ISCSI_LOGIN_OPTIONS* in/out -> LPVOID
# PortalGroup : ISCSI_TARGET_PORTAL_GROUPA* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f AddIScsiStaticTargetW (Unicode版) — 静的に構成するiSCSIターゲットを追加登録する。