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通知を受けるサービスハンドルまたはSCMハンドル。
eEventTypeSC_EVENT_TYPEin購読するイベント種別。SC_EVENT_TYPE列挙値を指定する。
pCallbackPSC_NOTIFICATION_CALLBACKinイベント発生時に呼ばれるコールバック関数のアドレス。
pCallbackContextvoid*inoptionalコールバックに渡されるユーザーコンテキスト。NULL可。
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, varptr(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, var
; 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 -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; 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, var
; 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 -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
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)。
const std = @import("std");

extern "sechost" fn SubscribeServiceChangeNotifications(
    hService: ?*anyopaque, // SC_HANDLE
    eEventType: i32, // SC_EVENT_TYPE
    pCallback: ?*anyopaque, // PSC_NOTIFICATION_CALLBACK
    pCallbackContext: ?*anyopaque, // void* optional
    pSubscription: [*c]isize // PSC_NOTIFICATION_REGISTRATION* out
) callconv(std.os.windows.WINAPI) u32;
proc SubscribeServiceChangeNotifications(
    hService: pointer,  # SC_HANDLE
    eEventType: int32,  # SC_EVENT_TYPE
    pCallback: pointer,  # PSC_NOTIFICATION_CALLBACK
    pCallbackContext: pointer,  # void* optional
    pSubscription: ptr int  # PSC_NOTIFICATION_REGISTRATION* out
): uint32 {.importc: "SubscribeServiceChangeNotifications", stdcall, dynlib: "SecHost.dll".}
pragma(lib, "sechost");
extern(Windows)
uint SubscribeServiceChangeNotifications(
    void* hService,   // SC_HANDLE
    int eEventType,   // SC_EVENT_TYPE
    void* pCallback,   // PSC_NOTIFICATION_CALLBACK
    void* pCallbackContext,   // void* optional
    ptrdiff_t* pSubscription   // PSC_NOTIFICATION_REGISTRATION* out
);
ccall((:SubscribeServiceChangeNotifications, "SecHost.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Int}),
      hService, eEventType, pCallback, pCallbackContext, pSubscription)
# hService : SC_HANDLE -> Ptr{Cvoid}
# eEventType : SC_EVENT_TYPE -> Int32
# pCallback : PSC_NOTIFICATION_CALLBACK -> Ptr{Cvoid}
# pCallbackContext : void* optional -> Ptr{Cvoid}
# pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t SubscribeServiceChangeNotifications(
    void* hService,
    int32_t eEventType,
    void* pCallback,
    void* pCallbackContext,
    intptr_t* pSubscription);
]]
local sechost = ffi.load("sechost")
-- sechost.SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription)
-- hService : SC_HANDLE
-- eEventType : SC_EVENT_TYPE
-- pCallback : PSC_NOTIFICATION_CALLBACK
-- pCallbackContext : void* optional
-- pSubscription : PSC_NOTIFICATION_REGISTRATION* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SecHost.dll');
const SubscribeServiceChangeNotifications = lib.func('__stdcall', 'SubscribeServiceChangeNotifications', 'uint32_t', ['void *', 'int32_t', 'void *', 'void *', 'intptr_t *']);
// SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription)
// hService : SC_HANDLE -> 'void *'
// eEventType : SC_EVENT_TYPE -> 'int32_t'
// pCallback : PSC_NOTIFICATION_CALLBACK -> 'void *'
// pCallbackContext : void* optional -> 'void *'
// pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("SecHost.dll", {
  SubscribeServiceChangeNotifications: { parameters: ["pointer", "i32", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription)
// hService : SC_HANDLE -> "pointer"
// eEventType : SC_EVENT_TYPE -> "i32"
// pCallback : PSC_NOTIFICATION_CALLBACK -> "pointer"
// pCallbackContext : void* optional -> "pointer"
// pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t SubscribeServiceChangeNotifications(
    void* hService,
    int32_t eEventType,
    void* pCallback,
    void* pCallbackContext,
    intptr_t* pSubscription);
