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

WSAInstallServiceClassA

関数
新しいサービスクラス情報を登録する。
DLLWS2_32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// WS2_32.dll  (ANSI / -A)
#include <windows.h>

INT WSAInstallServiceClassA(
    WSASERVICECLASSINFOA* lpServiceClassInfo
);

パラメーター

名前方向説明
lpServiceClassInfoWSASERVICECLASSINFOA*in

サービスクラスから名前空間固有の型へのマッピング情報。複数のマッピングを一度に処理できます。

関連するデータ構造の説明については、 サービスクラスのデータ構造のセクションを参照してください。

戻り値の型: INT

公式ドキュメント

WSAInstallServiceClass 関数は、名前空間内にサービスクラススキーマを登録します。(ANSI)

戻り値

操作が成功した場合、戻り値は 0 です。それ以外の場合は SOCKET_ERROR が返され、 WSAGetLastError を呼び出すことで具体的なエラー番号を取得できます。

エラーコード 意味
WSA_INVALID_PARAMETER
名前空間プロバイダーが要求されたクラス情報を提供できません。
WSA_NOT_ENOUGH_MEMORY
操作を実行するのに十分なメモリがありませんでした。
WSAEACCES
呼び出し元の関数に、サービスをインストールするのに十分な権限がありません。
WSAEALREADY
このサービスクラス識別子に対して、サービスクラス情報が既に登録されています。サービスクラス情報を変更するには、まず WSARemoveServiceClass を使用し、その後、更新したクラス情報データで再インストールしてください。
WSAEINVAL
サービスクラス情報が無効であるか、構造が正しくありませんでした。このエラーは、lpServiceClassInfo パラメーターが NULL の場合に返されます。
WSAEOPNOTSUPP
操作はサポートされていません。このエラーは、名前空間プロバイダーがこの関数を実装していない場合に返されます。
WSANO_DATA
要求された名前は有効ですが、要求された型のデータが見つかりませんでした。
WSANOTINITIALISED
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)

各言語での呼び出し定義

// WS2_32.dll  (ANSI / -A)
#include <windows.h>

INT WSAInstallServiceClassA(
    WSASERVICECLASSINFOA* lpServiceClassInfo
);
[DllImport("WS2_32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern int WSAInstallServiceClassA(
    IntPtr lpServiceClassInfo   // WSASERVICECLASSINFOA*
);
<DllImport("WS2_32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSAInstallServiceClassA(
    lpServiceClassInfo As IntPtr   ' WSASERVICECLASSINFOA*
) As Integer
End Function
' lpServiceClassInfo : WSASERVICECLASSINFOA*
Declare PtrSafe Function WSAInstallServiceClassA Lib "ws2_32" ( _
    ByVal lpServiceClassInfo As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WSAInstallServiceClassA = ctypes.windll.ws2_32.WSAInstallServiceClassA
WSAInstallServiceClassA.restype = ctypes.c_int
WSAInstallServiceClassA.argtypes = [
    ctypes.c_void_p,  # lpServiceClassInfo : WSASERVICECLASSINFOA*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WS2_32.dll')
WSAInstallServiceClassA = Fiddle::Function.new(
  lib['WSAInstallServiceClassA'],
  [
    Fiddle::TYPE_VOIDP,  # lpServiceClassInfo : WSASERVICECLASSINFOA*
  ],
  Fiddle::TYPE_INT)
#[link(name = "ws2_32")]
extern "system" {
    fn WSAInstallServiceClassA(
        lpServiceClassInfo: *mut WSASERVICECLASSINFOA  // WSASERVICECLASSINFOA*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WS2_32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int WSAInstallServiceClassA(IntPtr lpServiceClassInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAInstallServiceClassA' -Namespace Win32 -PassThru
# $api::WSAInstallServiceClassA(lpServiceClassInfo)
#uselib "WS2_32.dll"
#func global WSAInstallServiceClassA "WSAInstallServiceClassA" sptr
; WSAInstallServiceClassA varptr(lpServiceClassInfo)   ; 戻り値は stat
; lpServiceClassInfo : WSASERVICECLASSINFOA* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WS2_32.dll"
#cfunc global WSAInstallServiceClassA "WSAInstallServiceClassA" var
; res = WSAInstallServiceClassA(lpServiceClassInfo)
; lpServiceClassInfo : WSASERVICECLASSINFOA* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT WSAInstallServiceClassA(WSASERVICECLASSINFOA* lpServiceClassInfo)
#uselib "WS2_32.dll"
#cfunc global WSAInstallServiceClassA "WSAInstallServiceClassA" var
; res = WSAInstallServiceClassA(lpServiceClassInfo)
; lpServiceClassInfo : WSASERVICECLASSINFOA* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
	procWSAInstallServiceClassA = ws2_32.NewProc("WSAInstallServiceClassA")
)

// lpServiceClassInfo (WSASERVICECLASSINFOA*)
r1, _, err := procWSAInstallServiceClassA.Call(
	uintptr(lpServiceClassInfo),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function WSAInstallServiceClassA(
  lpServiceClassInfo: Pointer   // WSASERVICECLASSINFOA*
): Integer; stdcall;
  external 'WS2_32.dll' name 'WSAInstallServiceClassA';
result := DllCall("WS2_32\WSAInstallServiceClassA"
    , "Ptr", lpServiceClassInfo   ; WSASERVICECLASSINFOA*
    , "Int")   ; return: INT
●WSAInstallServiceClassA(lpServiceClassInfo) = DLL("WS2_32.dll", "int WSAInstallServiceClassA(void*)")
# 呼び出し: WSAInstallServiceClassA(lpServiceClassInfo)
# lpServiceClassInfo : WSASERVICECLASSINFOA* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "ws2_32" fn WSAInstallServiceClassA(
    lpServiceClassInfo: [*c]WSASERVICECLASSINFOA // WSASERVICECLASSINFOA*
) callconv(std.os.windows.WINAPI) i32;
proc WSAInstallServiceClassA(
    lpServiceClassInfo: ptr WSASERVICECLASSINFOA  # WSASERVICECLASSINFOA*
): int32 {.importc: "WSAInstallServiceClassA", stdcall, dynlib: "WS2_32.dll".}
pragma(lib, "ws2_32");
extern(Windows)
int WSAInstallServiceClassA(
    WSASERVICECLASSINFOA* lpServiceClassInfo   // WSASERVICECLASSINFOA*
);
ccall((:WSAInstallServiceClassA, "WS2_32.dll"), stdcall, Int32,
      (Ptr{WSASERVICECLASSINFOA},),
      lpServiceClassInfo)
# lpServiceClassInfo : WSASERVICECLASSINFOA* -> Ptr{WSASERVICECLASSINFOA}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WSAInstallServiceClassA(
    void* lpServiceClassInfo);
]]
local ws2_32 = ffi.load("ws2_32")
-- ws2_32.WSAInstallServiceClassA(lpServiceClassInfo)
-- lpServiceClassInfo : WSASERVICECLASSINFOA*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WS2_32.dll');
const WSAInstallServiceClassA = lib.func('__stdcall', 'WSAInstallServiceClassA', 'int32_t', ['void *']);
// WSAInstallServiceClassA(lpServiceClassInfo)
// lpServiceClassInfo : WSASERVICECLASSINFOA* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WS2_32.dll", {
  WSAInstallServiceClassA: { parameters: ["pointer"], result: "i32" },
});
// lib.symbols.WSAInstallServiceClassA(lpServiceClassInfo)
// lpServiceClassInfo : WSASERVICECLASSINFOA* -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WSAInstallServiceClassA(
    void* lpServiceClassInfo);
