ホーム › NetworkManagement.NetworkDiagnosticsFramework › NdfCreateWinSockIncident
NdfCreateWinSockIncident
関数Winsockソケットに関するネットワーク診断インシデントを作成する。
シグネチャ
// NDFAPI.dll
#include <windows.h>
HRESULT NdfCreateWinSockIncident(
SOCKET sock,
LPCWSTR host, // optional
WORD port,
LPCWSTR appId, // optional
SID* userId, // optional
void** handle
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| sock | SOCKET | in |
| host | LPCWSTR | inoptional |
| port | WORD | in |
| appId | LPCWSTR | inoptional |
| userId | SID* | inoptional |
| handle | void** | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// NDFAPI.dll
#include <windows.h>
HRESULT NdfCreateWinSockIncident(
SOCKET sock,
LPCWSTR host, // optional
WORD port,
LPCWSTR appId, // optional
SID* userId, // optional
void** handle
);[DllImport("NDFAPI.dll", ExactSpelling = true)]
static extern int NdfCreateWinSockIncident(
UIntPtr sock, // SOCKET
[MarshalAs(UnmanagedType.LPWStr)] string host, // LPCWSTR optional
ushort port, // WORD
[MarshalAs(UnmanagedType.LPWStr)] string appId, // LPCWSTR optional
IntPtr userId, // SID* optional
IntPtr handle // void** out
);<DllImport("NDFAPI.dll", ExactSpelling:=True)>
Public Shared Function NdfCreateWinSockIncident(
sock As UIntPtr, ' SOCKET
<MarshalAs(UnmanagedType.LPWStr)> host As String, ' LPCWSTR optional
port As UShort, ' WORD
<MarshalAs(UnmanagedType.LPWStr)> appId As String, ' LPCWSTR optional
userId As IntPtr, ' SID* optional
handle As IntPtr ' void** out
) As Integer
End Function' sock : SOCKET
' host : LPCWSTR optional
' port : WORD
' appId : LPCWSTR optional
' userId : SID* optional
' handle : void** out
Declare PtrSafe Function NdfCreateWinSockIncident Lib "ndfapi" ( _
ByVal sock As LongPtr, _
ByVal host As LongPtr, _
ByVal port As Integer, _
ByVal appId As LongPtr, _
ByVal userId As LongPtr, _
ByVal handle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
NdfCreateWinSockIncident = ctypes.windll.ndfapi.NdfCreateWinSockIncident
NdfCreateWinSockIncident.restype = ctypes.c_int
NdfCreateWinSockIncident.argtypes = [
ctypes.c_size_t, # sock : SOCKET
wintypes.LPCWSTR, # host : LPCWSTR optional
ctypes.c_ushort, # port : WORD
wintypes.LPCWSTR, # appId : LPCWSTR optional
ctypes.c_void_p, # userId : SID* optional
ctypes.c_void_p, # handle : void** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NDFAPI.dll')
NdfCreateWinSockIncident = Fiddle::Function.new(
lib['NdfCreateWinSockIncident'],
[
Fiddle::TYPE_UINTPTR_T, # sock : SOCKET
Fiddle::TYPE_VOIDP, # host : LPCWSTR optional
-Fiddle::TYPE_SHORT, # port : WORD
Fiddle::TYPE_VOIDP, # appId : LPCWSTR optional
Fiddle::TYPE_VOIDP, # userId : SID* optional
Fiddle::TYPE_VOIDP, # handle : void** out
],
Fiddle::TYPE_INT)#[link(name = "ndfapi")]
extern "system" {
fn NdfCreateWinSockIncident(
sock: usize, // SOCKET
host: *const u16, // LPCWSTR optional
port: u16, // WORD
appId: *const u16, // LPCWSTR optional
userId: *mut SID, // SID* optional
handle: *mut *mut () // void** out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NDFAPI.dll")]
public static extern int NdfCreateWinSockIncident(UIntPtr sock, [MarshalAs(UnmanagedType.LPWStr)] string host, ushort port, [MarshalAs(UnmanagedType.LPWStr)] string appId, IntPtr userId, IntPtr handle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NDFAPI_NdfCreateWinSockIncident' -Namespace Win32 -PassThru
# $api::NdfCreateWinSockIncident(sock, host, port, appId, userId, handle)#uselib "NDFAPI.dll"
#func global NdfCreateWinSockIncident "NdfCreateWinSockIncident" sptr, sptr, sptr, sptr, sptr, sptr
; NdfCreateWinSockIncident sock, host, port, appId, varptr(userId), handle ; 戻り値は stat
; sock : SOCKET -> "sptr"
; host : LPCWSTR optional -> "sptr"
; port : WORD -> "sptr"
; appId : LPCWSTR optional -> "sptr"
; userId : SID* optional -> "sptr"
; handle : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "NDFAPI.dll" #cfunc global NdfCreateWinSockIncident "NdfCreateWinSockIncident" sptr, wstr, int, wstr, var, sptr ; res = NdfCreateWinSockIncident(sock, host, port, appId, userId, handle) ; sock : SOCKET -> "sptr" ; host : LPCWSTR optional -> "wstr" ; port : WORD -> "int" ; appId : LPCWSTR optional -> "wstr" ; userId : SID* optional -> "var" ; handle : void** out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "NDFAPI.dll" #cfunc global NdfCreateWinSockIncident "NdfCreateWinSockIncident" sptr, wstr, int, wstr, sptr, sptr ; res = NdfCreateWinSockIncident(sock, host, port, appId, varptr(userId), handle) ; sock : SOCKET -> "sptr" ; host : LPCWSTR optional -> "wstr" ; port : WORD -> "int" ; appId : LPCWSTR optional -> "wstr" ; userId : SID* optional -> "sptr" ; handle : void** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT NdfCreateWinSockIncident(SOCKET sock, LPCWSTR host, WORD port, LPCWSTR appId, SID* userId, void** handle) #uselib "NDFAPI.dll" #cfunc global NdfCreateWinSockIncident "NdfCreateWinSockIncident" intptr, wstr, int, wstr, var, intptr ; res = NdfCreateWinSockIncident(sock, host, port, appId, userId, handle) ; sock : SOCKET -> "intptr" ; host : LPCWSTR optional -> "wstr" ; port : WORD -> "int" ; appId : LPCWSTR optional -> "wstr" ; userId : SID* optional -> "var" ; handle : void** out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT NdfCreateWinSockIncident(SOCKET sock, LPCWSTR host, WORD port, LPCWSTR appId, SID* userId, void** handle) #uselib "NDFAPI.dll" #cfunc global NdfCreateWinSockIncident "NdfCreateWinSockIncident" intptr, wstr, int, wstr, intptr, intptr ; res = NdfCreateWinSockIncident(sock, host, port, appId, varptr(userId), handle) ; sock : SOCKET -> "intptr" ; host : LPCWSTR optional -> "wstr" ; port : WORD -> "int" ; appId : LPCWSTR optional -> "wstr" ; userId : SID* optional -> "intptr" ; handle : void** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ndfapi = windows.NewLazySystemDLL("NDFAPI.dll")
procNdfCreateWinSockIncident = ndfapi.NewProc("NdfCreateWinSockIncident")
)
// sock (SOCKET), host (LPCWSTR optional), port (WORD), appId (LPCWSTR optional), userId (SID* optional), handle (void** out)
r1, _, err := procNdfCreateWinSockIncident.Call(
uintptr(sock),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(host))),
uintptr(port),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(appId))),
uintptr(userId),
uintptr(handle),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction NdfCreateWinSockIncident(
sock: NativeUInt; // SOCKET
host: PWideChar; // LPCWSTR optional
port: Word; // WORD
appId: PWideChar; // LPCWSTR optional
userId: Pointer; // SID* optional
handle: Pointer // void** out
): Integer; stdcall;
external 'NDFAPI.dll' name 'NdfCreateWinSockIncident';result := DllCall("NDFAPI\NdfCreateWinSockIncident"
, "UPtr", sock ; SOCKET
, "WStr", host ; LPCWSTR optional
, "UShort", port ; WORD
, "WStr", appId ; LPCWSTR optional
, "Ptr", userId ; SID* optional
, "Ptr", handle ; void** out
, "Int") ; return: HRESULT●NdfCreateWinSockIncident(sock, host, port, appId, userId, handle) = DLL("NDFAPI.dll", "int NdfCreateWinSockIncident(int, char*, int, char*, void*, void*)")
# 呼び出し: NdfCreateWinSockIncident(sock, host, port, appId, userId, handle)
# sock : SOCKET -> "int"
# host : LPCWSTR optional -> "char*"
# port : WORD -> "int"
# appId : LPCWSTR optional -> "char*"
# userId : SID* optional -> "void*"
# handle : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。