ホーム › Networking.WinSock › WSASend
WSASend
関数接続済みソケットへデータを送信する。
シグネチャ
// WS2_32.dll
#include <windows.h>
INT WSASend(
SOCKET s,
WSABUF* lpBuffers,
DWORD dwBufferCount,
DWORD* lpNumberOfBytesSent, // optional
DWORD dwFlags,
OVERLAPPED* lpOverlapped, // optional
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| s | SOCKET | in |
| lpBuffers | WSABUF* | in |
| dwBufferCount | DWORD | in |
| lpNumberOfBytesSent | DWORD* | outoptional |
| dwFlags | DWORD | in |
| lpOverlapped | OVERLAPPED* | inoutoptional |
| lpCompletionRoutine | LPWSAOVERLAPPED_COMPLETION_ROUTINE | inoptional |
戻り値の型: INT
各言語での呼び出し定義
// WS2_32.dll
#include <windows.h>
INT WSASend(
SOCKET s,
WSABUF* lpBuffers,
DWORD dwBufferCount,
DWORD* lpNumberOfBytesSent, // optional
DWORD dwFlags,
OVERLAPPED* lpOverlapped, // optional
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // optional
);[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern int WSASend(
UIntPtr s, // SOCKET
IntPtr lpBuffers, // WSABUF*
uint dwBufferCount, // DWORD
IntPtr lpNumberOfBytesSent, // DWORD* optional, out
uint dwFlags, // DWORD
IntPtr lpOverlapped, // OVERLAPPED* optional, in/out
IntPtr lpCompletionRoutine // LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
);<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSASend(
s As UIntPtr, ' SOCKET
lpBuffers As IntPtr, ' WSABUF*
dwBufferCount As UInteger, ' DWORD
lpNumberOfBytesSent As IntPtr, ' DWORD* optional, out
dwFlags As UInteger, ' DWORD
lpOverlapped As IntPtr, ' OVERLAPPED* optional, in/out
lpCompletionRoutine As IntPtr ' LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
) As Integer
End Function' s : SOCKET
' lpBuffers : WSABUF*
' dwBufferCount : DWORD
' lpNumberOfBytesSent : DWORD* optional, out
' dwFlags : DWORD
' lpOverlapped : OVERLAPPED* optional, in/out
' lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
Declare PtrSafe Function WSASend Lib "ws2_32" ( _
ByVal s As LongPtr, _
ByVal lpBuffers As LongPtr, _
ByVal dwBufferCount As Long, _
ByVal lpNumberOfBytesSent As LongPtr, _
ByVal dwFlags As Long, _
ByVal lpOverlapped As LongPtr, _
ByVal lpCompletionRoutine As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSASend = ctypes.windll.ws2_32.WSASend
WSASend.restype = ctypes.c_int
WSASend.argtypes = [
ctypes.c_size_t, # s : SOCKET
ctypes.c_void_p, # lpBuffers : WSABUF*
wintypes.DWORD, # dwBufferCount : DWORD
ctypes.POINTER(wintypes.DWORD), # lpNumberOfBytesSent : DWORD* optional, out
wintypes.DWORD, # dwFlags : DWORD
ctypes.c_void_p, # lpOverlapped : OVERLAPPED* optional, in/out
ctypes.c_void_p, # lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
WSASend = Fiddle::Function.new(
lib['WSASend'],
[
Fiddle::TYPE_UINTPTR_T, # s : SOCKET
Fiddle::TYPE_VOIDP, # lpBuffers : WSABUF*
-Fiddle::TYPE_INT, # dwBufferCount : DWORD
Fiddle::TYPE_VOIDP, # lpNumberOfBytesSent : DWORD* optional, out
-Fiddle::TYPE_INT, # dwFlags : DWORD
Fiddle::TYPE_VOIDP, # lpOverlapped : OVERLAPPED* optional, in/out
Fiddle::TYPE_VOIDP, # lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
],
Fiddle::TYPE_INT)#[link(name = "ws2_32")]
extern "system" {
fn WSASend(
s: usize, // SOCKET
lpBuffers: *mut WSABUF, // WSABUF*
dwBufferCount: u32, // DWORD
lpNumberOfBytesSent: *mut u32, // DWORD* optional, out
dwFlags: u32, // DWORD
lpOverlapped: *mut OVERLAPPED, // OVERLAPPED* optional, in/out
lpCompletionRoutine: *const core::ffi::c_void // LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern int WSASend(UIntPtr s, IntPtr lpBuffers, uint dwBufferCount, IntPtr lpNumberOfBytesSent, uint dwFlags, IntPtr lpOverlapped, IntPtr lpCompletionRoutine);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSASend' -Namespace Win32 -PassThru
# $api::WSASend(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine)#uselib "WS2_32.dll"
#func global WSASend "WSASend" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WSASend s, varptr(lpBuffers), dwBufferCount, varptr(lpNumberOfBytesSent), dwFlags, varptr(lpOverlapped), lpCompletionRoutine ; 戻り値は stat
; s : SOCKET -> "sptr"
; lpBuffers : WSABUF* -> "sptr"
; dwBufferCount : DWORD -> "sptr"
; lpNumberOfBytesSent : DWORD* optional, out -> "sptr"
; dwFlags : DWORD -> "sptr"
; lpOverlapped : OVERLAPPED* optional, in/out -> "sptr"
; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WS2_32.dll" #cfunc global WSASend "WSASend" sptr, var, int, var, int, var, sptr ; res = WSASend(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine) ; s : SOCKET -> "sptr" ; lpBuffers : WSABUF* -> "var" ; dwBufferCount : DWORD -> "int" ; lpNumberOfBytesSent : DWORD* optional, out -> "var" ; dwFlags : DWORD -> "int" ; lpOverlapped : OVERLAPPED* optional, in/out -> "var" ; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WS2_32.dll" #cfunc global WSASend "WSASend" sptr, sptr, int, sptr, int, sptr, sptr ; res = WSASend(s, varptr(lpBuffers), dwBufferCount, varptr(lpNumberOfBytesSent), dwFlags, varptr(lpOverlapped), lpCompletionRoutine) ; s : SOCKET -> "sptr" ; lpBuffers : WSABUF* -> "sptr" ; dwBufferCount : DWORD -> "int" ; lpNumberOfBytesSent : DWORD* optional, out -> "sptr" ; dwFlags : DWORD -> "int" ; lpOverlapped : OVERLAPPED* optional, in/out -> "sptr" ; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT WSASend(SOCKET s, WSABUF* lpBuffers, DWORD dwBufferCount, DWORD* lpNumberOfBytesSent, DWORD dwFlags, OVERLAPPED* lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) #uselib "WS2_32.dll" #cfunc global WSASend "WSASend" intptr, var, int, var, int, var, intptr ; res = WSASend(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine) ; s : SOCKET -> "intptr" ; lpBuffers : WSABUF* -> "var" ; dwBufferCount : DWORD -> "int" ; lpNumberOfBytesSent : DWORD* optional, out -> "var" ; dwFlags : DWORD -> "int" ; lpOverlapped : OVERLAPPED* optional, in/out -> "var" ; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT WSASend(SOCKET s, WSABUF* lpBuffers, DWORD dwBufferCount, DWORD* lpNumberOfBytesSent, DWORD dwFlags, OVERLAPPED* lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) #uselib "WS2_32.dll" #cfunc global WSASend "WSASend" intptr, intptr, int, intptr, int, intptr, intptr ; res = WSASend(s, varptr(lpBuffers), dwBufferCount, varptr(lpNumberOfBytesSent), dwFlags, varptr(lpOverlapped), lpCompletionRoutine) ; s : SOCKET -> "intptr" ; lpBuffers : WSABUF* -> "intptr" ; dwBufferCount : DWORD -> "int" ; lpNumberOfBytesSent : DWORD* optional, out -> "intptr" ; dwFlags : DWORD -> "int" ; lpOverlapped : OVERLAPPED* optional, in/out -> "intptr" ; lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procWSASend = ws2_32.NewProc("WSASend")
)
// s (SOCKET), lpBuffers (WSABUF*), dwBufferCount (DWORD), lpNumberOfBytesSent (DWORD* optional, out), dwFlags (DWORD), lpOverlapped (OVERLAPPED* optional, in/out), lpCompletionRoutine (LPWSAOVERLAPPED_COMPLETION_ROUTINE optional)
r1, _, err := procWSASend.Call(
uintptr(s),
uintptr(lpBuffers),
uintptr(dwBufferCount),
uintptr(lpNumberOfBytesSent),
uintptr(dwFlags),
uintptr(lpOverlapped),
uintptr(lpCompletionRoutine),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction WSASend(
s: NativeUInt; // SOCKET
lpBuffers: Pointer; // WSABUF*
dwBufferCount: DWORD; // DWORD
lpNumberOfBytesSent: Pointer; // DWORD* optional, out
dwFlags: DWORD; // DWORD
lpOverlapped: Pointer; // OVERLAPPED* optional, in/out
lpCompletionRoutine: Pointer // LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
): Integer; stdcall;
external 'WS2_32.dll' name 'WSASend';result := DllCall("WS2_32\WSASend"
, "UPtr", s ; SOCKET
, "Ptr", lpBuffers ; WSABUF*
, "UInt", dwBufferCount ; DWORD
, "Ptr", lpNumberOfBytesSent ; DWORD* optional, out
, "UInt", dwFlags ; DWORD
, "Ptr", lpOverlapped ; OVERLAPPED* optional, in/out
, "Ptr", lpCompletionRoutine ; LPWSAOVERLAPPED_COMPLETION_ROUTINE optional
, "Int") ; return: INT●WSASend(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine) = DLL("WS2_32.dll", "int WSASend(int, void*, dword, void*, dword, void*, void*)")
# 呼び出し: WSASend(s, lpBuffers, dwBufferCount, lpNumberOfBytesSent, dwFlags, lpOverlapped, lpCompletionRoutine)
# s : SOCKET -> "int"
# lpBuffers : WSABUF* -> "void*"
# dwBufferCount : DWORD -> "dword"
# lpNumberOfBytesSent : DWORD* optional, out -> "void*"
# dwFlags : DWORD -> "dword"
# lpOverlapped : OVERLAPPED* optional, in/out -> "void*"
# lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。