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

EnumDependentServicesA

関数
指定サービスに依存するサービスを列挙する。
DLLADVAPI32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL EnumDependentServicesA(
    SC_HANDLE hService,
    ENUM_SERVICE_STATE dwServiceState,
    ENUM_SERVICE_STATUSA* lpServices,   // optional
    DWORD cbBufSize,
    DWORD* pcbBytesNeeded,
    DWORD* lpServicesReturned
);

パラメーター

名前方向
hServiceSC_HANDLEin
dwServiceStateENUM_SERVICE_STATEin
lpServicesENUM_SERVICE_STATUSA*outoptional
cbBufSizeDWORDin
pcbBytesNeededDWORD*out
lpServicesReturnedDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL EnumDependentServicesA(
    SC_HANDLE hService,
    ENUM_SERVICE_STATE dwServiceState,
    ENUM_SERVICE_STATUSA* lpServices,   // optional
    DWORD cbBufSize,
    DWORD* pcbBytesNeeded,
    DWORD* lpServicesReturned
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool EnumDependentServicesA(
    IntPtr hService,   // SC_HANDLE
    uint dwServiceState,   // ENUM_SERVICE_STATE
    IntPtr lpServices,   // ENUM_SERVICE_STATUSA* optional, out
    uint cbBufSize,   // DWORD
    out uint pcbBytesNeeded,   // DWORD* out
    out uint lpServicesReturned   // DWORD* out
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EnumDependentServicesA(
    hService As IntPtr,   ' SC_HANDLE
    dwServiceState As UInteger,   ' ENUM_SERVICE_STATE
    lpServices As IntPtr,   ' ENUM_SERVICE_STATUSA* optional, out
    cbBufSize As UInteger,   ' DWORD
    <Out> ByRef pcbBytesNeeded As UInteger,   ' DWORD* out
    <Out> ByRef lpServicesReturned As UInteger   ' DWORD* out
) As Boolean
End Function
' hService : SC_HANDLE
' dwServiceState : ENUM_SERVICE_STATE
' lpServices : ENUM_SERVICE_STATUSA* optional, out
' cbBufSize : DWORD
' pcbBytesNeeded : DWORD* out
' lpServicesReturned : DWORD* out
Declare PtrSafe Function EnumDependentServicesA Lib "advapi32" ( _
    ByVal hService As LongPtr, _
    ByVal dwServiceState As Long, _
    ByVal lpServices As LongPtr, _
    ByVal cbBufSize As Long, _
    ByRef pcbBytesNeeded As Long, _
    ByRef lpServicesReturned As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

EnumDependentServicesA = ctypes.windll.advapi32.EnumDependentServicesA
EnumDependentServicesA.restype = wintypes.BOOL
EnumDependentServicesA.argtypes = [
    wintypes.HANDLE,  # hService : SC_HANDLE
    wintypes.DWORD,  # dwServiceState : ENUM_SERVICE_STATE
    ctypes.c_void_p,  # lpServices : ENUM_SERVICE_STATUSA* optional, out
    wintypes.DWORD,  # cbBufSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pcbBytesNeeded : DWORD* out
    ctypes.POINTER(wintypes.DWORD),  # lpServicesReturned : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
EnumDependentServicesA = Fiddle::Function.new(
  lib['EnumDependentServicesA'],
  [
    Fiddle::TYPE_VOIDP,  # hService : SC_HANDLE
    -Fiddle::TYPE_INT,  # dwServiceState : ENUM_SERVICE_STATE
    Fiddle::TYPE_VOIDP,  # lpServices : ENUM_SERVICE_STATUSA* optional, out
    -Fiddle::TYPE_INT,  # cbBufSize : DWORD
    Fiddle::TYPE_VOIDP,  # pcbBytesNeeded : DWORD* out
    Fiddle::TYPE_VOIDP,  # lpServicesReturned : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn EnumDependentServicesA(
        hService: *mut core::ffi::c_void,  // SC_HANDLE
        dwServiceState: u32,  // ENUM_SERVICE_STATE
        lpServices: *mut ENUM_SERVICE_STATUSA,  // ENUM_SERVICE_STATUSA* optional, out
        cbBufSize: u32,  // DWORD
        pcbBytesNeeded: *mut u32,  // DWORD* out
        lpServicesReturned: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool EnumDependentServicesA(IntPtr hService, uint dwServiceState, IntPtr lpServices, uint cbBufSize, out uint pcbBytesNeeded, out uint lpServicesReturned);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_EnumDependentServicesA' -Namespace Win32 -PassThru
# $api::EnumDependentServicesA(hService, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned)
#uselib "ADVAPI32.dll"
#func global EnumDependentServicesA "EnumDependentServicesA" sptr, sptr, sptr, sptr, sptr, sptr
; EnumDependentServicesA hService, dwServiceState, varptr(lpServices), cbBufSize, varptr(pcbBytesNeeded), varptr(lpServicesReturned)   ; 戻り値は stat
; hService : SC_HANDLE -> "sptr"
; dwServiceState : ENUM_SERVICE_STATE -> "sptr"
; lpServices : ENUM_SERVICE_STATUSA* optional, out -> "sptr"
; cbBufSize : DWORD -> "sptr"
; pcbBytesNeeded : DWORD* out -> "sptr"
; lpServicesReturned : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global EnumDependentServicesA "EnumDependentServicesA" sptr, int, var, int, var, var
; res = EnumDependentServicesA(hService, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned)
; hService : SC_HANDLE -> "sptr"
; dwServiceState : ENUM_SERVICE_STATE -> "int"
; lpServices : ENUM_SERVICE_STATUSA* optional, out -> "var"
; cbBufSize : DWORD -> "int"
; pcbBytesNeeded : DWORD* out -> "var"
; lpServicesReturned : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL EnumDependentServicesA(SC_HANDLE hService, ENUM_SERVICE_STATE dwServiceState, ENUM_SERVICE_STATUSA* lpServices, DWORD cbBufSize, DWORD* pcbBytesNeeded, DWORD* lpServicesReturned)
#uselib "ADVAPI32.dll"
#cfunc global EnumDependentServicesA "EnumDependentServicesA" intptr, int, var, int, var, var
; res = EnumDependentServicesA(hService, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned)
; hService : SC_HANDLE -> "intptr"
; dwServiceState : ENUM_SERVICE_STATE -> "int"
; lpServices : ENUM_SERVICE_STATUSA* optional, out -> "var"
; cbBufSize : DWORD -> "int"
; pcbBytesNeeded : DWORD* out -> "var"
; lpServicesReturned : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procEnumDependentServicesA = advapi32.NewProc("EnumDependentServicesA")
)

// hService (SC_HANDLE), dwServiceState (ENUM_SERVICE_STATE), lpServices (ENUM_SERVICE_STATUSA* optional, out), cbBufSize (DWORD), pcbBytesNeeded (DWORD* out), lpServicesReturned (DWORD* out)
r1, _, err := procEnumDependentServicesA.Call(
	uintptr(hService),
	uintptr(dwServiceState),
	uintptr(lpServices),
	uintptr(cbBufSize),
	uintptr(pcbBytesNeeded),
	uintptr(lpServicesReturned),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function EnumDependentServicesA(
  hService: THandle;   // SC_HANDLE
  dwServiceState: DWORD;   // ENUM_SERVICE_STATE
  lpServices: Pointer;   // ENUM_SERVICE_STATUSA* optional, out
  cbBufSize: DWORD;   // DWORD
  pcbBytesNeeded: Pointer;   // DWORD* out
  lpServicesReturned: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'EnumDependentServicesA';
result := DllCall("ADVAPI32\EnumDependentServicesA"
    , "Ptr", hService   ; SC_HANDLE
    , "UInt", dwServiceState   ; ENUM_SERVICE_STATE
    , "Ptr", lpServices   ; ENUM_SERVICE_STATUSA* optional, out
    , "UInt", cbBufSize   ; DWORD
    , "Ptr", pcbBytesNeeded   ; DWORD* out
    , "Ptr", lpServicesReturned   ; DWORD* out
    , "Int")   ; return: BOOL
●EnumDependentServicesA(hService, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned) = DLL("ADVAPI32.dll", "bool EnumDependentServicesA(void*, dword, void*, dword, void*, void*)")
# 呼び出し: EnumDependentServicesA(hService, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned)
# hService : SC_HANDLE -> "void*"
# dwServiceState : ENUM_SERVICE_STATE -> "dword"
# lpServices : ENUM_SERVICE_STATUSA* optional, out -> "void*"
# cbBufSize : DWORD -> "dword"
# pcbBytesNeeded : DWORD* out -> "void*"
# lpServicesReturned : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。