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

NotifyServiceStatusChangeW

関数
サービスの状態変化を非同期で通知するよう登録する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// ADVAPI32.dll  (Unicode / -W)
#include <windows.h>

DWORD NotifyServiceStatusChangeW(
    SC_HANDLE hService,
    SERVICE_NOTIFY dwNotifyMask,
    SERVICE_NOTIFY_2W* pNotifyBuffer
);

パラメーター

名前方向
hServiceSC_HANDLEin
dwNotifyMaskSERVICE_NOTIFYin
pNotifyBufferSERVICE_NOTIFY_2W*in

戻り値の型: DWORD

各言語での呼び出し定義

// ADVAPI32.dll  (Unicode / -W)
#include <windows.h>

DWORD NotifyServiceStatusChangeW(
    SC_HANDLE hService,
    SERVICE_NOTIFY dwNotifyMask,
    SERVICE_NOTIFY_2W* pNotifyBuffer
);
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint NotifyServiceStatusChangeW(
    IntPtr hService,   // SC_HANDLE
    uint dwNotifyMask,   // SERVICE_NOTIFY
    IntPtr pNotifyBuffer   // SERVICE_NOTIFY_2W*
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function NotifyServiceStatusChangeW(
    hService As IntPtr,   ' SC_HANDLE
    dwNotifyMask As UInteger,   ' SERVICE_NOTIFY
    pNotifyBuffer As IntPtr   ' SERVICE_NOTIFY_2W*
) As UInteger
End Function
' hService : SC_HANDLE
' dwNotifyMask : SERVICE_NOTIFY
' pNotifyBuffer : SERVICE_NOTIFY_2W*
Declare PtrSafe Function NotifyServiceStatusChangeW Lib "advapi32" ( _
    ByVal hService As LongPtr, _
    ByVal dwNotifyMask As Long, _
    ByVal pNotifyBuffer 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

NotifyServiceStatusChangeW = ctypes.windll.advapi32.NotifyServiceStatusChangeW
NotifyServiceStatusChangeW.restype = wintypes.DWORD
NotifyServiceStatusChangeW.argtypes = [
    wintypes.HANDLE,  # hService : SC_HANDLE
    wintypes.DWORD,  # dwNotifyMask : SERVICE_NOTIFY
    ctypes.c_void_p,  # pNotifyBuffer : SERVICE_NOTIFY_2W*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
NotifyServiceStatusChangeW = Fiddle::Function.new(
  lib['NotifyServiceStatusChangeW'],
  [
    Fiddle::TYPE_VOIDP,  # hService : SC_HANDLE
    -Fiddle::TYPE_INT,  # dwNotifyMask : SERVICE_NOTIFY
    Fiddle::TYPE_VOIDP,  # pNotifyBuffer : SERVICE_NOTIFY_2W*
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "advapi32")]
extern "system" {
    fn NotifyServiceStatusChangeW(
        hService: *mut core::ffi::c_void,  // SC_HANDLE
        dwNotifyMask: u32,  // SERVICE_NOTIFY
        pNotifyBuffer: *mut SERVICE_NOTIFY_2W  // SERVICE_NOTIFY_2W*
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint NotifyServiceStatusChangeW(IntPtr hService, uint dwNotifyMask, IntPtr pNotifyBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_NotifyServiceStatusChangeW' -Namespace Win32 -PassThru
# $api::NotifyServiceStatusChangeW(hService, dwNotifyMask, pNotifyBuffer)
#uselib "ADVAPI32.dll"
#func global NotifyServiceStatusChangeW "NotifyServiceStatusChangeW" wptr, wptr, wptr
; NotifyServiceStatusChangeW hService, dwNotifyMask, varptr(pNotifyBuffer)   ; 戻り値は stat
; hService : SC_HANDLE -> "wptr"
; dwNotifyMask : SERVICE_NOTIFY -> "wptr"
; pNotifyBuffer : SERVICE_NOTIFY_2W* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global NotifyServiceStatusChangeW "NotifyServiceStatusChangeW" sptr, int, var
; res = NotifyServiceStatusChangeW(hService, dwNotifyMask, pNotifyBuffer)
; hService : SC_HANDLE -> "sptr"
; dwNotifyMask : SERVICE_NOTIFY -> "int"
; pNotifyBuffer : SERVICE_NOTIFY_2W* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD NotifyServiceStatusChangeW(SC_HANDLE hService, SERVICE_NOTIFY dwNotifyMask, SERVICE_NOTIFY_2W* pNotifyBuffer)
#uselib "ADVAPI32.dll"
#cfunc global NotifyServiceStatusChangeW "NotifyServiceStatusChangeW" intptr, int, var
; res = NotifyServiceStatusChangeW(hService, dwNotifyMask, pNotifyBuffer)
; hService : SC_HANDLE -> "intptr"
; dwNotifyMask : SERVICE_NOTIFY -> "int"
; pNotifyBuffer : SERVICE_NOTIFY_2W* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procNotifyServiceStatusChangeW = advapi32.NewProc("NotifyServiceStatusChangeW")
)

// hService (SC_HANDLE), dwNotifyMask (SERVICE_NOTIFY), pNotifyBuffer (SERVICE_NOTIFY_2W*)
r1, _, err := procNotifyServiceStatusChangeW.Call(
	uintptr(hService),
	uintptr(dwNotifyMask),
	uintptr(pNotifyBuffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NotifyServiceStatusChangeW(
  hService: THandle;   // SC_HANDLE
  dwNotifyMask: DWORD;   // SERVICE_NOTIFY
  pNotifyBuffer: Pointer   // SERVICE_NOTIFY_2W*
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'NotifyServiceStatusChangeW';
result := DllCall("ADVAPI32\NotifyServiceStatusChangeW"
    , "Ptr", hService   ; SC_HANDLE
    , "UInt", dwNotifyMask   ; SERVICE_NOTIFY
    , "Ptr", pNotifyBuffer   ; SERVICE_NOTIFY_2W*
    , "UInt")   ; return: DWORD
●NotifyServiceStatusChangeW(hService, dwNotifyMask, pNotifyBuffer) = DLL("ADVAPI32.dll", "dword NotifyServiceStatusChangeW(void*, dword, void*)")
# 呼び出し: NotifyServiceStatusChangeW(hService, dwNotifyMask, pNotifyBuffer)
# hService : SC_HANDLE -> "void*"
# dwNotifyMask : SERVICE_NOTIFY -> "dword"
# pNotifyBuffer : SERVICE_NOTIFY_2W* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。