ホーム › Networking.WinSock › WSARemoveServiceClass
WSARemoveServiceClass
関数指定したサービスクラスを登録解除する。
シグネチャ
// WS2_32.dll
#include <windows.h>
INT WSARemoveServiceClass(
GUID* lpServiceClassId
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpServiceClassId | GUID* | in | 削除するサービスクラスの GUID へのポインター。 |
戻り値の型: INT
公式ドキュメント
WSARemoveServiceClass 関数は、レジストリからサービスクラススキーマを永続的に削除します。
戻り値
操作が成功した場合、戻り値は 0 です。それ以外の場合は SOCKET_ERROR が返され、 WSAGetLastError を呼び出すことで特定のエラー番号を取得できます。
| エラーコード | 意味 |
|---|---|
| 指定されたクラスが見つかりませんでした。 | |
| 呼び出し元のルーチンには、このサービスを削除するための十分な権限がありません。 | |
| このクラスをまだ参照しているサービスインスタンスが存在します。現時点ではこのクラスを削除できません。 | |
| WS2_32.DLL が初期化されていません。アプリケーションは、いずれかの Windows Sockets 関数を呼び出す前に、まず WSAStartup を呼び出す必要があります。 | |
| 指定された GUID が無効でした。 | |
| 操作を実行するのに十分なメモリがありませんでした。 |
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WS2_32.dll
#include <windows.h>
INT WSARemoveServiceClass(
GUID* lpServiceClassId
);[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern int WSARemoveServiceClass(
ref Guid lpServiceClassId // GUID*
);<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSARemoveServiceClass(
ByRef lpServiceClassId As Guid ' GUID*
) As Integer
End Function' lpServiceClassId : GUID*
Declare PtrSafe Function WSARemoveServiceClass Lib "ws2_32" ( _
ByVal lpServiceClassId As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSARemoveServiceClass = ctypes.windll.ws2_32.WSARemoveServiceClass
WSARemoveServiceClass.restype = ctypes.c_int
WSARemoveServiceClass.argtypes = [
ctypes.c_void_p, # lpServiceClassId : GUID*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
WSARemoveServiceClass = Fiddle::Function.new(
lib['WSARemoveServiceClass'],
[
Fiddle::TYPE_VOIDP, # lpServiceClassId : GUID*
],
Fiddle::TYPE_INT)#[link(name = "ws2_32")]
extern "system" {
fn WSARemoveServiceClass(
lpServiceClassId: *mut GUID // GUID*
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern int WSARemoveServiceClass(ref Guid lpServiceClassId);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSARemoveServiceClass' -Namespace Win32 -PassThru
# $api::WSARemoveServiceClass(lpServiceClassId)#uselib "WS2_32.dll"
#func global WSARemoveServiceClass "WSARemoveServiceClass" sptr
; WSARemoveServiceClass varptr(lpServiceClassId) ; 戻り値は stat
; lpServiceClassId : GUID* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WS2_32.dll" #cfunc global WSARemoveServiceClass "WSARemoveServiceClass" var ; res = WSARemoveServiceClass(lpServiceClassId) ; lpServiceClassId : GUID* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WS2_32.dll" #cfunc global WSARemoveServiceClass "WSARemoveServiceClass" sptr ; res = WSARemoveServiceClass(varptr(lpServiceClassId)) ; lpServiceClassId : GUID* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT WSARemoveServiceClass(GUID* lpServiceClassId) #uselib "WS2_32.dll" #cfunc global WSARemoveServiceClass "WSARemoveServiceClass" var ; res = WSARemoveServiceClass(lpServiceClassId) ; lpServiceClassId : GUID* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT WSARemoveServiceClass(GUID* lpServiceClassId) #uselib "WS2_32.dll" #cfunc global WSARemoveServiceClass "WSARemoveServiceClass" intptr ; res = WSARemoveServiceClass(varptr(lpServiceClassId)) ; lpServiceClassId : GUID* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procWSARemoveServiceClass = ws2_32.NewProc("WSARemoveServiceClass")
)
// lpServiceClassId (GUID*)
r1, _, err := procWSARemoveServiceClass.Call(
uintptr(lpServiceClassId),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction WSARemoveServiceClass(
lpServiceClassId: PGUID // GUID*
): Integer; stdcall;
external 'WS2_32.dll' name 'WSARemoveServiceClass';result := DllCall("WS2_32\WSARemoveServiceClass"
, "Ptr", lpServiceClassId ; GUID*
, "Int") ; return: INT●WSARemoveServiceClass(lpServiceClassId) = DLL("WS2_32.dll", "int WSARemoveServiceClass(void*)")
# 呼び出し: WSARemoveServiceClass(lpServiceClassId)
# lpServiceClassId : GUID* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ws2_32" fn WSARemoveServiceClass(
lpServiceClassId: [*c]GUID // GUID*
) callconv(std.os.windows.WINAPI) i32;proc WSARemoveServiceClass(
lpServiceClassId: ptr GUID # GUID*
): int32 {.importc: "WSARemoveServiceClass", stdcall, dynlib: "WS2_32.dll".}pragma(lib, "ws2_32");
extern(Windows)
int WSARemoveServiceClass(
GUID* lpServiceClassId // GUID*
);ccall((:WSARemoveServiceClass, "WS2_32.dll"), stdcall, Int32,
(Ptr{GUID},),
lpServiceClassId)
# lpServiceClassId : GUID* -> Ptr{GUID}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WSARemoveServiceClass(
void* lpServiceClassId);
]]
local ws2_32 = ffi.load("ws2_32")
-- ws2_32.WSARemoveServiceClass(lpServiceClassId)
-- lpServiceClassId : GUID*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WS2_32.dll');
const WSARemoveServiceClass = lib.func('__stdcall', 'WSARemoveServiceClass', 'int32_t', ['void *']);
// WSARemoveServiceClass(lpServiceClassId)
// lpServiceClassId : GUID* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WS2_32.dll", {
WSARemoveServiceClass: { parameters: ["pointer"], result: "i32" },
});
// lib.symbols.WSARemoveServiceClass(lpServiceClassId)
// lpServiceClassId : GUID* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WSARemoveServiceClass(
void* lpServiceClassId);
C, "WS2_32.dll");
// $ffi->WSARemoveServiceClass(lpServiceClassId);
// lpServiceClassId : GUID*
// 構造体/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 Ws2_32 extends StdCallLibrary {
Ws2_32 INSTANCE = Native.load("ws2_32", Ws2_32.class);
int WSARemoveServiceClass(
Pointer lpServiceClassId // GUID*
);
}@[Link("ws2_32")]
lib LibWS2_32
fun WSARemoveServiceClass = WSARemoveServiceClass(
lpServiceClassId : GUID* # GUID*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WSARemoveServiceClassNative = Int32 Function(Pointer<Void>);
typedef WSARemoveServiceClassDart = int Function(Pointer<Void>);
final WSARemoveServiceClass = DynamicLibrary.open('WS2_32.dll')
.lookupFunction<WSARemoveServiceClassNative, WSARemoveServiceClassDart>('WSARemoveServiceClass');
// lpServiceClassId : GUID* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WSARemoveServiceClass(
lpServiceClassId: PGUID // GUID*
): Integer; stdcall;
external 'WS2_32.dll' name 'WSARemoveServiceClass';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WSARemoveServiceClass"
c_WSARemoveServiceClass :: Ptr () -> IO Int32
-- lpServiceClassId : GUID* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wsaremoveserviceclass =
foreign "WSARemoveServiceClass"
((ptr void) @-> returning int32_t)
(* lpServiceClassId : GUID* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ws2_32 (t "WS2_32.dll"))
(cffi:use-foreign-library ws2_32)
(cffi:defcfun ("WSARemoveServiceClass" wsaremove-service-class :convention :stdcall) :int32
(lp-service-class-id :pointer)) ; GUID*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WSARemoveServiceClass = Win32::API::More->new('WS2_32',
'int WSARemoveServiceClass(LPVOID lpServiceClassId)');
# my $ret = $WSARemoveServiceClass->Call($lpServiceClassId);
# lpServiceClassId : GUID* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f WSAGetLastError — 直前のソケット操作のエラーコードを取得する。
- f WSAStartup — Winsock DLLの使用を初期化し利用を開始する。