ホーム › Networking.WinSock › WSAInstallServiceClassW
WSAInstallServiceClassW
関数新しいサービスクラス情報を登録する。
シグネチャ
// WS2_32.dll (Unicode / -W)
#include <windows.h>
INT WSAInstallServiceClassW(
WSASERVICECLASSINFOW* lpServiceClassInfo
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpServiceClassInfo | WSASERVICECLASSINFOW* | in | サービスクラスから名前空間固有の型へのマッピング情報です。一度に複数のマッピングを処理できます。 関連するデータ構造の説明については、 サービスクラスのデータ構造 のセクションを参照してください。 |
戻り値の型: INT
公式ドキュメント
WSAInstallServiceClass 関数は、名前空間内にサービスクラススキーマを登録します。(Unicode)
戻り値
操作が成功した場合、戻り値は 0 です。それ以外の場合は SOCKET_ERROR が返され、 WSAGetLastError を呼び出すことで具体的なエラー番号を取得できます。
| エラーコード | 意味 |
|---|---|
| 名前空間プロバイダーが、要求されたクラス情報を提供できません。 | |
| 操作を実行するためのメモリが不足していました。 | |
| 呼び出し元の関数に、サービスをインストールするための十分な権限がありません。 | |
| このサービスクラス識別子に対するサービスクラス情報は、すでに登録されています。サービスクラス情報を変更するには、まず WSARemoveServiceClass を使用し、その後、更新したクラス情報データで再インストールしてください。 | |
| サービスクラス情報が無効、または不適切に構成されていました。このエラーは、lpServiceClassInfo パラメーターが NULL の場合に返されます。 | |
| 操作はサポートされていません。このエラーは、名前空間プロバイダーがこの関数を実装していない場合に返されます。 | |
| 要求された名前は有効ですが、要求された型のデータが見つかりませんでした。 | |
| WS2_32.DLL が初期化されていません。アプリケーションは、Windows Sockets の関数を呼び出す前に、まず WSAStartup を呼び出す必要があります。 |
解説(Remarks)
メモ
winsock2.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして WSAInstallServiceClass を定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則 を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 (Unicode / -W)
#include <windows.h>
INT WSAInstallServiceClassW(
WSASERVICECLASSINFOW* lpServiceClassInfo
);[DllImport("WS2_32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern int WSAInstallServiceClassW(
IntPtr lpServiceClassInfo // WSASERVICECLASSINFOW*
);<DllImport("WS2_32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSAInstallServiceClassW(
lpServiceClassInfo As IntPtr ' WSASERVICECLASSINFOW*
) As Integer
End Function' lpServiceClassInfo : WSASERVICECLASSINFOW*
Declare PtrSafe Function WSAInstallServiceClassW Lib "ws2_32" ( _
ByVal lpServiceClassInfo As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSAInstallServiceClassW = ctypes.windll.ws2_32.WSAInstallServiceClassW
WSAInstallServiceClassW.restype = ctypes.c_int
WSAInstallServiceClassW.argtypes = [
ctypes.c_void_p, # lpServiceClassInfo : WSASERVICECLASSINFOW*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
WSAInstallServiceClassW = Fiddle::Function.new(
lib['WSAInstallServiceClassW'],
[
Fiddle::TYPE_VOIDP, # lpServiceClassInfo : WSASERVICECLASSINFOW*
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "ws2_32")]
extern "system" {
fn WSAInstallServiceClassW(
lpServiceClassInfo: *mut WSASERVICECLASSINFOW // WSASERVICECLASSINFOW*
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int WSAInstallServiceClassW(IntPtr lpServiceClassInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAInstallServiceClassW' -Namespace Win32 -PassThru
# $api::WSAInstallServiceClassW(lpServiceClassInfo)#uselib "WS2_32.dll"
#func global WSAInstallServiceClassW "WSAInstallServiceClassW" wptr
; WSAInstallServiceClassW varptr(lpServiceClassInfo) ; 戻り値は stat
; lpServiceClassInfo : WSASERVICECLASSINFOW* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WS2_32.dll" #cfunc global WSAInstallServiceClassW "WSAInstallServiceClassW" var ; res = WSAInstallServiceClassW(lpServiceClassInfo) ; lpServiceClassInfo : WSASERVICECLASSINFOW* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WS2_32.dll" #cfunc global WSAInstallServiceClassW "WSAInstallServiceClassW" sptr ; res = WSAInstallServiceClassW(varptr(lpServiceClassInfo)) ; lpServiceClassInfo : WSASERVICECLASSINFOW* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT WSAInstallServiceClassW(WSASERVICECLASSINFOW* lpServiceClassInfo) #uselib "WS2_32.dll" #cfunc global WSAInstallServiceClassW "WSAInstallServiceClassW" var ; res = WSAInstallServiceClassW(lpServiceClassInfo) ; lpServiceClassInfo : WSASERVICECLASSINFOW* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT WSAInstallServiceClassW(WSASERVICECLASSINFOW* lpServiceClassInfo) #uselib "WS2_32.dll" #cfunc global WSAInstallServiceClassW "WSAInstallServiceClassW" intptr ; res = WSAInstallServiceClassW(varptr(lpServiceClassInfo)) ; lpServiceClassInfo : WSASERVICECLASSINFOW* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procWSAInstallServiceClassW = ws2_32.NewProc("WSAInstallServiceClassW")
)
// lpServiceClassInfo (WSASERVICECLASSINFOW*)
r1, _, err := procWSAInstallServiceClassW.Call(
uintptr(lpServiceClassInfo),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction WSAInstallServiceClassW(
lpServiceClassInfo: Pointer // WSASERVICECLASSINFOW*
): Integer; stdcall;
external 'WS2_32.dll' name 'WSAInstallServiceClassW';result := DllCall("WS2_32\WSAInstallServiceClassW"
, "Ptr", lpServiceClassInfo ; WSASERVICECLASSINFOW*
, "Int") ; return: INT●WSAInstallServiceClassW(lpServiceClassInfo) = DLL("WS2_32.dll", "int WSAInstallServiceClassW(void*)")
# 呼び出し: WSAInstallServiceClassW(lpServiceClassInfo)
# lpServiceClassInfo : WSASERVICECLASSINFOW* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "ws2_32" fn WSAInstallServiceClassW(
lpServiceClassInfo: [*c]WSASERVICECLASSINFOW // WSASERVICECLASSINFOW*
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc WSAInstallServiceClassW(
lpServiceClassInfo: ptr WSASERVICECLASSINFOW # WSASERVICECLASSINFOW*
): int32 {.importc: "WSAInstallServiceClassW", stdcall, dynlib: "WS2_32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "ws2_32");
extern(Windows)
int WSAInstallServiceClassW(
WSASERVICECLASSINFOW* lpServiceClassInfo // WSASERVICECLASSINFOW*
);ccall((:WSAInstallServiceClassW, "WS2_32.dll"), stdcall, Int32,
(Ptr{WSASERVICECLASSINFOW},),
lpServiceClassInfo)
# lpServiceClassInfo : WSASERVICECLASSINFOW* -> Ptr{WSASERVICECLASSINFOW}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t WSAInstallServiceClassW(
void* lpServiceClassInfo);
]]
local ws2_32 = ffi.load("ws2_32")
-- ws2_32.WSAInstallServiceClassW(lpServiceClassInfo)
-- lpServiceClassInfo : WSASERVICECLASSINFOW*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('WS2_32.dll');
const WSAInstallServiceClassW = lib.func('__stdcall', 'WSAInstallServiceClassW', 'int32_t', ['void *']);
// WSAInstallServiceClassW(lpServiceClassInfo)
// lpServiceClassInfo : WSASERVICECLASSINFOW* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WS2_32.dll", {
WSAInstallServiceClassW: { parameters: ["pointer"], result: "i32" },
});
// lib.symbols.WSAInstallServiceClassW(lpServiceClassInfo)
// lpServiceClassInfo : WSASERVICECLASSINFOW* -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WSAInstallServiceClassW(
void* lpServiceClassInfo);
C, "WS2_32.dll");
// $ffi->WSAInstallServiceClassW(lpServiceClassInfo);
// lpServiceClassInfo : WSASERVICECLASSINFOW*
// 構造体/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, W32APIOptions.UNICODE_OPTIONS);
int WSAInstallServiceClassW(
Pointer lpServiceClassInfo // WSASERVICECLASSINFOW*
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("ws2_32")]
lib LibWS2_32
fun WSAInstallServiceClassW = WSAInstallServiceClassW(
lpServiceClassInfo : WSASERVICECLASSINFOW* # WSASERVICECLASSINFOW*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WSAInstallServiceClassWNative = Int32 Function(Pointer<Void>);
typedef WSAInstallServiceClassWDart = int Function(Pointer<Void>);
final WSAInstallServiceClassW = DynamicLibrary.open('WS2_32.dll')
.lookupFunction<WSAInstallServiceClassWNative, WSAInstallServiceClassWDart>('WSAInstallServiceClassW');
// lpServiceClassInfo : WSASERVICECLASSINFOW* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WSAInstallServiceClassW(
lpServiceClassInfo: Pointer // WSASERVICECLASSINFOW*
): Integer; stdcall;
external 'WS2_32.dll' name 'WSAInstallServiceClassW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WSAInstallServiceClassW"
c_WSAInstallServiceClassW :: Ptr () -> IO Int32
-- lpServiceClassInfo : WSASERVICECLASSINFOW* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wsainstallserviceclassw =
foreign "WSAInstallServiceClassW"
((ptr void) @-> returning int32_t)
(* lpServiceClassInfo : WSASERVICECLASSINFOW* -> (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 ("WSAInstallServiceClassW" wsainstall-service-class-w :convention :stdcall) :int32
(lp-service-class-info :pointer)) ; WSASERVICECLASSINFOW*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WSAInstallServiceClassW = Win32::API::More->new('WS2_32',
'int WSAInstallServiceClassW(LPVOID lpServiceClassInfo)');
# my $ret = $WSAInstallServiceClassW->Call($lpServiceClassInfo);
# lpServiceClassInfo : WSASERVICECLASSINFOW* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f WSAInstallServiceClassA (ANSI版) — 新しいサービスクラス情報を登録する。
公式の関連項目
- f WSAGetLastError — 直前のソケット操作のエラーコードを取得する。
- f WSAGetServiceClassInfoW — サービスクラスのスキーマ情報を取得する。