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

WSASetServiceA

関数
サービスインスタンスの登録や登録解除を行う。
DLLWS2_32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 8.1 以降

シグネチャ

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

INT WSASetServiceA(
    WSAQUERYSETA* lpqsRegInfo,
    WSAESETSERVICEOP essoperation,
    DWORD dwControlFlags
);

パラメーター

名前方向
lpqsRegInfoWSAQUERYSETA*in
essoperationWSAESETSERVICEOPin
dwControlFlagsDWORDin

戻り値の型: INT

各言語での呼び出し定義

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

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

WSASetServiceA = ctypes.windll.ws2_32.WSASetServiceA
WSASetServiceA.restype = ctypes.c_int
WSASetServiceA.argtypes = [
    ctypes.c_void_p,  # lpqsRegInfo : WSAQUERYSETA*
    ctypes.c_int,  # essoperation : WSAESETSERVICEOP
    wintypes.DWORD,  # dwControlFlags : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WS2_32.dll')
WSASetServiceA = Fiddle::Function.new(
  lib['WSASetServiceA'],
  [
    Fiddle::TYPE_VOIDP,  # lpqsRegInfo : WSAQUERYSETA*
    Fiddle::TYPE_INT,  # essoperation : WSAESETSERVICEOP
    -Fiddle::TYPE_INT,  # dwControlFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "ws2_32")]
extern "system" {
    fn WSASetServiceA(
        lpqsRegInfo: *mut WSAQUERYSETA,  // WSAQUERYSETA*
        essoperation: i32,  // WSAESETSERVICEOP
        dwControlFlags: u32  // DWORD
    ) -> 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 WSASetServiceA(IntPtr lpqsRegInfo, int essoperation, uint dwControlFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSASetServiceA' -Namespace Win32 -PassThru
# $api::WSASetServiceA(lpqsRegInfo, essoperation, dwControlFlags)
#uselib "WS2_32.dll"
#func global WSASetServiceA "WSASetServiceA" sptr, sptr, sptr
; WSASetServiceA varptr(lpqsRegInfo), essoperation, dwControlFlags   ; 戻り値は stat
; lpqsRegInfo : WSAQUERYSETA* -> "sptr"
; essoperation : WSAESETSERVICEOP -> "sptr"
; dwControlFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WS2_32.dll"
#cfunc global WSASetServiceA "WSASetServiceA" var, int, int
; res = WSASetServiceA(lpqsRegInfo, essoperation, dwControlFlags)
; lpqsRegInfo : WSAQUERYSETA* -> "var"
; essoperation : WSAESETSERVICEOP -> "int"
; dwControlFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT WSASetServiceA(WSAQUERYSETA* lpqsRegInfo, WSAESETSERVICEOP essoperation, DWORD dwControlFlags)
#uselib "WS2_32.dll"
#cfunc global WSASetServiceA "WSASetServiceA" var, int, int
; res = WSASetServiceA(lpqsRegInfo, essoperation, dwControlFlags)
; lpqsRegInfo : WSAQUERYSETA* -> "var"
; essoperation : WSAESETSERVICEOP -> "int"
; dwControlFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
	procWSASetServiceA = ws2_32.NewProc("WSASetServiceA")
)

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