ホーム › Networking.WinSock › WSAGetLastError
WSAGetLastError
関数直前のソケット操作のエラーコードを取得する。
シグネチャ
// WS2_32.dll
#include <windows.h>
WSA_ERROR WSAGetLastError(void);パラメーターなし。戻り値: WSA_ERROR
各言語での呼び出し定義
// WS2_32.dll
#include <windows.h>
WSA_ERROR WSAGetLastError(void);[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern int WSAGetLastError();<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSAGetLastError() As Integer
End FunctionDeclare PtrSafe Function WSAGetLastError Lib "ws2_32" () As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSAGetLastError = ctypes.windll.ws2_32.WSAGetLastError
WSAGetLastError.restype = ctypes.c_int
WSAGetLastError.argtypes = []
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
WSAGetLastError = Fiddle::Function.new(
lib['WSAGetLastError'],
[],
Fiddle::TYPE_INT)#[link(name = "ws2_32")]
extern "system" {
fn WSAGetLastError() -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern int WSAGetLastError();
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAGetLastError' -Namespace Win32 -PassThru
# $api::WSAGetLastError()#uselib "WS2_32.dll"
#func global WSAGetLastError "WSAGetLastError"
; WSAGetLastError ; 戻り値は stat
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WS2_32.dll"
#cfunc global WSAGetLastError "WSAGetLastError"
; res = WSAGetLastError(); WSA_ERROR WSAGetLastError()
#uselib "WS2_32.dll"
#cfunc global WSAGetLastError "WSAGetLastError"
; res = WSAGetLastError()import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procWSAGetLastError = ws2_32.NewProc("WSAGetLastError")
)
r1, _, err := procWSAGetLastError.Call()
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WSA_ERRORfunction WSAGetLastError: Integer; stdcall;
external 'WS2_32.dll' name 'WSAGetLastError';result := DllCall("WS2_32\WSAGetLastError", "Int")●WSAGetLastError() = DLL("WS2_32.dll", "int WSAGetLastError()")
# 呼び出し: WSAGetLastError()
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。