ホーム › System.Services › WaitServiceState
WaitServiceState
関数サービスが指定した状態になるまで待機する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
DWORD WaitServiceState(
SC_HANDLE hService,
DWORD dwNotify,
DWORD dwTimeout, // optional
HANDLE hCancelEvent // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hService | SC_HANDLE | in |
| dwNotify | DWORD | in |
| dwTimeout | DWORD | inoptional |
| hCancelEvent | HANDLE | inoptional |
戻り値の型: DWORD
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
DWORD WaitServiceState(
SC_HANDLE hService,
DWORD dwNotify,
DWORD dwTimeout, // optional
HANDLE hCancelEvent // optional
);[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern uint WaitServiceState(
IntPtr hService, // SC_HANDLE
uint dwNotify, // DWORD
uint dwTimeout, // DWORD optional
IntPtr hCancelEvent // HANDLE optional
);<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function WaitServiceState(
hService As IntPtr, ' SC_HANDLE
dwNotify As UInteger, ' DWORD
dwTimeout As UInteger, ' DWORD optional
hCancelEvent As IntPtr ' HANDLE optional
) As UInteger
End Function' hService : SC_HANDLE
' dwNotify : DWORD
' dwTimeout : DWORD optional
' hCancelEvent : HANDLE optional
Declare PtrSafe Function WaitServiceState Lib "advapi32" ( _
ByVal hService As LongPtr, _
ByVal dwNotify As Long, _
ByVal dwTimeout As Long, _
ByVal hCancelEvent As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WaitServiceState = ctypes.windll.advapi32.WaitServiceState
WaitServiceState.restype = wintypes.DWORD
WaitServiceState.argtypes = [
wintypes.HANDLE, # hService : SC_HANDLE
wintypes.DWORD, # dwNotify : DWORD
wintypes.DWORD, # dwTimeout : DWORD optional
wintypes.HANDLE, # hCancelEvent : HANDLE optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
WaitServiceState = Fiddle::Function.new(
lib['WaitServiceState'],
[
Fiddle::TYPE_VOIDP, # hService : SC_HANDLE
-Fiddle::TYPE_INT, # dwNotify : DWORD
-Fiddle::TYPE_INT, # dwTimeout : DWORD optional
Fiddle::TYPE_VOIDP, # hCancelEvent : HANDLE optional
],
-Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn WaitServiceState(
hService: *mut core::ffi::c_void, // SC_HANDLE
dwNotify: u32, // DWORD
dwTimeout: u32, // DWORD optional
hCancelEvent: *mut core::ffi::c_void // HANDLE optional
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern uint WaitServiceState(IntPtr hService, uint dwNotify, uint dwTimeout, IntPtr hCancelEvent);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_WaitServiceState' -Namespace Win32 -PassThru
# $api::WaitServiceState(hService, dwNotify, dwTimeout, hCancelEvent)#uselib "ADVAPI32.dll"
#func global WaitServiceState "WaitServiceState" sptr, sptr, sptr, sptr
; WaitServiceState hService, dwNotify, dwTimeout, hCancelEvent ; 戻り値は stat
; hService : SC_HANDLE -> "sptr"
; dwNotify : DWORD -> "sptr"
; dwTimeout : DWORD optional -> "sptr"
; hCancelEvent : HANDLE optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global WaitServiceState "WaitServiceState" sptr, int, int, sptr
; res = WaitServiceState(hService, dwNotify, dwTimeout, hCancelEvent)
; hService : SC_HANDLE -> "sptr"
; dwNotify : DWORD -> "int"
; dwTimeout : DWORD optional -> "int"
; hCancelEvent : HANDLE optional -> "sptr"; DWORD WaitServiceState(SC_HANDLE hService, DWORD dwNotify, DWORD dwTimeout, HANDLE hCancelEvent)
#uselib "ADVAPI32.dll"
#cfunc global WaitServiceState "WaitServiceState" intptr, int, int, intptr
; res = WaitServiceState(hService, dwNotify, dwTimeout, hCancelEvent)
; hService : SC_HANDLE -> "intptr"
; dwNotify : DWORD -> "int"
; dwTimeout : DWORD optional -> "int"
; hCancelEvent : HANDLE optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procWaitServiceState = advapi32.NewProc("WaitServiceState")
)
// hService (SC_HANDLE), dwNotify (DWORD), dwTimeout (DWORD optional), hCancelEvent (HANDLE optional)
r1, _, err := procWaitServiceState.Call(
uintptr(hService),
uintptr(dwNotify),
uintptr(dwTimeout),
uintptr(hCancelEvent),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction WaitServiceState(
hService: THandle; // SC_HANDLE
dwNotify: DWORD; // DWORD
dwTimeout: DWORD; // DWORD optional
hCancelEvent: THandle // HANDLE optional
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'WaitServiceState';result := DllCall("ADVAPI32\WaitServiceState"
, "Ptr", hService ; SC_HANDLE
, "UInt", dwNotify ; DWORD
, "UInt", dwTimeout ; DWORD optional
, "Ptr", hCancelEvent ; HANDLE optional
, "UInt") ; return: DWORD●WaitServiceState(hService, dwNotify, dwTimeout, hCancelEvent) = DLL("ADVAPI32.dll", "dword WaitServiceState(void*, dword, dword, void*)")
# 呼び出し: WaitServiceState(hService, dwNotify, dwTimeout, hCancelEvent)
# hService : SC_HANDLE -> "void*"
# dwNotify : DWORD -> "dword"
# dwTimeout : DWORD optional -> "dword"
# hCancelEvent : HANDLE optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。