Win32 API 日本語リファレンス
ホームSystem.Services › SubscribeServiceChangeNotifications

SubscribeServiceChangeNotifications

関数
サービスの変更イベント通知を購読する。
DLLSecHost.dll呼出規約winapi

シグネチャ

// SecHost.dll
#include <windows.h>

DWORD SubscribeServiceChangeNotifications(
    SC_HANDLE hService,
    SC_EVENT_TYPE eEventType,
    PSC_NOTIFICATION_CALLBACK pCallback,
    void* pCallbackContext,   // optional
    PSC_NOTIFICATION_REGISTRATION* pSubscription
);

パラメーター

名前方向
hServiceSC_HANDLEin
eEventTypeSC_EVENT_TYPEin
pCallbackPSC_NOTIFICATION_CALLBACKin
pCallbackContextvoid*inoptional
pSubscriptionPSC_NOTIFICATION_REGISTRATION*out

戻り値の型: DWORD

各言語での呼び出し定義

// SecHost.dll
#include <windows.h>

DWORD SubscribeServiceChangeNotifications(
    SC_HANDLE hService,
    SC_EVENT_TYPE eEventType,
    PSC_NOTIFICATION_CALLBACK pCallback,
    void* pCallbackContext,   // optional
    PSC_NOTIFICATION_REGISTRATION* pSubscription
);
[DllImport("SecHost.dll", ExactSpelling = true)]
static extern uint SubscribeServiceChangeNotifications(
    IntPtr hService,   // SC_HANDLE
    int eEventType,   // SC_EVENT_TYPE
    IntPtr pCallback,   // PSC_NOTIFICATION_CALLBACK
    IntPtr pCallbackContext,   // void* optional
    out IntPtr pSubscription   // PSC_NOTIFICATION_REGISTRATION* out
);
<DllImport("SecHost.dll", ExactSpelling:=True)>
Public Shared Function SubscribeServiceChangeNotifications(
    hService As IntPtr,   ' SC_HANDLE
    eEventType As Integer,   ' SC_EVENT_TYPE
    pCallback As IntPtr,   ' PSC_NOTIFICATION_CALLBACK
    pCallbackContext As IntPtr,   ' void* optional
    <Out> ByRef pSubscription As IntPtr   ' PSC_NOTIFICATION_REGISTRATION* out
) As UInteger
End Function
' hService : SC_HANDLE
' eEventType : SC_EVENT_TYPE
' pCallback : PSC_NOTIFICATION_CALLBACK
' pCallbackContext : void* optional
' pSubscription : PSC_NOTIFICATION_REGISTRATION* out
Declare PtrSafe Function SubscribeServiceChangeNotifications Lib "sechost" ( _
    ByVal hService As LongPtr, _
    ByVal eEventType As Long, _
    ByVal pCallback As LongPtr, _
    ByVal pCallbackContext As LongPtr, _
    ByRef pSubscription As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SubscribeServiceChangeNotifications = ctypes.windll.sechost.SubscribeServiceChangeNotifications
SubscribeServiceChangeNotifications.restype = wintypes.DWORD
SubscribeServiceChangeNotifications.argtypes = [
    wintypes.HANDLE,  # hService : SC_HANDLE
    ctypes.c_int,  # eEventType : SC_EVENT_TYPE
    ctypes.c_void_p,  # pCallback : PSC_NOTIFICATION_CALLBACK
    ctypes.POINTER(None),  # pCallbackContext : void* optional
    ctypes.c_void_p,  # pSubscription : PSC_NOTIFICATION_REGISTRATION* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SecHost.dll')
SubscribeServiceChangeNotifications = Fiddle::Function.new(
  lib['SubscribeServiceChangeNotifications'],
  [
    Fiddle::TYPE_VOIDP,  # hService : SC_HANDLE
    Fiddle::TYPE_INT,  # eEventType : SC_EVENT_TYPE
    Fiddle::TYPE_VOIDP,  # pCallback : PSC_NOTIFICATION_CALLBACK
    Fiddle::TYPE_VOIDP,  # pCallbackContext : void* optional
    Fiddle::TYPE_VOIDP,  # pSubscription : PSC_NOTIFICATION_REGISTRATION* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "sechost")]
extern "system" {
    fn SubscribeServiceChangeNotifications(
        hService: *mut core::ffi::c_void,  // SC_HANDLE
        eEventType: i32,  // SC_EVENT_TYPE
        pCallback: *const core::ffi::c_void,  // PSC_NOTIFICATION_CALLBACK
        pCallbackContext: *mut (),  // void* optional
        pSubscription: *mut isize  // PSC_NOTIFICATION_REGISTRATION* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SecHost.dll")]
public static extern uint SubscribeServiceChangeNotifications(IntPtr hService, int eEventType, IntPtr pCallback, IntPtr pCallbackContext, out IntPtr pSubscription);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SecHost_SubscribeServiceChangeNotifications' -Namespace Win32 -PassThru
# $api::SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription)
#uselib "SecHost.dll"
#func global SubscribeServiceChangeNotifications "SubscribeServiceChangeNotifications" sptr, sptr, sptr, sptr, sptr
; SubscribeServiceChangeNotifications hService, eEventType, pCallback, pCallbackContext, pSubscription   ; 戻り値は stat
; hService : SC_HANDLE -> "sptr"
; eEventType : SC_EVENT_TYPE -> "sptr"
; pCallback : PSC_NOTIFICATION_CALLBACK -> "sptr"
; pCallbackContext : void* optional -> "sptr"
; pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SecHost.dll"
#cfunc global SubscribeServiceChangeNotifications "SubscribeServiceChangeNotifications" sptr, int, sptr, sptr, int
; res = SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription)
; hService : SC_HANDLE -> "sptr"
; eEventType : SC_EVENT_TYPE -> "int"
; pCallback : PSC_NOTIFICATION_CALLBACK -> "sptr"
; pCallbackContext : void* optional -> "sptr"
; pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> "int"
; DWORD SubscribeServiceChangeNotifications(SC_HANDLE hService, SC_EVENT_TYPE eEventType, PSC_NOTIFICATION_CALLBACK pCallback, void* pCallbackContext, PSC_NOTIFICATION_REGISTRATION* pSubscription)
#uselib "SecHost.dll"
#cfunc global SubscribeServiceChangeNotifications "SubscribeServiceChangeNotifications" intptr, int, intptr, intptr, int
; res = SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription)
; hService : SC_HANDLE -> "intptr"
; eEventType : SC_EVENT_TYPE -> "int"
; pCallback : PSC_NOTIFICATION_CALLBACK -> "intptr"
; pCallbackContext : void* optional -> "intptr"
; pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	sechost = windows.NewLazySystemDLL("SecHost.dll")
	procSubscribeServiceChangeNotifications = sechost.NewProc("SubscribeServiceChangeNotifications")
)

// hService (SC_HANDLE), eEventType (SC_EVENT_TYPE), pCallback (PSC_NOTIFICATION_CALLBACK), pCallbackContext (void* optional), pSubscription (PSC_NOTIFICATION_REGISTRATION* out)
r1, _, err := procSubscribeServiceChangeNotifications.Call(
	uintptr(hService),
	uintptr(eEventType),
	uintptr(pCallback),
	uintptr(pCallbackContext),
	uintptr(pSubscription),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function SubscribeServiceChangeNotifications(
  hService: THandle;   // SC_HANDLE
  eEventType: Integer;   // SC_EVENT_TYPE
  pCallback: Pointer;   // PSC_NOTIFICATION_CALLBACK
  pCallbackContext: Pointer;   // void* optional
  pSubscription: Pointer   // PSC_NOTIFICATION_REGISTRATION* out
): DWORD; stdcall;
  external 'SecHost.dll' name 'SubscribeServiceChangeNotifications';
result := DllCall("SecHost\SubscribeServiceChangeNotifications"
    , "Ptr", hService   ; SC_HANDLE
    , "Int", eEventType   ; SC_EVENT_TYPE
    , "Ptr", pCallback   ; PSC_NOTIFICATION_CALLBACK
    , "Ptr", pCallbackContext   ; void* optional
    , "Ptr", pSubscription   ; PSC_NOTIFICATION_REGISTRATION* out
    , "UInt")   ; return: DWORD
●SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription) = DLL("SecHost.dll", "dword SubscribeServiceChangeNotifications(void*, int, void*, void*, void*)")
# 呼び出し: SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription)
# hService : SC_HANDLE -> "void*"
# eEventType : SC_EVENT_TYPE -> "int"
# pCallback : PSC_NOTIFICATION_CALLBACK -> "void*"
# pCallbackContext : void* optional -> "void*"
# pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。