C, "SecHost.dll");
// $ffi->SubscribeServiceChangeNotifications(hService, eEventType, pCallback, pCallbackContext, pSubscription);
// hService : SC_HANDLE
// eEventType : SC_EVENT_TYPE
// pCallback : PSC_NOTIFICATION_CALLBACK
// pCallbackContext : void* optional
// pSubscription : PSC_NOTIFICATION_REGISTRATION* out
// 構造体/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 Sechost extends StdCallLibrary {
    Sechost INSTANCE = Native.load("sechost", Sechost.class);
    int SubscribeServiceChangeNotifications(
        Pointer hService,   // SC_HANDLE
        int eEventType,   // SC_EVENT_TYPE
        Callback pCallback,   // PSC_NOTIFICATION_CALLBACK
        Pointer pCallbackContext,   // void* optional
        LongByReference pSubscription   // PSC_NOTIFICATION_REGISTRATION* out
    );
}
@[Link("sechost")]
lib LibSecHost
  fun SubscribeServiceChangeNotifications = SubscribeServiceChangeNotifications(
    hService : Void*,   # SC_HANDLE
    eEventType : Int32,   # SC_EVENT_TYPE
    pCallback : Void*,   # PSC_NOTIFICATION_CALLBACK
    pCallbackContext : Void*,   # void* optional
    pSubscription : LibC::SSizeT*   # PSC_NOTIFICATION_REGISTRATION* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SubscribeServiceChangeNotificationsNative = Uint32 Function(Pointer<Void>, Int32, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
typedef SubscribeServiceChangeNotificationsDart = int Function(Pointer<Void>, int, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
final SubscribeServiceChangeNotifications = DynamicLibrary.open('SecHost.dll')
    .lookupFunction<SubscribeServiceChangeNotificationsNative, SubscribeServiceChangeNotificationsDart>('SubscribeServiceChangeNotifications');
// hService : SC_HANDLE -> Pointer<Void>
// eEventType : SC_EVENT_TYPE -> Int32
// pCallback : PSC_NOTIFICATION_CALLBACK -> Pointer<Void>
// pCallbackContext : void* optional -> Pointer<Void>
// pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SubscribeServiceChangeNotifications"
  c_SubscribeServiceChangeNotifications :: Ptr () -> Int32 -> Ptr () -> Ptr () -> Ptr CIntPtr -> IO Word32
-- hService : SC_HANDLE -> Ptr ()
-- eEventType : SC_EVENT_TYPE -> Int32
-- pCallback : PSC_NOTIFICATION_CALLBACK -> Ptr ()
-- pCallbackContext : void* optional -> Ptr ()
-- pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let subscribeservicechangenotifications =
  foreign "SubscribeServiceChangeNotifications"
    ((ptr void) @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr intptr_t) @-> returning uint32_t)
(* hService : SC_HANDLE -> (ptr void) *)
(* eEventType : SC_EVENT_TYPE -> int32_t *)
(* pCallback : PSC_NOTIFICATION_CALLBACK -> (ptr void) *)
(* pCallbackContext : void* optional -> (ptr void) *)
(* pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library sechost (t "SecHost.dll"))
(cffi:use-foreign-library sechost)

(cffi:defcfun ("SubscribeServiceChangeNotifications" subscribe-service-change-notifications :convention :stdcall) :uint32
  (h-service :pointer)   ; SC_HANDLE
  (e-event-type :int32)   ; SC_EVENT_TYPE
  (p-callback :pointer)   ; PSC_NOTIFICATION_CALLBACK
  (p-callback-context :pointer)   ; void* optional
  (p-subscription :pointer))   ; PSC_NOTIFICATION_REGISTRATION* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SubscribeServiceChangeNotifications = Win32::API::More->new('SecHost',
    'DWORD SubscribeServiceChangeNotifications(HANDLE hService, int eEventType, LPVOID pCallback, LPVOID pCallbackContext, LPVOID pSubscription)');
# my $ret = $SubscribeServiceChangeNotifications->Call($hService, $eEventType, $pCallback, $pCallbackContext, $pSubscription);
# hService : SC_HANDLE -> HANDLE
# eEventType : SC_EVENT_TYPE -> int
# pCallback : PSC_NOTIFICATION_CALLBACK -> LPVOID
# pCallbackContext : void* optional -> LPVOID
# pSubscription : PSC_NOTIFICATION_REGISTRATION* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型