ホーム › Security.Authentication.Identity › SecAllocateAndSetCallTarget
SecAllocateAndSetCallTarget
関数呼び出しコンテキストにIPアドレスとターゲット名を設定する。
シグネチャ
// SspiCli.dll
#include <windows.h>
HRESULT SecAllocateAndSetCallTarget(
BYTE* lpIpAddress, // optional
DWORD cchIpAddress,
LPWSTR TargetName, // optional
INT* FreeCallContext
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpIpAddress | BYTE* | inoptional | 設定するIPアドレスのバイト列へのポインタ。 |
| cchIpAddress | DWORD | in | lpIpAddressのバイト数を指定する。 |
| TargetName | LPWSTR | inoptional | 設定する呼び出しターゲット名を示すワイド文字列。 |
| FreeCallContext | INT* | out | 出力。後で解放するための呼び出しコンテキスト識別子を受け取るポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// SspiCli.dll
#include <windows.h>
HRESULT SecAllocateAndSetCallTarget(
BYTE* lpIpAddress, // optional
DWORD cchIpAddress,
LPWSTR TargetName, // optional
INT* FreeCallContext
);[DllImport("SspiCli.dll", ExactSpelling = true)]
static extern int SecAllocateAndSetCallTarget(
IntPtr lpIpAddress, // BYTE* optional
uint cchIpAddress, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string TargetName, // LPWSTR optional
out int FreeCallContext // INT* out
);<DllImport("SspiCli.dll", ExactSpelling:=True)>
Public Shared Function SecAllocateAndSetCallTarget(
lpIpAddress As IntPtr, ' BYTE* optional
cchIpAddress As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> TargetName As String, ' LPWSTR optional
<Out> ByRef FreeCallContext As Integer ' INT* out
) As Integer
End Function' lpIpAddress : BYTE* optional
' cchIpAddress : DWORD
' TargetName : LPWSTR optional
' FreeCallContext : INT* out
Declare PtrSafe Function SecAllocateAndSetCallTarget Lib "sspicli" ( _
ByVal lpIpAddress As LongPtr, _
ByVal cchIpAddress As Long, _
ByVal TargetName As LongPtr, _
ByRef FreeCallContext As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SecAllocateAndSetCallTarget = ctypes.windll.sspicli.SecAllocateAndSetCallTarget
SecAllocateAndSetCallTarget.restype = ctypes.c_int
SecAllocateAndSetCallTarget.argtypes = [
ctypes.POINTER(ctypes.c_ubyte), # lpIpAddress : BYTE* optional
wintypes.DWORD, # cchIpAddress : DWORD
wintypes.LPCWSTR, # TargetName : LPWSTR optional
ctypes.POINTER(ctypes.c_int), # FreeCallContext : INT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SspiCli.dll')
SecAllocateAndSetCallTarget = Fiddle::Function.new(
lib['SecAllocateAndSetCallTarget'],
[
Fiddle::TYPE_VOIDP, # lpIpAddress : BYTE* optional
-Fiddle::TYPE_INT, # cchIpAddress : DWORD
Fiddle::TYPE_VOIDP, # TargetName : LPWSTR optional
Fiddle::TYPE_VOIDP, # FreeCallContext : INT* out
],
Fiddle::TYPE_INT)#[link(name = "sspicli")]
extern "system" {
fn SecAllocateAndSetCallTarget(
lpIpAddress: *mut u8, // BYTE* optional
cchIpAddress: u32, // DWORD
TargetName: *mut u16, // LPWSTR optional
FreeCallContext: *mut i32 // INT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SspiCli.dll")]
public static extern int SecAllocateAndSetCallTarget(IntPtr lpIpAddress, uint cchIpAddress, [MarshalAs(UnmanagedType.LPWStr)] string TargetName, out int FreeCallContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SspiCli_SecAllocateAndSetCallTarget' -Namespace Win32 -PassThru
# $api::SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext)#uselib "SspiCli.dll"
#func global SecAllocateAndSetCallTarget "SecAllocateAndSetCallTarget" sptr, sptr, sptr, sptr
; SecAllocateAndSetCallTarget varptr(lpIpAddress), cchIpAddress, TargetName, varptr(FreeCallContext) ; 戻り値は stat
; lpIpAddress : BYTE* optional -> "sptr"
; cchIpAddress : DWORD -> "sptr"
; TargetName : LPWSTR optional -> "sptr"
; FreeCallContext : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SspiCli.dll" #cfunc global SecAllocateAndSetCallTarget "SecAllocateAndSetCallTarget" var, int, wstr, var ; res = SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext) ; lpIpAddress : BYTE* optional -> "var" ; cchIpAddress : DWORD -> "int" ; TargetName : LPWSTR optional -> "wstr" ; FreeCallContext : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SspiCli.dll" #cfunc global SecAllocateAndSetCallTarget "SecAllocateAndSetCallTarget" sptr, int, wstr, sptr ; res = SecAllocateAndSetCallTarget(varptr(lpIpAddress), cchIpAddress, TargetName, varptr(FreeCallContext)) ; lpIpAddress : BYTE* optional -> "sptr" ; cchIpAddress : DWORD -> "int" ; TargetName : LPWSTR optional -> "wstr" ; FreeCallContext : INT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SecAllocateAndSetCallTarget(BYTE* lpIpAddress, DWORD cchIpAddress, LPWSTR TargetName, INT* FreeCallContext) #uselib "SspiCli.dll" #cfunc global SecAllocateAndSetCallTarget "SecAllocateAndSetCallTarget" var, int, wstr, var ; res = SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext) ; lpIpAddress : BYTE* optional -> "var" ; cchIpAddress : DWORD -> "int" ; TargetName : LPWSTR optional -> "wstr" ; FreeCallContext : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SecAllocateAndSetCallTarget(BYTE* lpIpAddress, DWORD cchIpAddress, LPWSTR TargetName, INT* FreeCallContext) #uselib "SspiCli.dll" #cfunc global SecAllocateAndSetCallTarget "SecAllocateAndSetCallTarget" intptr, int, wstr, intptr ; res = SecAllocateAndSetCallTarget(varptr(lpIpAddress), cchIpAddress, TargetName, varptr(FreeCallContext)) ; lpIpAddress : BYTE* optional -> "intptr" ; cchIpAddress : DWORD -> "int" ; TargetName : LPWSTR optional -> "wstr" ; FreeCallContext : INT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
sspicli = windows.NewLazySystemDLL("SspiCli.dll")
procSecAllocateAndSetCallTarget = sspicli.NewProc("SecAllocateAndSetCallTarget")
)
// lpIpAddress (BYTE* optional), cchIpAddress (DWORD), TargetName (LPWSTR optional), FreeCallContext (INT* out)
r1, _, err := procSecAllocateAndSetCallTarget.Call(
uintptr(lpIpAddress),
uintptr(cchIpAddress),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(TargetName))),
uintptr(FreeCallContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SecAllocateAndSetCallTarget(
lpIpAddress: Pointer; // BYTE* optional
cchIpAddress: DWORD; // DWORD
TargetName: PWideChar; // LPWSTR optional
FreeCallContext: Pointer // INT* out
): Integer; stdcall;
external 'SspiCli.dll' name 'SecAllocateAndSetCallTarget';result := DllCall("SspiCli\SecAllocateAndSetCallTarget"
, "Ptr", lpIpAddress ; BYTE* optional
, "UInt", cchIpAddress ; DWORD
, "WStr", TargetName ; LPWSTR optional
, "Ptr", FreeCallContext ; INT* out
, "Int") ; return: HRESULT●SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext) = DLL("SspiCli.dll", "int SecAllocateAndSetCallTarget(void*, dword, char*, void*)")
# 呼び出し: SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext)
# lpIpAddress : BYTE* optional -> "void*"
# cchIpAddress : DWORD -> "dword"
# TargetName : LPWSTR optional -> "char*"
# FreeCallContext : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "sspicli" fn SecAllocateAndSetCallTarget(
lpIpAddress: [*c]u8, // BYTE* optional
cchIpAddress: u32, // DWORD
TargetName: [*c]const u16, // LPWSTR optional
FreeCallContext: [*c]i32 // INT* out
) callconv(std.os.windows.WINAPI) i32;proc SecAllocateAndSetCallTarget(
lpIpAddress: ptr uint8, # BYTE* optional
cchIpAddress: uint32, # DWORD
TargetName: WideCString, # LPWSTR optional
FreeCallContext: ptr int32 # INT* out
): int32 {.importc: "SecAllocateAndSetCallTarget", stdcall, dynlib: "SspiCli.dll".}pragma(lib, "sspicli");
extern(Windows)
int SecAllocateAndSetCallTarget(
ubyte* lpIpAddress, // BYTE* optional
uint cchIpAddress, // DWORD
const(wchar)* TargetName, // LPWSTR optional
int* FreeCallContext // INT* out
);ccall((:SecAllocateAndSetCallTarget, "SspiCli.dll"), stdcall, Int32,
(Ptr{UInt8}, UInt32, Cwstring, Ptr{Int32}),
lpIpAddress, cchIpAddress, TargetName, FreeCallContext)
# lpIpAddress : BYTE* optional -> Ptr{UInt8}
# cchIpAddress : DWORD -> UInt32
# TargetName : LPWSTR optional -> Cwstring
# FreeCallContext : INT* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SecAllocateAndSetCallTarget(
uint8_t* lpIpAddress,
uint32_t cchIpAddress,
const uint16_t* TargetName,
int32_t* FreeCallContext);
]]
local sspicli = ffi.load("sspicli")
-- sspicli.SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext)
-- lpIpAddress : BYTE* optional
-- cchIpAddress : DWORD
-- TargetName : LPWSTR optional
-- FreeCallContext : INT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SspiCli.dll');
const SecAllocateAndSetCallTarget = lib.func('__stdcall', 'SecAllocateAndSetCallTarget', 'int32_t', ['uint8_t *', 'uint32_t', 'str16', 'int32_t *']);
// SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext)
// lpIpAddress : BYTE* optional -> 'uint8_t *'
// cchIpAddress : DWORD -> 'uint32_t'
// TargetName : LPWSTR optional -> 'str16'
// FreeCallContext : INT* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SspiCli.dll", {
SecAllocateAndSetCallTarget: { parameters: ["pointer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext)
// lpIpAddress : BYTE* optional -> "pointer"
// cchIpAddress : DWORD -> "u32"
// TargetName : LPWSTR optional -> "buffer"
// FreeCallContext : INT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SecAllocateAndSetCallTarget(
uint8_t* lpIpAddress,
uint32_t cchIpAddress,
const uint16_t* TargetName,
int32_t* FreeCallContext);
C, "SspiCli.dll");
// $ffi->SecAllocateAndSetCallTarget(lpIpAddress, cchIpAddress, TargetName, FreeCallContext);
// lpIpAddress : BYTE* optional
// cchIpAddress : DWORD
// TargetName : LPWSTR optional
// FreeCallContext : INT* 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 Sspicli extends StdCallLibrary {
Sspicli INSTANCE = Native.load("sspicli", Sspicli.class);
int SecAllocateAndSetCallTarget(
byte[] lpIpAddress, // BYTE* optional
int cchIpAddress, // DWORD
WString TargetName, // LPWSTR optional
IntByReference FreeCallContext // INT* out
);
}@[Link("sspicli")]
lib LibSspiCli
fun SecAllocateAndSetCallTarget = SecAllocateAndSetCallTarget(
lpIpAddress : UInt8*, # BYTE* optional
cchIpAddress : UInt32, # DWORD
TargetName : UInt16*, # LPWSTR optional
FreeCallContext : Int32* # INT* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SecAllocateAndSetCallTargetNative = Int32 Function(Pointer<Uint8>, Uint32, Pointer<Utf16>, Pointer<Int32>);
typedef SecAllocateAndSetCallTargetDart = int Function(Pointer<Uint8>, int, Pointer<Utf16>, Pointer<Int32>);
final SecAllocateAndSetCallTarget = DynamicLibrary.open('SspiCli.dll')
.lookupFunction<SecAllocateAndSetCallTargetNative, SecAllocateAndSetCallTargetDart>('SecAllocateAndSetCallTarget');
// lpIpAddress : BYTE* optional -> Pointer<Uint8>
// cchIpAddress : DWORD -> Uint32
// TargetName : LPWSTR optional -> Pointer<Utf16>
// FreeCallContext : INT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SecAllocateAndSetCallTarget(
lpIpAddress: Pointer; // BYTE* optional
cchIpAddress: DWORD; // DWORD
TargetName: PWideChar; // LPWSTR optional
FreeCallContext: Pointer // INT* out
): Integer; stdcall;
external 'SspiCli.dll' name 'SecAllocateAndSetCallTarget';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SecAllocateAndSetCallTarget"
c_SecAllocateAndSetCallTarget :: Ptr Word8 -> Word32 -> CWString -> Ptr Int32 -> IO Int32
-- lpIpAddress : BYTE* optional -> Ptr Word8
-- cchIpAddress : DWORD -> Word32
-- TargetName : LPWSTR optional -> CWString
-- FreeCallContext : INT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let secallocateandsetcalltarget =
foreign "SecAllocateAndSetCallTarget"
((ptr uint8_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr int32_t) @-> returning int32_t)
(* lpIpAddress : BYTE* optional -> (ptr uint8_t) *)
(* cchIpAddress : DWORD -> uint32_t *)
(* TargetName : LPWSTR optional -> (ptr uint16_t) *)
(* FreeCallContext : INT* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library sspicli (t "SspiCli.dll"))
(cffi:use-foreign-library sspicli)
(cffi:defcfun ("SecAllocateAndSetCallTarget" sec-allocate-and-set-call-target :convention :stdcall) :int32
(lp-ip-address :pointer) ; BYTE* optional
(cch-ip-address :uint32) ; DWORD
(target-name (:string :encoding :utf-16le)) ; LPWSTR optional
(free-call-context :pointer)) ; INT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SecAllocateAndSetCallTarget = Win32::API::More->new('SspiCli',
'int SecAllocateAndSetCallTarget(LPVOID lpIpAddress, DWORD cchIpAddress, LPCWSTR TargetName, LPVOID FreeCallContext)');
# my $ret = $SecAllocateAndSetCallTarget->Call($lpIpAddress, $cchIpAddress, $TargetName, $FreeCallContext);
# lpIpAddress : BYTE* optional -> LPVOID
# cchIpAddress : DWORD -> DWORD
# TargetName : LPWSTR optional -> LPCWSTR
# FreeCallContext : INT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。