C, "WS2_32.dll");
// $ffi->WSAInstallServiceClassA(lpServiceClassInfo);
// lpServiceClassInfo : WSASERVICECLASSINFOA*
// 構造体/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.ASCII_OPTIONS);
    int WSAInstallServiceClassA(
        Pointer lpServiceClassInfo   // WSASERVICECLASSINFOA*
    );
}
@[Link("ws2_32")]
lib LibWS2_32
  fun WSAInstallServiceClassA = WSAInstallServiceClassA(
    lpServiceClassInfo : WSASERVICECLASSINFOA*   # WSASERVICECLASSINFOA*
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WSAInstallServiceClassANative = Int32 Function(Pointer<Void>);
typedef WSAInstallServiceClassADart = int Function(Pointer<Void>);
final WSAInstallServiceClassA = DynamicLibrary.open('WS2_32.dll')
    .lookupFunction<WSAInstallServiceClassANative, WSAInstallServiceClassADart>('WSAInstallServiceClassA');
// lpServiceClassInfo : WSASERVICECLASSINFOA* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WSAInstallServiceClassA(
  lpServiceClassInfo: Pointer   // WSASERVICECLASSINFOA*
): Integer; stdcall;
  external 'WS2_32.dll' name 'WSAInstallServiceClassA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WSAInstallServiceClassA"
  c_WSAInstallServiceClassA :: Ptr () -> IO Int32
-- lpServiceClassInfo : WSASERVICECLASSINFOA* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wsainstallserviceclassa =
  foreign "WSAInstallServiceClassA"
    ((ptr void) @-> returning int32_t)
(* lpServiceClassInfo : WSASERVICECLASSINFOA* -> (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 ("WSAInstallServiceClassA" wsainstall-service-class-a :convention :stdcall) :int32
  (lp-service-class-info :pointer))   ; WSASERVICECLASSINFOA*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WSAInstallServiceClassA = Win32::API::More->new('WS2_32',
    'int WSAInstallServiceClassA(LPVOID lpServiceClassInfo)');
# my $ret = $WSAInstallServiceClassA->Call($lpServiceClassInfo);
# lpServiceClassInfo : WSASERVICECLASSINFOA* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目
使用する型