ホーム › Networking.WinHttp › WinHttpWebSocketShutdown
WinHttpWebSocketShutdown
関数WebSocket接続の送信方向を終了する。
シグネチャ
// WINHTTP.dll
#include <windows.h>
DWORD WinHttpWebSocketShutdown(
void* hWebSocket,
WORD usStatus,
void* pvReason, // optional
DWORD dwReasonLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWebSocket | void* | in | WebSocket へのハンドル。 注意 WinHttpWebSocketShutdown はこのハンドルを閉じません。ハンドルを閉じるには、hWebSocket が不要になった時点で WinHttpCloseHandle を呼び出してください。
|
| usStatus | WORD | in | クローズステータスコード。指定可能な値については WINHTTP_WEB_SOCKET_CLOSE_STATUS を参照してください。 |
| pvReason | void* | inoptional | クローズの詳細な理由。 |
| dwReasonLength | DWORD | in | pvReason の長さ(バイト単位)。 pvReason が NULL の場合、この値は 0 でなければなりません。この値は 0 から 123 の範囲内である必要があります。 |
戻り値の型: DWORD
公式ドキュメント
WebSocket サーバーにクローズフレームを送信して送信チャネルを閉じますが、受信チャネルは開いたままにします。
戻り値
解説(Remarks)
WinHttpWebSocketShutdown はクローズフレームを送信し、WebSocket 接続上でそれ以上データが送信されないようにします。受信チャネルは閉じません。接続を完全に閉じて以降の受信操作を行わせたくない場合は、WinHttpWebSocketClose を使用してください。
サーバーからのクローズフレームの受信(通常の受信操作を通じて)はアプリケーションの責任です。
WinHttpWebSocketShutdown を呼び出した後、アプリケーションがクローズフレームを自身で受信せずスタックに委任したい場合は、WinHttpWebSocketClose を呼び出すことができます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WINHTTP.dll
#include <windows.h>
DWORD WinHttpWebSocketShutdown(
void* hWebSocket,
WORD usStatus,
void* pvReason, // optional
DWORD dwReasonLength
);[DllImport("WINHTTP.dll", ExactSpelling = true)]
static extern uint WinHttpWebSocketShutdown(
IntPtr hWebSocket, // void*
ushort usStatus, // WORD
IntPtr pvReason, // void* optional
uint dwReasonLength // DWORD
);<DllImport("WINHTTP.dll", ExactSpelling:=True)>
Public Shared Function WinHttpWebSocketShutdown(
hWebSocket As IntPtr, ' void*
usStatus As UShort, ' WORD
pvReason As IntPtr, ' void* optional
dwReasonLength As UInteger ' DWORD
) As UInteger
End Function' hWebSocket : void*
' usStatus : WORD
' pvReason : void* optional
' dwReasonLength : DWORD
Declare PtrSafe Function WinHttpWebSocketShutdown Lib "winhttp" ( _
ByVal hWebSocket As LongPtr, _
ByVal usStatus As Integer, _
ByVal pvReason As LongPtr, _
ByVal dwReasonLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WinHttpWebSocketShutdown = ctypes.windll.winhttp.WinHttpWebSocketShutdown
WinHttpWebSocketShutdown.restype = wintypes.DWORD
WinHttpWebSocketShutdown.argtypes = [
ctypes.POINTER(None), # hWebSocket : void*
ctypes.c_ushort, # usStatus : WORD
ctypes.POINTER(None), # pvReason : void* optional
wintypes.DWORD, # dwReasonLength : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WINHTTP.dll')
WinHttpWebSocketShutdown = Fiddle::Function.new(
lib['WinHttpWebSocketShutdown'],
[
Fiddle::TYPE_VOIDP, # hWebSocket : void*
-Fiddle::TYPE_SHORT, # usStatus : WORD
Fiddle::TYPE_VOIDP, # pvReason : void* optional
-Fiddle::TYPE_INT, # dwReasonLength : DWORD
],
-Fiddle::TYPE_INT)#[link(name = "winhttp")]
extern "system" {
fn WinHttpWebSocketShutdown(
hWebSocket: *mut (), // void*
usStatus: u16, // WORD
pvReason: *mut (), // void* optional
dwReasonLength: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WINHTTP.dll")]
public static extern uint WinHttpWebSocketShutdown(IntPtr hWebSocket, ushort usStatus, IntPtr pvReason, uint dwReasonLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINHTTP_WinHttpWebSocketShutdown' -Namespace Win32 -PassThru
# $api::WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength)#uselib "WINHTTP.dll"
#func global WinHttpWebSocketShutdown "WinHttpWebSocketShutdown" sptr, sptr, sptr, sptr
; WinHttpWebSocketShutdown hWebSocket, usStatus, pvReason, dwReasonLength ; 戻り値は stat
; hWebSocket : void* -> "sptr"
; usStatus : WORD -> "sptr"
; pvReason : void* optional -> "sptr"
; dwReasonLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WINHTTP.dll"
#cfunc global WinHttpWebSocketShutdown "WinHttpWebSocketShutdown" sptr, int, sptr, int
; res = WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength)
; hWebSocket : void* -> "sptr"
; usStatus : WORD -> "int"
; pvReason : void* optional -> "sptr"
; dwReasonLength : DWORD -> "int"; DWORD WinHttpWebSocketShutdown(void* hWebSocket, WORD usStatus, void* pvReason, DWORD dwReasonLength)
#uselib "WINHTTP.dll"
#cfunc global WinHttpWebSocketShutdown "WinHttpWebSocketShutdown" intptr, int, intptr, int
; res = WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength)
; hWebSocket : void* -> "intptr"
; usStatus : WORD -> "int"
; pvReason : void* optional -> "intptr"
; dwReasonLength : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winhttp = windows.NewLazySystemDLL("WINHTTP.dll")
procWinHttpWebSocketShutdown = winhttp.NewProc("WinHttpWebSocketShutdown")
)
// hWebSocket (void*), usStatus (WORD), pvReason (void* optional), dwReasonLength (DWORD)
r1, _, err := procWinHttpWebSocketShutdown.Call(
uintptr(hWebSocket),
uintptr(usStatus),
uintptr(pvReason),
uintptr(dwReasonLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction WinHttpWebSocketShutdown(
hWebSocket: Pointer; // void*
usStatus: Word; // WORD
pvReason: Pointer; // void* optional
dwReasonLength: DWORD // DWORD
): DWORD; stdcall;
external 'WINHTTP.dll' name 'WinHttpWebSocketShutdown';result := DllCall("WINHTTP\WinHttpWebSocketShutdown"
, "Ptr", hWebSocket ; void*
, "UShort", usStatus ; WORD
, "Ptr", pvReason ; void* optional
, "UInt", dwReasonLength ; DWORD
, "UInt") ; return: DWORD●WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength) = DLL("WINHTTP.dll", "dword WinHttpWebSocketShutdown(void*, int, void*, dword)")
# 呼び出し: WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength)
# hWebSocket : void* -> "void*"
# usStatus : WORD -> "int"
# pvReason : void* optional -> "void*"
# dwReasonLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winhttp" fn WinHttpWebSocketShutdown(
hWebSocket: ?*anyopaque, // void*
usStatus: u16, // WORD
pvReason: ?*anyopaque, // void* optional
dwReasonLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;proc WinHttpWebSocketShutdown(
hWebSocket: pointer, # void*
usStatus: uint16, # WORD
pvReason: pointer, # void* optional
dwReasonLength: uint32 # DWORD
): uint32 {.importc: "WinHttpWebSocketShutdown", stdcall, dynlib: "WINHTTP.dll".}pragma(lib, "winhttp");
extern(Windows)
uint WinHttpWebSocketShutdown(
void* hWebSocket, // void*
ushort usStatus, // WORD
void* pvReason, // void* optional
uint dwReasonLength // DWORD
);ccall((:WinHttpWebSocketShutdown, "WINHTTP.dll"), stdcall, UInt32,
(Ptr{Cvoid}, UInt16, Ptr{Cvoid}, UInt32),
hWebSocket, usStatus, pvReason, dwReasonLength)
# hWebSocket : void* -> Ptr{Cvoid}
# usStatus : WORD -> UInt16
# pvReason : void* optional -> Ptr{Cvoid}
# dwReasonLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t WinHttpWebSocketShutdown(
void* hWebSocket,
uint16_t usStatus,
void* pvReason,
uint32_t dwReasonLength);
]]
local winhttp = ffi.load("winhttp")
-- winhttp.WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength)
-- hWebSocket : void*
-- usStatus : WORD
-- pvReason : void* optional
-- dwReasonLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WINHTTP.dll');
const WinHttpWebSocketShutdown = lib.func('__stdcall', 'WinHttpWebSocketShutdown', 'uint32_t', ['void *', 'uint16_t', 'void *', 'uint32_t']);
// WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength)
// hWebSocket : void* -> 'void *'
// usStatus : WORD -> 'uint16_t'
// pvReason : void* optional -> 'void *'
// dwReasonLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WINHTTP.dll", {
WinHttpWebSocketShutdown: { parameters: ["pointer", "u16", "pointer", "u32"], result: "u32" },
});
// lib.symbols.WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength)
// hWebSocket : void* -> "pointer"
// usStatus : WORD -> "u16"
// pvReason : void* optional -> "pointer"
// dwReasonLength : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t WinHttpWebSocketShutdown(
void* hWebSocket,
uint16_t usStatus,
void* pvReason,
uint32_t dwReasonLength);
C, "WINHTTP.dll");
// $ffi->WinHttpWebSocketShutdown(hWebSocket, usStatus, pvReason, dwReasonLength);
// hWebSocket : void*
// usStatus : WORD
// pvReason : void* optional
// dwReasonLength : DWORD
// 構造体/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 Winhttp extends StdCallLibrary {
Winhttp INSTANCE = Native.load("winhttp", Winhttp.class);
int WinHttpWebSocketShutdown(
Pointer hWebSocket, // void*
short usStatus, // WORD
Pointer pvReason, // void* optional
int dwReasonLength // DWORD
);
}@[Link("winhttp")]
lib LibWINHTTP
fun WinHttpWebSocketShutdown = WinHttpWebSocketShutdown(
hWebSocket : Void*, # void*
usStatus : UInt16, # WORD
pvReason : Void*, # void* optional
dwReasonLength : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WinHttpWebSocketShutdownNative = Uint32 Function(Pointer<Void>, Uint16, Pointer<Void>, Uint32);
typedef WinHttpWebSocketShutdownDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final WinHttpWebSocketShutdown = DynamicLibrary.open('WINHTTP.dll')
.lookupFunction<WinHttpWebSocketShutdownNative, WinHttpWebSocketShutdownDart>('WinHttpWebSocketShutdown');
// hWebSocket : void* -> Pointer<Void>
// usStatus : WORD -> Uint16
// pvReason : void* optional -> Pointer<Void>
// dwReasonLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WinHttpWebSocketShutdown(
hWebSocket: Pointer; // void*
usStatus: Word; // WORD
pvReason: Pointer; // void* optional
dwReasonLength: DWORD // DWORD
): DWORD; stdcall;
external 'WINHTTP.dll' name 'WinHttpWebSocketShutdown';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WinHttpWebSocketShutdown"
c_WinHttpWebSocketShutdown :: Ptr () -> Word16 -> Ptr () -> Word32 -> IO Word32
-- hWebSocket : void* -> Ptr ()
-- usStatus : WORD -> Word16
-- pvReason : void* optional -> Ptr ()
-- dwReasonLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let winhttpwebsocketshutdown =
foreign "WinHttpWebSocketShutdown"
((ptr void) @-> uint16_t @-> (ptr void) @-> uint32_t @-> returning uint32_t)
(* hWebSocket : void* -> (ptr void) *)
(* usStatus : WORD -> uint16_t *)
(* pvReason : void* optional -> (ptr void) *)
(* dwReasonLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winhttp (t "WINHTTP.dll"))
(cffi:use-foreign-library winhttp)
(cffi:defcfun ("WinHttpWebSocketShutdown" win-http-web-socket-shutdown :convention :stdcall) :uint32
(h-web-socket :pointer) ; void*
(us-status :uint16) ; WORD
(pv-reason :pointer) ; void* optional
(dw-reason-length :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WinHttpWebSocketShutdown = Win32::API::More->new('WINHTTP',
'DWORD WinHttpWebSocketShutdown(LPVOID hWebSocket, WORD usStatus, LPVOID pvReason, DWORD dwReasonLength)');
# my $ret = $WinHttpWebSocketShutdown->Call($hWebSocket, $usStatus, $pvReason, $dwReasonLength);
# hWebSocket : void* -> LPVOID
# usStatus : WORD -> WORD
# pvReason : void* optional -> LPVOID
# dwReasonLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- e WINHTTP_WEB_SOCKET_CLOSE_STATUS
- f WinHttpCloseHandle — WinHTTPハンドルを閉じてリソースを解放する。
- f WinHttpWebSocketClose — WebSocket接続を閉じる。