Win32 API 日本語リファレンス
ホームNetworking.WinSock › WSAAsyncSelect

WSAAsyncSelect

関数
ソケットのネットワークイベント通知をウィンドウメッセージで要求する。
DLLWS2_32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// WS2_32.dll
#include <windows.h>

INT WSAAsyncSelect(
    SOCKET s,
    HWND hWnd,
    DWORD wMsg,
    INT lEvent
);

パラメーター

名前方向
sSOCKETin
hWndHWNDin
wMsgDWORDin
lEventINTin

戻り値の型: INT

各言語での呼び出し定義

// WS2_32.dll
#include <windows.h>

INT WSAAsyncSelect(
    SOCKET s,
    HWND hWnd,
    DWORD wMsg,
    INT lEvent
);
[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern int WSAAsyncSelect(
    UIntPtr s,   // SOCKET
    IntPtr hWnd,   // HWND
    uint wMsg,   // DWORD
    int lEvent   // INT
);
<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSAAsyncSelect(
    s As UIntPtr,   ' SOCKET
    hWnd As IntPtr,   ' HWND
    wMsg As UInteger,   ' DWORD
    lEvent As Integer   ' INT
) As Integer
End Function
' s : SOCKET
' hWnd : HWND
' wMsg : DWORD
' lEvent : INT
Declare PtrSafe Function WSAAsyncSelect Lib "ws2_32" ( _
    ByVal s As LongPtr, _
    ByVal hWnd As LongPtr, _
    ByVal wMsg As Long, _
    ByVal lEvent As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WSAAsyncSelect = ctypes.windll.ws2_32.WSAAsyncSelect
WSAAsyncSelect.restype = ctypes.c_int
WSAAsyncSelect.argtypes = [
    ctypes.c_size_t,  # s : SOCKET
    wintypes.HANDLE,  # hWnd : HWND
    wintypes.DWORD,  # wMsg : DWORD
    ctypes.c_int,  # lEvent : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WS2_32.dll')
WSAAsyncSelect = Fiddle::Function.new(
  lib['WSAAsyncSelect'],
  [
    Fiddle::TYPE_UINTPTR_T,  # s : SOCKET
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    -Fiddle::TYPE_INT,  # wMsg : DWORD
    Fiddle::TYPE_INT,  # lEvent : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "ws2_32")]
extern "system" {
    fn WSAAsyncSelect(
        s: usize,  // SOCKET
        hWnd: *mut core::ffi::c_void,  // HWND
        wMsg: u32,  // DWORD
        lEvent: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern int WSAAsyncSelect(UIntPtr s, IntPtr hWnd, uint wMsg, int lEvent);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAAsyncSelect' -Namespace Win32 -PassThru
# $api::WSAAsyncSelect(s, hWnd, wMsg, lEvent)
#uselib "WS2_32.dll"
#func global WSAAsyncSelect "WSAAsyncSelect" sptr, sptr, sptr, sptr
; WSAAsyncSelect s, hWnd, wMsg, lEvent   ; 戻り値は stat
; s : SOCKET -> "sptr"
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "sptr"
; lEvent : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WS2_32.dll"
#cfunc global WSAAsyncSelect "WSAAsyncSelect" sptr, sptr, int, int
; res = WSAAsyncSelect(s, hWnd, wMsg, lEvent)
; s : SOCKET -> "sptr"
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "int"
; lEvent : INT -> "int"
; INT WSAAsyncSelect(SOCKET s, HWND hWnd, DWORD wMsg, INT lEvent)
#uselib "WS2_32.dll"
#cfunc global WSAAsyncSelect "WSAAsyncSelect" intptr, intptr, int, int
; res = WSAAsyncSelect(s, hWnd, wMsg, lEvent)
; s : SOCKET -> "intptr"
; hWnd : HWND -> "intptr"
; wMsg : DWORD -> "int"
; lEvent : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
	procWSAAsyncSelect = ws2_32.NewProc("WSAAsyncSelect")
)

// s (SOCKET), hWnd (HWND), wMsg (DWORD), lEvent (INT)
r1, _, err := procWSAAsyncSelect.Call(
	uintptr(s),
	uintptr(hWnd),
	uintptr(wMsg),
	uintptr(lEvent),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function WSAAsyncSelect(
  s: NativeUInt;   // SOCKET
  hWnd: THandle;   // HWND
  wMsg: DWORD;   // DWORD
  lEvent: Integer   // INT
): Integer; stdcall;
  external 'WS2_32.dll' name 'WSAAsyncSelect';
result := DllCall("WS2_32\WSAAsyncSelect"
    , "UPtr", s   ; SOCKET
    , "Ptr", hWnd   ; HWND
    , "UInt", wMsg   ; DWORD
    , "Int", lEvent   ; INT
    , "Int")   ; return: INT
●WSAAsyncSelect(s, hWnd, wMsg, lEvent) = DLL("WS2_32.dll", "int WSAAsyncSelect(int, void*, dword, int)")
# 呼び出し: WSAAsyncSelect(s, hWnd, wMsg, lEvent)
# s : SOCKET -> "int"
# hWnd : HWND -> "void*"
# wMsg : DWORD -> "dword"
# lEvent : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。